Skip to content

Commit d50de84

Browse files
authored
Backend code coverage tests, refactor (#133)
* chore: refactor code * add test express with code coverage * start backend test * npm publish after coverage jobs * use npx * last coverage threshold
1 parent 24a5cf4 commit d50de84

File tree

8 files changed

+385
-10
lines changed

8 files changed

+385
-10
lines changed

.circleci/config.yml

+47-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
version: 2.1
22
orbs:
3-
cypress: cypress-io/[email protected]
3+
cypress: cypress-io/[email protected] # used to run e2e tests
4+
node: circleci/[email protected] # used to publish new NPM version
5+
6+
jobs:
7+
publish:
8+
executor:
9+
name: node/default
10+
tag: '12'
11+
steps:
12+
- checkout
13+
- node/with-cache:
14+
steps:
15+
- run: npm ci
16+
- run: npm run semantic-release
17+
418
workflows:
519
build:
620
jobs:
21+
- cypress/install
722
- cypress/run:
23+
name: frontend coverage
24+
requires:
25+
- cypress/install
826
# we need to start the web application
927
start: npm start
1028
# there are no jobs to follow this one
@@ -23,5 +41,31 @@ workflows:
2341
- run: npx nyc report --check-coverage true --lines 100 --include cypress/about.js
2442
# make sure unit tests are covered
2543
- run: npx nyc report --check-coverage true --lines 100 --include cypress/unit.js
26-
# publish new version if necessary
27-
- run: npm run semantic-release
44+
45+
- cypress/run:
46+
name: backend coverage
47+
requires:
48+
- cypress/install
49+
50+
start: npm run start:test:backend
51+
command: npx cypress run --config-file cypress-backend.json
52+
53+
# there are no jobs to follow this one
54+
# so no need to save the workspace files (saves time)
55+
no-workspace: true
56+
post-steps:
57+
# store the created coverage report folder
58+
# you can click on it in the CircleCI UI
59+
# to see live static HTML site
60+
- store_artifacts:
61+
path: coverage
62+
# print code coverage summary to the terminal
63+
# and make sure there the coverage is above certain limit
64+
- run: npx nyc report --check-coverage true --lines 85
65+
# and look at the server index file - should be fully covered
66+
- run: npx nyc report --check-coverage true --lines 100 --include test-backend/index.js
67+
68+
- publish:
69+
requires:
70+
- frontend coverage
71+
- backend coverage

cypress-backend.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"baseUrl": "http://localhost:3003",
3+
"integrationFolder": "cypress/test-backend",
4+
"env": {
5+
"codeCoverage": {
6+
"url": "http://localhost:3003/__coverage__"
7+
}
8+
}
9+
}

cypress/test-backend/spec.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="Cypress" />
2+
it('has backend code coverage', () => {
3+
cy.visit('/')
4+
cy.request('/hello')
5+
})

0 commit comments

Comments
 (0)