Skip to content

Commit ab61cf6

Browse files
committed
multiple backends
1 parent de64a01 commit ab61cf6

File tree

11 files changed

+93
-0
lines changed

11 files changed

+93
-0
lines changed

.circleci/config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ workflows:
152152
- exclude-files
153153
- frontend
154154
- fullstack
155+
- multiple-backend
155156
- one-spec
156157
- same-folder
157158
- support-files

test-apps/multiple-backends/.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"plugins": ["istanbul"]
3+
}

test-apps/multiple-backends/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# example: multiple backends
2+
3+
> Getting code coverage from multiple backends
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const { defineConfig } = require('cypress')
2+
3+
module.exports = defineConfig({
4+
fixturesFolder: false,
5+
env: {
6+
codeCoverage: {
7+
url: ['http://localhost:3003/__coverage__', 'http://localhost:3004/__coverage__'],
8+
expectBackendCoverageOnly: true,
9+
},
10+
},
11+
e2e: {
12+
setupNodeEvents(on, config) {
13+
return require('./cypress/plugins/index.js')(on, config)
14+
},
15+
baseUrl: 'http://localhost:3003',
16+
},
17+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference types="Cypress" />
2+
it('has multiple backends with code coverage', () => {
3+
cy.visit('/')
4+
cy.request('/hello')
5+
cy.request('http://localhost:3004/world')
6+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = (on, config) => {
2+
require('@cypress/code-coverage/task')(on, config)
3+
return config
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@cypress/code-coverage/support'
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "example-multiple-backends",
3+
"description": "Code coverage for multiple backends",
4+
"private": true,
5+
"scripts": {
6+
"cy:run": "cypress run",
7+
"start": "nyc --silent node server/server-3003 & nyc --silent node server/server-3004",
8+
"pretest": "rimraf .nyc_output .cache coverage dist",
9+
"test": "start-test \"3003|3004\" cy:run",
10+
"coverage:verify": "npx nyc report --check-coverage true --lines 100",
11+
"coverage:check-files": "check-coverage server-3003.js server-3004.js && only-covered server-3003.js server-3004.js"
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<body>
2+
test backend
3+
</body>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const express = require('express')
2+
const app = express()
3+
const port = 3003
4+
5+
// if there is code coverage information
6+
// then expose an endpoint that returns it
7+
/* istanbul ignore next */
8+
if (global.__coverage__) {
9+
console.log('have code coverage, will add middleware for express')
10+
console.log(`to fetch: GET :${port}/__coverage__`)
11+
require('@cypress/code-coverage/middleware/express')(app)
12+
}
13+
14+
app.use(express.static(__dirname))
15+
16+
app.get('/hello', (req, res) => {
17+
console.log('sending hello')
18+
res.send('Hello')
19+
})
20+
21+
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const express = require('express')
2+
const app = express()
3+
const port = 3004
4+
5+
// if there is code coverage information
6+
// then expose an endpoint that returns it
7+
/* istanbul ignore next */
8+
if (global.__coverage__) {
9+
console.log('have code coverage, will add middleware for express')
10+
console.log(`to fetch: GET :${port}/__coverage__`)
11+
require('@cypress/code-coverage/middleware/express')(app)
12+
}
13+
14+
app.use(express.static(__dirname))
15+
16+
app.get('/world', (req, res) => {
17+
console.log('sending world')
18+
res.send('World!')
19+
})
20+
21+
app.listen(port, () => console.log(`Example app listening on port ${port}!`))

0 commit comments

Comments
 (0)