Skip to content

Commit 066241c

Browse files
committed
fix: support NYC cwd option for file pattern matching
- Add support for NYC 'cwd' option in findSourceFiles function - Pass cwd option to globby for proper file pattern resolution - Add test case 'all-files-cwd' to verify cwd functionality - Update CI configuration to include new test case in matrix This fix ensures that when NYC is configured with a 'cwd' option, the file patterns are resolved relative to the specified directory instead of the current working directory.
1 parent 6d1e588 commit 066241c

File tree

13 files changed

+90
-1
lines changed

13 files changed

+90
-1
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ workflows:
145145
parameters:
146146
jobname:
147147
- all-files
148+
- all-files-cwd
148149
- backend
149150
- batch-send-coverage
150151
- before-all-visit

task-utils.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ function tryFindingLocalFiles(nycFilename) {
293293
function findSourceFiles(nycOptions) {
294294
debug('include all files options: %o', {
295295
all: nycOptions.all,
296+
cwd: nycOptions.cwd,
296297
include: nycOptions.include,
297298
exclude: nycOptions.exclude,
298299
extension: nycOptions.extension
@@ -330,7 +331,12 @@ function findSourceFiles(nycOptions) {
330331

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

333-
const allFiles = globby.sync(patterns, { absolute: true })
334+
const globbyOptions = { absolute: true }
335+
if (nycOptions.cwd) {
336+
globbyOptions.cwd = nycOptions.cwd
337+
}
338+
const allFiles = globby.sync(patterns, globbyOptions)
339+
334340
return allFiles
335341
}
336342
/**

test-apps/all-files-cwd/.babelrc

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

test-apps/all-files-cwd/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# example: all files
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { defineConfig } = require('cypress')
2+
3+
module.exports = defineConfig({
4+
fixturesFolder: false,
5+
e2e: {
6+
setupNodeEvents(on, config) {
7+
return require('./cypress/plugins/index.js')(on, config)
8+
},
9+
baseUrl: 'http://localhost:1234'
10+
}
11+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
10+
// application's code should be instrumented
11+
cy.window().should('have.property', '__coverage__')
12+
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = (on, config) => {
2+
require('@cypress/code-coverage/task')(on, config)
3+
return config
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@cypress/code-coverage/support'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require('./commands')

test-apps/all-files-cwd/index.html

Lines changed: 17 additions & 0 deletions
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>

0 commit comments

Comments
 (0)