-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support multiple servers from which to gather code coverage (#880)
Co-authored-by: Jennifer Shehane <jennifer@cypress.io> Co-authored-by: Matt Schile <mschile@cypress.io>
- Loading branch information
1 parent
83bd4fe
commit 207b027
Showing
13 changed files
with
142 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"plugins": ["istanbul"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# example: multiple backends | ||
|
||
> Getting code coverage from multiple backends |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { defineConfig } = require('cypress') | ||
|
||
module.exports = defineConfig({ | ||
fixturesFolder: false, | ||
env: { | ||
codeCoverage: { | ||
url: ['http://localhost:3003/__coverage__', 'http://localhost:3004/__coverage__'], | ||
expectBackendCoverageOnly: true, | ||
}, | ||
}, | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
return require('./cypress/plugins/index.js')(on, config) | ||
}, | ||
baseUrl: 'http://localhost:3003', | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/// <reference types="Cypress" /> | ||
it('has multiple backends with code coverage', () => { | ||
cy.visit('/') | ||
cy.request('/hello') | ||
cy.request('http://localhost:3004/world') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = (on, config) => { | ||
require('@cypress/code-coverage/task')(on, config) | ||
return config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import '@cypress/code-coverage/support' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "example-multiple-backends", | ||
"description": "Code coverage for multiple backends", | ||
"private": true, | ||
"scripts": { | ||
"cy:run": "cypress run", | ||
"start": "nyc --silent node server/server-3003 & nyc --silent node server/server-3004", | ||
"pretest": "rimraf .nyc_output .cache coverage dist", | ||
"test": "start-test \"3003|3004\" cy:run", | ||
"coverage:verify": "npx nyc report --check-coverage true --lines 100", | ||
"coverage:check-files": "check-coverage server-3003.js server-3004.js && only-covered server-3003.js server-3004.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<body> | ||
test multiple backends | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const express = require('express') | ||
const app = express() | ||
const port = 3003 | ||
|
||
// if there is code coverage information | ||
// then expose an endpoint that returns it | ||
/* istanbul ignore next */ | ||
if (global.__coverage__) { | ||
console.log('have code coverage, will add middleware for express') | ||
console.log(`to fetch: GET :${port}/__coverage__`) | ||
require('@cypress/code-coverage/middleware/express')(app) | ||
} | ||
|
||
app.use(express.static(__dirname)) | ||
|
||
app.get('/hello', (req, res) => { | ||
console.log('sending hello') | ||
res.send('Hello') | ||
}) | ||
|
||
app.listen(port, () => console.log(`Example app listening on port ${port}!`)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const express = require('express') | ||
const app = express() | ||
const port = 3004 | ||
|
||
// if there is code coverage information | ||
// then expose an endpoint that returns it | ||
/* istanbul ignore next */ | ||
if (global.__coverage__) { | ||
console.log('have code coverage, will add middleware for express') | ||
console.log(`to fetch: GET :${port}/__coverage__`) | ||
require('@cypress/code-coverage/middleware/express')(app) | ||
} | ||
|
||
app.use(express.static(__dirname)) | ||
|
||
app.get('/world', (req, res) => { | ||
console.log('sending world') | ||
res.send('World!') | ||
}) | ||
|
||
app.listen(port, () => console.log(`Example app listening on port ${port}!`)) |