Skip to content

Commit 8e7f19d

Browse files
committed
start fullstack example
1 parent 0a7ea71 commit 8e7f19d

File tree

10 files changed

+218
-0
lines changed

10 files changed

+218
-0
lines changed

examples/fullstack/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# example: fullstack
2+
3+
> Combined code coverage from the backend code, and e2e and unit tests

examples/fullstack/cypress.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"fixturesFolder": false,
3+
"baseUrl": "http://localhost:3003",
4+
"env": {
5+
"codeCoverage": {
6+
"url": "http://localhost:3003/__coverage__"
7+
}
8+
}
9+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/// <reference types="Cypress" />
2+
it('uses frontend code and calls backend', () => {
3+
cy.visit('/')
4+
cy.contains('Page body').should('be.visible')
5+
6+
cy.window()
7+
.invoke('add', 2, 3)
8+
.should('equal', 5)
9+
10+
cy.window()
11+
.invoke('sub', 2, 3)
12+
.should('equal', -1)
13+
14+
cy.log('** backend request **')
15+
cy.request('/hello')
16+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = (on, config) => {
2+
require('../../../../task')(on, config)
3+
on('file:preprocessor', require('../../../../use-babelrc'))
4+
return config
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../../../../support'

examples/fullstack/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
window.add = (a, b) => a + b
2+
3+
window.sub = (a, b) => a - b

examples/fullstack/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "example-fullstack",
3+
"description": "Combined code coverage from the backend code, and e2e and unit tests",
4+
"devDependencies": {},
5+
"scripts": {
6+
"start": "../../node_modules/.bin/nyc --silent node server/server",
7+
"cy:open": "../../node_modules/.bin/cypress open",
8+
"dev": "../../node_modules/.bin/start-test 3003 cy:open"
9+
}
10+
}

examples/fullstack/server/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<body>
2+
Page body
3+
<script src="main-instrumented.js"></script>
4+
</body>

examples/fullstack/server/main-instrumented.js

Lines changed: 146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/fullstack/server/server.js

Lines changed: 21 additions & 0 deletions
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('../../../middleware/express')(app)
12+
}
13+
14+
app.use(express.static(__dirname))
15+
16+
app.get('/hello', (req, res) => {
17+
console.log('sending hello world')
18+
res.send('Hello World!')
19+
})
20+
21+
app.listen(port, () => console.log(`Example app listening on port ${port}!`))

0 commit comments

Comments
 (0)