Skip to content

Commit

Permalink
fix: do not ignore node_modules if it is specified by an user #23616 (#…
Browse files Browse the repository at this point in the history
…28456)

* FileDataSource: do not ignore node_modules if it is spicified by an user

* extra empty commit

* update changelog

* update the changelog

* add x.x.x version to  the changelog

* change version location in the changelog

* provide an exact version and a release date, since it is checkec by regex in the parse-changelog.js

* add unit tests

* Fix changelog

---------

Co-authored-by: Cacie Prins <cacieprins@users.noreply.github.com>
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
  • Loading branch information
3 people committed Dec 28, 2023
1 parent 8ba64c4 commit ef3f04f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cli/CHANGELOG.md
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
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
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 () => {
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

5 comments on commit ef3f04f

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ef3f04f Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/linux-x64/develop-ef3f04fbfda469ea0c2c48967fa6cf299b7a12f2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ef3f04f Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/linux-arm64/develop-ef3f04fbfda469ea0c2c48967fa6cf299b7a12f2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ef3f04f Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/darwin-x64/develop-ef3f04fbfda469ea0c2c48967fa6cf299b7a12f2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ef3f04f Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/darwin-arm64/develop-ef3f04fbfda469ea0c2c48967fa6cf299b7a12f2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on ef3f04f Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.6.3/win32-x64/develop-ef3f04fbfda469ea0c2c48967fa6cf299b7a12f2/cypress.tgz

Please sign in to comment.