Skip to content
Open
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
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ workflows:
parameters:
jobname:
- all-files
- all-files-cwd
- backend
- batch-send-coverage
- before-all-visit
Expand Down Expand Up @@ -174,6 +175,7 @@ workflows:
- lint
- test-code-coverage-plugin
- test-all-files
- test-all-files-cwd
- test-backend
- test-batch-send-coverage
- test-before-all-visit
Expand Down
8 changes: 7 additions & 1 deletion task-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ function tryFindingLocalFiles(nycFilename) {
function findSourceFiles(nycOptions) {
debug('include all files options: %o', {
all: nycOptions.all,
cwd: nycOptions.cwd,
include: nycOptions.include,
exclude: nycOptions.exclude,
extension: nycOptions.extension
Expand Down Expand Up @@ -330,7 +331,12 @@ function findSourceFiles(nycOptions) {

debug('searching files to include using patterns %o', patterns)

const allFiles = globby.sync(patterns, { absolute: true })
const globbyOptions = { absolute: true }
if (nycOptions.cwd) {
globbyOptions.cwd = nycOptions.cwd
}
const allFiles = globby.sync(patterns, globbyOptions)

return allFiles
}
/**
Expand Down
3 changes: 3 additions & 0 deletions test-apps/all-files-cwd/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["istanbul"]
}
1 change: 1 addition & 0 deletions test-apps/all-files-cwd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# example: all files
11 changes: 11 additions & 0 deletions test-apps/all-files-cwd/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
fixturesFolder: false,
e2e: {
setupNodeEvents(on, config) {
return require('./cypress/plugins/index.js')(on, config)
},
baseUrl: 'http://localhost:1234'
}
})
12 changes: 12 additions & 0 deletions test-apps/all-files-cwd/cypress/e2e/spec.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference types="cypress" />
it('works', () => {
cy.visit('/')
cy.contains('Page body')

cy.window()
.invoke('reverse', 'super')
.should('equal', 'repus')

// application's code should be instrumented
cy.window().should('have.property', '__coverage__')
})
4 changes: 4 additions & 0 deletions test-apps/all-files-cwd/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (on, config) => {
require('@cypress/code-coverage/task')(on, config)
return config
}
1 change: 1 addition & 0 deletions test-apps/all-files-cwd/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@cypress/code-coverage/support'
1 change: 1 addition & 0 deletions test-apps/all-files-cwd/cypress/support/e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./commands')
17 changes: 17 additions & 0 deletions test-apps/all-files-cwd/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 test-apps/all-files-cwd/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
22 changes: 22 additions & 0 deletions test-apps/all-files-cwd/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "example-all-files-cwd",
"description": "Report all files cwd",
"private": true,
"scripts": {
"cy:run": "cypress run",
"start": "parcel serve ../all-files/index.html",
"start:windows": "npx bin-up parcel serve ../all-files/index.html",
"pretest": "rimraf .nyc_output .cache coverage dist",
"test": "start-test 1234 cy:run",
"coverage:verify": "npx nyc report --temp-dir ../all-files-cwd/.nyc_output --check-coverage true --lines 100",
"coverage:check-files": "check-coverage main.js && check-coverage second.js && check-coverage not-covered.js && check-coverage cypress.config.js && only-covered --from coverage/coverage-final.json main.js second.js not-covered.js cypress.config.js"
},
"nyc": {
"all": true,
"cwd": "../all-files",
"include": "*.js"
},
"devDependencies": {
"@babel/core": "^7.22.15"
}
}
7 changes: 7 additions & 0 deletions test-apps/all-files-cwd/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('')