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: exclude node_modules #302

Merged
merged 4 commits into from
Sep 20, 2024
Merged
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
12 changes: 12 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ function findCypressSpecsV10(opts = {}, type = 'e2e', returnAbsolute = false) {
: options.excludeSpecPattern
? [options.excludeSpecPattern]
: []

debug('ignore patterns %o', ignore)
const userIgnoresNodeModules = ignore.some((pattern) =>
pattern.includes('node_modules'),
)
if (userIgnoresNodeModules) {
debug('user ignored node_modules')
} else {
debug('user did not ignore node_modules, adding it')
ignore.push('**/node_modules/**')
}

const globbyOptions = {
sort: true,
ignore,
Expand Down
3 changes: 3 additions & 0 deletions test-skip-node-modules/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
cypress/videos/
cypress/screenshots/
13 changes: 13 additions & 0 deletions test-skip-node-modules/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { defineConfig } = require('cypress')

module.exports = defineConfig({
e2e: {
// baseUrl, etc
supportFile: false,
fixturesFolder: false,
setupNodeEvents(on, config) {
// implement node event listeners here
// and load any plugins that require the Node environment
},
},
})
3 changes: 3 additions & 0 deletions test-skip-node-modules/cypress/e2e/node_modules/spec2.cy.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test-skip-node-modules/cypress/e2e/spec1.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('has first test')

it('has second test')
37 changes: 37 additions & 0 deletions test-skip-node-modules/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions test-skip-node-modules/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "test-skip-node-modules",
"version": "1.0.0",
"description": "Test ignoring node_modules folder",
"private": true,
"main": "index.js",
"scripts": {
"test": "cypress run",
"demo-tests": "DEBUG=find-cypress-specs node ../bin/find",
"deps": "../node_modules/.bin/spec-change --folder cypress"
},
"keywords": [],
"author": "",
"license": "ISC"
}
11 changes: 11 additions & 0 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,14 @@ test('counts all tags including required', async (t) => {
// console.log(result)
t.snapshot(result)
})

test('skips specs in the node_modules automatically', async (t) => {
t.plan(2)
const result = await execa('node', ['../bin/find'], {
cwd: './test-skip-node-modules',
filter: ['code', 'stdout'],
})
// console.log(result)
t.false(result.includes('node_modules'))
t.snapshot(result)
})
11 changes: 11 additions & 0 deletions test/snapshots/cli.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,14 @@ Generated by [AVA](https://avajs.dev).
user 2␊
-------␊
`

## skips specs in the node_modules automatically

> Snapshot 1

` code: 0␊
stdout:␊
-------␊
cypress/e2e/spec1.cy.js␊
-------␊
`
Binary file modified test/snapshots/cli.js.snap
Binary file not shown.
Loading