Skip to content

Commit

Permalink
multiple backends
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthemanuel committed Sep 16, 2024
1 parent de64a01 commit ab61cf6
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ workflows:
- exclude-files
- frontend
- fullstack
- multiple-backend
- one-spec
- same-folder
- support-files
Expand Down
3 changes: 3 additions & 0 deletions test-apps/multiple-backends/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["istanbul"]
}
3 changes: 3 additions & 0 deletions test-apps/multiple-backends/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# example: multiple backends

> Getting code coverage from multiple backends
17 changes: 17 additions & 0 deletions test-apps/multiple-backends/cypress.config.js
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',
},
})
6 changes: 6 additions & 0 deletions test-apps/multiple-backends/cypress/e2e/spec.cy.js
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')
})
4 changes: 4 additions & 0 deletions test-apps/multiple-backends/cypress/plugins/index.js
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
}
1 change: 1 addition & 0 deletions test-apps/multiple-backends/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@cypress/code-coverage/support'
13 changes: 13 additions & 0 deletions test-apps/multiple-backends/package.json
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"
}
}
3 changes: 3 additions & 0 deletions test-apps/multiple-backends/server/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<body>
test backend
</body>
21 changes: 21 additions & 0 deletions test-apps/multiple-backends/server/server-3003.js
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}!`))
21 changes: 21 additions & 0 deletions test-apps/multiple-backends/server/server-3004.js
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}!`))

0 comments on commit ab61cf6

Please sign in to comment.