Skip to content

Commit 8af71b9

Browse files
authored
feat: read nyc report options from package 192 (#193)
* feat: support include and exclude nyc in package * add CI example
1 parent 0321251 commit 8af71b9

File tree

13 files changed

+106
-1
lines changed

13 files changed

+106
-1
lines changed

.circleci/config.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,37 @@ workflows:
286286
../../node_modules/.bin/only-covered main.js
287287
working_directory: examples/support-files
288288

289+
- cypress/run:
290+
attach-workspace: true
291+
name: example-exclude-files
292+
requires:
293+
- cypress/install
294+
# there are no jobs to follow this one
295+
# so no need to save the workspace files (saves time)
296+
no-workspace: true
297+
start: npm start --prefix examples/exclude-files
298+
wait-on: 'http://localhost:1234'
299+
command: npx cypress run --project examples/exclude-files
300+
# store screenshots and videos
301+
store_artifacts: true
302+
post-steps:
303+
- run: cat examples/exclude-files/.nyc_output/out.json
304+
# store the created coverage report folder
305+
# you can click on it in the CircleCI UI
306+
# to see live static HTML site
307+
- store_artifacts:
308+
path: examples/exclude-files/coverage
309+
# make sure the examples captures 100% of code
310+
- run:
311+
command: npx nyc report --check-coverage true --lines 100
312+
working_directory: examples/exclude-files
313+
- run:
314+
name: Check code coverage 📈
315+
command: |
316+
../../node_modules/.bin/check-coverage main.js
317+
../../node_modules/.bin/only-covered main.js
318+
working_directory: examples/exclude-files
319+
289320
- cypress/run:
290321
attach-workspace: true
291322
name: example-use-plugins-and-support
@@ -362,3 +393,4 @@ workflows:
362393
- example-support-files
363394
- example-use-plugins-and-support
364395
- example-one-spec
396+
- example-exclude-files

examples/exclude-files/.babelrc

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

examples/exclude-files/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# example: exclude files
2+
3+
Exclude some files from final coverage report by using `nyc` object in [package.json](package.json) file.

examples/exclude-files/cypress.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"fixturesFolder": false,
3+
"pluginsFile": "cypress/plugins/index.js",
4+
"baseUrl": "http://localhost:1234"
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference types="cypress" />
2+
it('works', () => {
3+
cy.visit('/')
4+
cy.contains('Page body')
5+
6+
cy.window()
7+
.invoke('reverse', 'super')
8+
.should('equal', 'repus')
9+
})
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '../../../../support'
2+
console.log('this is commands file')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./commands')

examples/exclude-files/index.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<body>
2+
Page body
3+
<script src="main.js"></script>
4+
<script src="second.js"></script>
5+
<script>
6+
// use functions creates in "main.js"
7+
if (add(2, 3) !== 5) {
8+
throw new Error('wrong addition')
9+
}
10+
if (sub(2, 3) !== -1) {
11+
throw new Error('wrong subtraction')
12+
}
13+
if (reverse('foo') !== 'oof') {
14+
throw new Error('wrong string reverse')
15+
}
16+
</script>
17+
</body>

examples/exclude-files/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

0 commit comments

Comments
 (0)