Skip to content

Commit

Permalink
fix(grep): fix options sent to fast glob package - issue 27216 (#27231)
Browse files Browse the repository at this point in the history
* Declare function so we can import

* Fix ignore pattern to match api

* Fix lint

* Only force array if not already an array

Turn grep filtering on for own test

* Add a command to test grep tag @smoke

* adding tests

---------

Co-authored-by: Cacie Prins <cacieprins@users.noreply.github.com>
Co-authored-by: Jordan <jordan@jpdesigning.com>
Co-authored-by: Adam Stone-Lord <adams@cypress.io>
Co-authored-by: Matthew Schile <mschile@cypress.io>
  • Loading branch information
5 people committed Oct 13, 2023
1 parent facf87d commit 5a7eee5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
9 changes: 8 additions & 1 deletion npm/grep/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
const { defineConfig } = require('cypress')
const cypressGrepPlugin = require('./src/plugin')

module.exports = defineConfig({
e2e: {
defaultCommandTimeout: 1000,
setupNodeEvents (on, config) {
require('./src/plugin')(config)
cypressGrepPlugin(config)

on('task', {
grep (config) {
return cypressGrepPlugin(config)
},
})

return config
},
Expand Down
33 changes: 33 additions & 0 deletions npm/grep/cypress/e2e/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,3 +437,36 @@ describe('utils', () => {
})
})
})

describe('plugin', () => {
context('excludeSpecPattern', () => {
it('supports an array value', () => {
cy.task('grep', {
excludeSpecPattern: ['**/test2.spec.js', '**/test3.spec.js'],
specPattern: '**/*.spec.js',
env: {
grepTags: 'smoke',
grepFilterSpecs: true,
},
}).then((config) => {
expect(config.specPattern.length).to.equal(1)
expect(config.specPattern[0]).to.contain('test1.spec.js')
})
})

it('supports a string value', () => {
cy.task('grep', {
excludeSpecPattern: '**/test2.spec.js',
specPattern: '**/*.spec.js',
env: {
grepTags: 'smoke',
grepFilterSpecs: true,
},
}).then((config) => {
expect(config.specPattern.length).to.equal(2)
expect(config.specPattern[0]).to.contain('test1.spec.js')
expect(config.specPattern[1]).to.contain('test3.spec.js')
})
})
})
})
2 changes: 1 addition & 1 deletion npm/grep/src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function cypressGrepPlugin (config) {
debug('integrationFolder', integrationFolder)
const specFiles = globby.sync(specPattern, {
cwd: integrationFolder,
ignore: excludeSpecPattern,
ignore: Array.isArray(excludeSpecPattern) ? excludeSpecPattern : [excludeSpecPattern],
absolute: true,
})

Expand Down

0 comments on commit 5a7eee5

Please sign in to comment.