diff --git a/.circleci/config.yml b/.circleci/config.yml index 0d20df9f..937a2387 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -362,3 +393,4 @@ workflows: - example-support-files - example-use-plugins-and-support - example-one-spec + - example-exclude-files diff --git a/examples/exclude-files/.babelrc b/examples/exclude-files/.babelrc new file mode 100644 index 00000000..7a016cf8 --- /dev/null +++ b/examples/exclude-files/.babelrc @@ -0,0 +1,3 @@ +{ + "plugins": ["istanbul"] +} diff --git a/examples/exclude-files/README.md b/examples/exclude-files/README.md new file mode 100644 index 00000000..3975988e --- /dev/null +++ b/examples/exclude-files/README.md @@ -0,0 +1,3 @@ +# example: exclude files + +Exclude some files from final coverage report by using `nyc` object in [package.json](package.json) file. diff --git a/examples/exclude-files/cypress.json b/examples/exclude-files/cypress.json new file mode 100644 index 00000000..c7994dc6 --- /dev/null +++ b/examples/exclude-files/cypress.json @@ -0,0 +1,5 @@ +{ + "fixturesFolder": false, + "pluginsFile": "cypress/plugins/index.js", + "baseUrl": "http://localhost:1234" +} diff --git a/examples/exclude-files/cypress/integration/spec.js b/examples/exclude-files/cypress/integration/spec.js new file mode 100644 index 00000000..3d30a8af --- /dev/null +++ b/examples/exclude-files/cypress/integration/spec.js @@ -0,0 +1,9 @@ +/// +it('works', () => { + cy.visit('/') + cy.contains('Page body') + + cy.window() + .invoke('reverse', 'super') + .should('equal', 'repus') +}) diff --git a/examples/exclude-files/cypress/plugins/index.js b/examples/exclude-files/cypress/plugins/index.js new file mode 100644 index 00000000..b17c48db --- /dev/null +++ b/examples/exclude-files/cypress/plugins/index.js @@ -0,0 +1,5 @@ +module.exports = (on, config) => { + require('../../../../task')(on, config) + on('file:preprocessor', require('../../../../use-babelrc')) + return config +} diff --git a/examples/exclude-files/cypress/support/commands.js b/examples/exclude-files/cypress/support/commands.js new file mode 100644 index 00000000..219920ee --- /dev/null +++ b/examples/exclude-files/cypress/support/commands.js @@ -0,0 +1,2 @@ +import '../../../../support' +console.log('this is commands file') diff --git a/examples/exclude-files/cypress/support/index.js b/examples/exclude-files/cypress/support/index.js new file mode 100644 index 00000000..b5c578c9 --- /dev/null +++ b/examples/exclude-files/cypress/support/index.js @@ -0,0 +1 @@ +require('./commands') diff --git a/examples/exclude-files/index.html b/examples/exclude-files/index.html new file mode 100644 index 00000000..993f0c18 --- /dev/null +++ b/examples/exclude-files/index.html @@ -0,0 +1,17 @@ + + Page body + + + + diff --git a/examples/exclude-files/main.js b/examples/exclude-files/main.js new file mode 100644 index 00000000..5dd69be2 --- /dev/null +++ b/examples/exclude-files/main.js @@ -0,0 +1,3 @@ +window.add = (a, b) => a + b + +window.sub = (a, b) => a - b diff --git a/examples/exclude-files/package.json b/examples/exclude-files/package.json new file mode 100644 index 00000000..12c1e965 --- /dev/null +++ b/examples/exclude-files/package.json @@ -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" + } +} diff --git a/examples/exclude-files/second.js b/examples/exclude-files/second.js new file mode 100644 index 00000000..494a0c5f --- /dev/null +++ b/examples/exclude-files/second.js @@ -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('') diff --git a/task.js b/task.js index f5621960..5be673bf 100644 --- a/task.js +++ b/task.js @@ -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)