Skip to content
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

fix: do not ignore node_modules if it is specified by an user #23616 #28456

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6fa1618
FileDataSource: do not ignore node_modules if it is spicified by an user
qwazimoda Dec 4, 2023
298a7a8
extra empty commit
qwazimoda Dec 4, 2023
6ab2e64
update changelog
qwazimoda Dec 4, 2023
f986092
Merge branch 'develop' into issue-24685-do-not-ignore-node_modules-if…
qwazimoda Dec 5, 2023
e03b1bf
Merge branch 'develop' into issue-24685-do-not-ignore-node_modules-if…
qwazimoda Dec 5, 2023
9239de3
Merge branch 'develop' into issue-24685-do-not-ignore-node_modules-if…
qwazimoda Dec 5, 2023
777ceed
update the changelog
qwazimoda Dec 8, 2023
83eecd1
add x.x.x version to the changelog
qwazimoda Dec 8, 2023
93ca397
change version location in the changelog
qwazimoda Dec 8, 2023
47bbe16
provide an exact version and a release date, since it is checkec by r…
qwazimoda Dec 8, 2023
0a75e6a
add unit tests
qwazimoda Dec 13, 2023
e25de10
Merge branch 'develop' into issue-24685-do-not-ignore-node_modules-if…
qwazimoda Dec 13, 2023
ebf516c
Merge branch 'develop' into issue-24685-do-not-ignore-node_modules-if…
cacieprins Dec 14, 2023
706d73c
Merge branch 'develop' into issue-24685-do-not-ignore-node_modules-if…
qwazimoda Dec 15, 2023
6adda65
Merge branch 'develop' into issue-24685-do-not-ignore-node_modules-if…
qwazimoda Dec 16, 2023
3be6a30
Merge branch 'develop' into issue-24685-do-not-ignore-node_modules-if…
qwazimoda Dec 19, 2023
fa1f259
Merge branch 'develop' into issue-24685-do-not-ignore-node_modules-if…
jennifer-shehane Dec 27, 2023
cc0a3dd
Fix changelog
jennifer-shehane Dec 27, 2023
2400ad2
Merge branch 'develop' into issue-24685-do-not-ignore-node_modules-if…
jennifer-shehane Dec 28, 2023
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 cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ _Released 1/2/2024 (PENDING)_

**Bugfixes:**

- Now 'node_modules' will not be ignored if a project path or a provided path to spec files contains it. Fixes [#23616](https://github.com/cypress-io/cypress/issues/23616).
- When generating assertions via Cypress Studio, the preview of the generated assertions now correctly displays the past tense of 'expected' instead of 'expect'. Fixed in [#28593](https://github.com/cypress-io/cypress/pull/28593).

## 13.6.2
Expand All @@ -15,6 +16,7 @@ _Released 12/26/2023_

- Fixed a regression in [`13.6.1`](https://docs.cypress.io/guides/references/changelog/13.6.1) where a malformed URI would crash Cypress. Fixes [#28521](https://github.com/cypress-io/cypress/issues/28521).
- Fixed a regression in [`12.4.0`](https://docs.cypress.io/guides/references/changelog/12.4.0) where erroneous `<br>` tags were displaying in error messages in the Command Log making them less readable. Fixes [#28452](https://github.com/cypress-io/cypress/issues/28452).
- Now 'node_modules' will not be ignored if a project path or a provided path to spec files contains it. Fixes [#23616](https://github.com/cypress-io/cypress/issues/23616).

**Performance:**

Expand Down
4 changes: 3 additions & 1 deletion packages/data-context/src/sources/FileDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export class FileDataSource {
return globPattern
})

const ignoreGlob = (globOptions.ignore ?? []).concat('**/node_modules/**')
const nodeModulesInGlobPath = ([] as string[]).concat(glob).some((globPattern) => globPattern.includes('node_modules'))
const ignoreNodeModules = !!((cwd.includes('node_modules') || nodeModulesInGlobPath))
const ignoreGlob = (globOptions.ignore ?? []).concat(ignoreNodeModules ? [] : '**/node_modules/**')

if (os.platform() === 'win32') {
// globby can't work with backwards slashes
Expand Down
94 changes: 93 additions & 1 deletion packages/data-context/test/unit/sources/FileDataSource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('FileDataSource', () => {
expect(files).to.have.length(3)
})

it('always ignores files within node_modules', async () => {
it('by default ignores files within node_modules', async () => {
const nodeModulesPath = path.join(projectPath, 'node_modules')

await fs.mkdir(nodeModulesPath)
Expand All @@ -118,6 +118,40 @@ describe('FileDataSource', () => {
expect(files).to.have.length(2)
})

it('does not ignores files within node_modules, if node_modules is in the glob path', async () => {
qwazimoda marked this conversation as resolved.
Show resolved Hide resolved
const nodeModulesPath = path.join(projectPath, 'node_modules')

await fs.mkdir(nodeModulesPath)
await fs.writeFile(path.join(nodeModulesPath, 'module-script-1.js'), '')
await fs.writeFile(path.join(nodeModulesPath, 'module-script-2.js'), '')
const files = await fileDataSource.getFilesByGlob(
projectPath,
'**/(node_modules/)?*script-*.js',
{ ignore: ['./scripts/**/*'] },
)

// scripts at root (2 of them) and scripts at node_modules should be found
// and ./scripts is explicitly ignored
expect(files).to.have.length(4)
})

it('does not ignores files within node_modules, if node_modules is in the project path', async () => {
const nodeModulesPath = path.join(projectPath, 'node_modules')

await fs.mkdir(nodeModulesPath)
await fs.writeFile(path.join(nodeModulesPath, 'module-script-1.js'), '')
await fs.writeFile(path.join(nodeModulesPath, 'module-script-2.js'), '')
await fs.writeFile(path.join(nodeModulesPath, 'module-script-3.js'), '')
const files = await fileDataSource.getFilesByGlob(
nodeModulesPath,
'**/*script-*.js',
{ ignore: ['./scripts/**/*'] },
)

// only scripts at node_modules should be found, since it is the project path
expect(files).to.have.length(3)
})

it('converts globs to POSIX paths on windows', async () => {
const windowsSeperator = '\\'

Expand Down Expand Up @@ -254,6 +288,64 @@ describe('FileDataSource', () => {
)
})

it('does not ignore node_modules, if the working dir is located inside node_modules', async () => {
const files = await fileDataSource.getFilesByGlob(
'/node_modules/project/',
'/cypress/e2e/**.cy.js',
)

expect(files).to.eq(mockMatches)
expect(matchGlobsStub).to.have.been.calledWith(
['/cypress/e2e/**.cy.js'],
{
...defaultGlobbyOptions,
cwd: '/node_modules/project/',
ignore: [],
},
)
})

it('does not ignore node_modules, if one of glob paths contains node_modules', async () => {
const files = await fileDataSource.getFilesByGlob(
'/',
[
'/node_modules/cypress/e2e/**.cy.js',
'/cypress/e2e/**.cy.js',
],
)

expect(files).to.eq(mockMatches)
expect(matchGlobsStub).to.have.been.calledWith(
[
'node_modules/cypress/e2e/**.cy.js',
'cypress/e2e/**.cy.js',
],
{
...defaultGlobbyOptions,
cwd: '/',
ignore: [],
},
)
})

it('uses supplied ignore options, when node_modules are not ignored', async () => {
const files = await fileDataSource.getFilesByGlob(
'/node_modules/project/',
'/node_modules/test_package/e2e/**.cy.js',
{ ignore: ['ignore/foo.*', '/ignore/bar.*'] },
)

expect(files).to.eq(mockMatches)
expect(matchGlobsStub).to.have.been.calledWith(
['/node_modules/test_package/e2e/**.cy.js'],
{
...defaultGlobbyOptions,
cwd: '/node_modules/project/',
ignore: ['ignore/foo.*', '/ignore/bar.*'],
},
)
})

it('uses supplied globby options', async () => {
const files = await fileDataSource.getFilesByGlob(
'/',
Expand Down
Loading