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

+32
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

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

examples/exclude-files/README.md

+3
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

+5
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+
}
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+
})
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '../../../../support'
2+
console.log('this is commands file')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./commands')

examples/exclude-files/index.html

+17
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

+3
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/exclude-files/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "example-exclude-files",
3+
"description": "Exclude some files from final coverage report",
4+
"scripts": {
5+
"start": "../../node_modules/.bin/parcel serve index.html",
6+
"cy:open": "../../node_modules/.bin/cypress open",
7+
"dev": "../../node_modules/.bin/start-test 1234 cy:open"
8+
},
9+
"nyc": {
10+
"exclude": ["second.js"]
11+
},
12+
"devDependencies": {
13+
"@babel/core": "7.9.0"
14+
}
15+
}

examples/exclude-files/second.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// this file should be excluded from the final coverage numbers
2+
// using "nyc.exclude" list in package.json
3+
window.reverse = s =>
4+
s
5+
.split('')
6+
.reverse()
7+
.join('')

task.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ const tasks = {
151151
const nycReportOptions = {
152152
reportDir,
153153
tempDir: coverageFolder,
154-
reporter: [].concat(reporter) // make sure this is a list
154+
reporter: [].concat(reporter), // make sure this is a list
155+
include: nycOptions.include,
156+
exclude: nycOptions.exclude
155157
}
158+
156159
debug('calling NYC reporter with options %o', nycReportOptions)
157160
debug('current working directory is %s', process.cwd())
158161
const nyc = new NYC(nycReportOptions)

0 commit comments

Comments
 (0)