diff --git a/.circleci/config.yml b/.circleci/config.yml
index 317abe60c..b9ac1ab13 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -145,6 +145,7 @@ workflows:
parameters:
jobname:
- all-files
+ - all-files-cwd
- backend
- batch-send-coverage
- before-all-visit
@@ -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
diff --git a/task-utils.js b/task-utils.js
index 7e39cfdef..6ebf1ae68 100644
--- a/task-utils.js
+++ b/task-utils.js
@@ -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
@@ -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
}
/**
diff --git a/test-apps/all-files-cwd/.babelrc b/test-apps/all-files-cwd/.babelrc
new file mode 100644
index 000000000..7a016cf8e
--- /dev/null
+++ b/test-apps/all-files-cwd/.babelrc
@@ -0,0 +1,3 @@
+{
+ "plugins": ["istanbul"]
+}
diff --git a/test-apps/all-files-cwd/README.md b/test-apps/all-files-cwd/README.md
new file mode 100644
index 000000000..e5faf2889
--- /dev/null
+++ b/test-apps/all-files-cwd/README.md
@@ -0,0 +1 @@
+# example: all files
diff --git a/test-apps/all-files-cwd/cypress.config.js b/test-apps/all-files-cwd/cypress.config.js
new file mode 100644
index 000000000..7b34c2f8e
--- /dev/null
+++ b/test-apps/all-files-cwd/cypress.config.js
@@ -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'
+ }
+})
diff --git a/test-apps/all-files-cwd/cypress/e2e/spec.cy.js b/test-apps/all-files-cwd/cypress/e2e/spec.cy.js
new file mode 100644
index 000000000..d7ca62b2f
--- /dev/null
+++ b/test-apps/all-files-cwd/cypress/e2e/spec.cy.js
@@ -0,0 +1,12 @@
+///
+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__')
+})
diff --git a/test-apps/all-files-cwd/cypress/plugins/index.js b/test-apps/all-files-cwd/cypress/plugins/index.js
new file mode 100644
index 000000000..101311b68
--- /dev/null
+++ b/test-apps/all-files-cwd/cypress/plugins/index.js
@@ -0,0 +1,4 @@
+module.exports = (on, config) => {
+ require('@cypress/code-coverage/task')(on, config)
+ return config
+}
diff --git a/test-apps/all-files-cwd/cypress/support/commands.js b/test-apps/all-files-cwd/cypress/support/commands.js
new file mode 100644
index 000000000..cc6040de7
--- /dev/null
+++ b/test-apps/all-files-cwd/cypress/support/commands.js
@@ -0,0 +1 @@
+import '@cypress/code-coverage/support'
diff --git a/test-apps/all-files-cwd/cypress/support/e2e.js b/test-apps/all-files-cwd/cypress/support/e2e.js
new file mode 100644
index 000000000..b5c578c9d
--- /dev/null
+++ b/test-apps/all-files-cwd/cypress/support/e2e.js
@@ -0,0 +1 @@
+require('./commands')
diff --git a/test-apps/all-files-cwd/index.html b/test-apps/all-files-cwd/index.html
new file mode 100644
index 000000000..993f0c189
--- /dev/null
+++ b/test-apps/all-files-cwd/index.html
@@ -0,0 +1,17 @@
+
+ Page body
+
+
+
+
diff --git a/test-apps/all-files-cwd/main.js b/test-apps/all-files-cwd/main.js
new file mode 100644
index 000000000..5dd69be2f
--- /dev/null
+++ b/test-apps/all-files-cwd/main.js
@@ -0,0 +1,3 @@
+window.add = (a, b) => a + b
+
+window.sub = (a, b) => a - b
diff --git a/test-apps/all-files-cwd/package.json b/test-apps/all-files-cwd/package.json
new file mode 100644
index 000000000..b0cc9cdb8
--- /dev/null
+++ b/test-apps/all-files-cwd/package.json
@@ -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"
+ }
+}
diff --git a/test-apps/all-files-cwd/second.js b/test-apps/all-files-cwd/second.js
new file mode 100644
index 000000000..494a0c5fc
--- /dev/null
+++ b/test-apps/all-files-cwd/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('')