Skip to content

feat: read nyc report options from package 192 #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,37 @@ workflows:
../../node_modules/.bin/only-covered main.js
working_directory: examples/support-files

- cypress/run:
attach-workspace: true
name: example-exclude-files
requires:
- cypress/install
# there are no jobs to follow this one
# so no need to save the workspace files (saves time)
no-workspace: true
start: npm start --prefix examples/exclude-files
wait-on: 'http://localhost:1234'
command: npx cypress run --project examples/exclude-files
# store screenshots and videos
store_artifacts: true
post-steps:
- run: cat examples/exclude-files/.nyc_output/out.json
# store the created coverage report folder
# you can click on it in the CircleCI UI
# to see live static HTML site
- store_artifacts:
path: examples/exclude-files/coverage
# make sure the examples captures 100% of code
- run:
command: npx nyc report --check-coverage true --lines 100
working_directory: examples/exclude-files
- run:
name: Check code coverage 📈
command: |
../../node_modules/.bin/check-coverage main.js
../../node_modules/.bin/only-covered main.js
working_directory: examples/exclude-files

- cypress/run:
attach-workspace: true
name: example-use-plugins-and-support
Expand Down Expand Up @@ -362,3 +393,4 @@ workflows:
- example-support-files
- example-use-plugins-and-support
- example-one-spec
- example-exclude-files
3 changes: 3 additions & 0 deletions examples/exclude-files/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["istanbul"]
}
3 changes: 3 additions & 0 deletions examples/exclude-files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# example: exclude files

Exclude some files from final coverage report by using `nyc` object in [package.json](package.json) file.
5 changes: 5 additions & 0 deletions examples/exclude-files/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"fixturesFolder": false,
"pluginsFile": "cypress/plugins/index.js",
"baseUrl": "http://localhost:1234"
}
9 changes: 9 additions & 0 deletions examples/exclude-files/cypress/integration/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference types="cypress" />
it('works', () => {
cy.visit('/')
cy.contains('Page body')

cy.window()
.invoke('reverse', 'super')
.should('equal', 'repus')
})
5 changes: 5 additions & 0 deletions examples/exclude-files/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = (on, config) => {
require('../../../../task')(on, config)
on('file:preprocessor', require('../../../../use-babelrc'))
return config
}
2 changes: 2 additions & 0 deletions examples/exclude-files/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import '../../../../support'
console.log('this is commands file')
1 change: 1 addition & 0 deletions examples/exclude-files/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./commands')
17 changes: 17 additions & 0 deletions examples/exclude-files/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<body>
Page body
<script src="main.js"></script>
<script src="second.js"></script>
<script>
// use functions creates in "main.js"
if (add(2, 3) !== 5) {
throw new Error('wrong addition')
}
if (sub(2, 3) !== -1) {
throw new Error('wrong subtraction')
}
if (reverse('foo') !== 'oof') {
throw new Error('wrong string reverse')
}
</script>
</body>
3 changes: 3 additions & 0 deletions examples/exclude-files/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
window.add = (a, b) => a + b

window.sub = (a, b) => a - b
15 changes: 15 additions & 0 deletions examples/exclude-files/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "example-exclude-files",
"description": "Exclude some files from final coverage report",
"scripts": {
"start": "../../node_modules/.bin/parcel serve index.html",
"cy:open": "../../node_modules/.bin/cypress open",
"dev": "../../node_modules/.bin/start-test 1234 cy:open"
},
"nyc": {
"exclude": ["second.js"]
},
"devDependencies": {
"@babel/core": "7.9.0"
}
}
7 changes: 7 additions & 0 deletions examples/exclude-files/second.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// this file should be excluded from the final coverage numbers
// using "nyc.exclude" list in package.json
window.reverse = s =>
s
.split('')
.reverse()
.join('')
5 changes: 4 additions & 1 deletion task.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ const tasks = {
const nycReportOptions = {
reportDir,
tempDir: coverageFolder,
reporter: [].concat(reporter) // make sure this is a list
reporter: [].concat(reporter), // make sure this is a list
include: nycOptions.include,
exclude: nycOptions.exclude
}

debug('calling NYC reporter with options %o', nycReportOptions)
debug('current working directory is %s', process.cwd())
const nyc = new NYC(nycReportOptions)
Expand Down