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

feat: validate specPattern root level #19980

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2123078
feat: validate specPattern root level
estrada9166 Jan 31, 2022
67dc001
Fix/add tests
estrada9166 Jan 31, 2022
308eb3d
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Jan 31, 2022
1b984f3
Fix test
estrada9166 Jan 31, 2022
26241c9
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Jan 31, 2022
6c7694a
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Feb 1, 2022
b6da23f
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Feb 1, 2022
b53e599
Update specExcludePattern
estrada9166 Feb 1, 2022
21194b0
Fix tests
estrada9166 Feb 1, 2022
5b64d92
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Feb 1, 2022
ced4624
Fix/add tests
estrada9166 Feb 1, 2022
fd579a1
Fix/add tests
estrada9166 Feb 1, 2022
69abb25
Fix tests
estrada9166 Feb 2, 2022
2db5c66
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Feb 2, 2022
0b312ea
Rename specExcludePattern to excludeSpecPattern
estrada9166 Feb 2, 2022
642b2e5
Fix tests
estrada9166 Feb 2, 2022
5373d0f
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Feb 3, 2022
3b10efb
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Feb 3, 2022
2fcfc78
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Feb 3, 2022
2b1fd40
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Feb 3, 2022
e4db6ae
Merge branch '10.0-release' into alejandro/feat/validate-specPattern-…
estrada9166 Feb 4, 2022
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
8 changes: 4 additions & 4 deletions npm/design-system/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ module.exports = {
env: {
reactDevtools: true,
},
ignoreSpecPattern: [
'**/__snapshots__/*',
'**/__image_snapshots__/*',
],
fixturesFolder: false,
component: {
ignoreSpecPattern: [
'**/__snapshots__/*',
'**/__image_snapshots__/*',
],
devServer (cypressConfig) {
const { startDevServer } = require('@cypress/vite-dev-server')

Expand Down
10 changes: 5 additions & 5 deletions npm/react/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ module.exports = {
'env': {
'reactDevtools': true,
},
'ignoreSpecPattern': [
'**/__snapshots__/*',
'**/__image_snapshots__/*',
],
'experimentalFetchPolyfill': true,
'component': {
ignoreSpecPattern: 'examples/**/*',
'ignoreSpecPattern': [
'**/__snapshots__/*',
'**/__image_snapshots__/*',
'examples/**/*',
],
devServer (cypressConfig, devServerConfig) {
const { startDevServer } = require('@cypress/webpack-dev-server')
const path = require('path')
Expand Down
8 changes: 4 additions & 4 deletions npm/react/examples/snapshots/cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ module.exports = {
'fixturesFolder': false,
'viewportWidth': 500,
'viewportHeight': 500,
'ignoreSpecPattern': [
'**/__snapshots__/*',
'**/__image_snapshots__/*',
],
'env': {
'cypress-plugin-snapshots': {
'prettier': true,
},
},
'component': {
'ignoreSpecPattern': [
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if this should be the default for CT. @cowboy maybe?

I also think baseUrl should be disallowed top level, it's E2E only. We should defs go over the config changes w/ a fine toothed comb to make sure everything is 💯, but this PR is definitely a good start.

'**/__snapshots__/*',
'**/__image_snapshots__/*',
],
setupNodeEvents (on, config) {
// load file devServer that comes with this plugin
// https://github.com/bahmutov/cypress-react-unit-test#install
Expand Down
10 changes: 10 additions & 0 deletions packages/config/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,4 +540,14 @@ export const breakingRootOptions: Array<BreakingOption> = [
errorKey: 'SUPPORT_FILE_ROOT_NOT_SUPPORTED',
isWarning: false,
},
{
name: 'specPattern',
errorKey: 'SPEC_PATTERN_ROOT_NOT_SUPPORTED',
isWarning: false,
},
{
name: 'ignoreSpecPattern',
errorKey: 'IGNORE_SPEC_PATTERN_ROOT_NOT_SUPPORTED',
isWarning: false,
},
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { expect } from 'chai'
import { matchedSpecs, transformSpec, SpecWithRelativeRoot } from '../../../src/sources'
import { matchedSpecs, transformSpec, SpecWithRelativeRoot, BrowserApiShape } from '../../../src/sources'
import path from 'path'
import { DataContext } from '../../../src'
import { graphqlSchema } from '@packages/graphql/src/schema'
import { AppApiShape, AuthApiShape, ElectronApiShape, LocalSettingsApiShape, ProjectApiShape } from '../../../src/actions'
import { ErrorApiShape } from '../../../src/DataContext'
import { InjectedConfigApi } from '../../../src/data'

describe('matchedSpecs', () => {
context('got a single spec pattern from --spec via cli', () => {
Expand Down Expand Up @@ -114,3 +120,60 @@ describe('transformSpec', () => {
expect(result).to.eql(actual)
})
})

describe('findSpecs', () => {
const temporary = 'tmp'

const fixture = [
'component/App.spec.ts',
'component/App.cy.ts',
'component/App.cy.js',
'e2e/onboarding.spec.ts',
'e2e/onboarding.cy.ts',
'e2e/onboarding.cy.js',
]

let ctx: DataContext

beforeEach(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, I wonder if we want a createTestDataContext method that does all this - I think a lot of tests might benefit from it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah! we may want to move to a util, that can be really useful so we can create more unit tests for different dataSources and dataActions

ctx = new DataContext({
schema: graphqlSchema,
mode: 'run',
modeOptions: {},
appApi: {} as AppApiShape,
localSettingsApi: {} as LocalSettingsApiShape,
authApi: {} as AuthApiShape,
errorApi: {} as ErrorApiShape,
configApi: {
getServerPluginHandlers: () => [],
} as InjectedConfigApi,
projectApi: {} as ProjectApiShape,
electronApi: {} as ElectronApiShape,
browserApi: {} as BrowserApiShape,
})

await Promise.all(fixture.map((element) => ctx.fs.outputFile(path.join(temporary, element), '')))
})

afterEach(async () => {
await ctx.fs.remove(temporary)
})

it('find all the *.cy.{ts,js} excluding the e2e', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, we definitely needed these tests.

const specs = await ctx.project.findSpecs(temporary, 'component', ['**/*.cy.{ts,js}'], ['e2e/*.{spec,cy}.{ts,js}'], [])

expect(specs).to.have.length(2)
})

it('find all the *.{cy,spec}.{ts,js} excluding the e2e', async () => {
const specs = await ctx.project.findSpecs(temporary, 'component', ['**/*.{cy,spec}.{ts,js}'], ['e2e/*.{spec,cy}.{ts,js}'], [])

expect(specs).to.have.length(3)
})

it('find all the e2e specs', async () => {
const specs = await ctx.project.findSpecs(temporary, 'e2e', ['e2e/*.{cy,spec}.{ts,js}'], [], [])

expect(specs).to.have.length(3)
})
})
10 changes: 10 additions & 0 deletions packages/server/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,16 @@ const getMsgByType = function (type, ...args) {
return stripIndent`\
The ${chalk.yellow(`\`supportFile\``)} configuration option was removed from the root in Cypress version \`10.0.0\`. Please update this option under each testing type property.

https://on.cypress.io/migration-guide`
case 'SPEC_PATTERN_ROOT_NOT_SUPPORTED':
return stripIndent`\
The ${chalk.yellow(`\`specPattern\``)} configuration option was removed from the root in Cypress version \`10.0.0\`. Please update this option under each testing type property.

https://on.cypress.io/migration-guide`
case 'IGNORE_SPEC_PATTERN_ROOT_NOT_SUPPORTED':
return stripIndent`\
The ${chalk.yellow(`\`ignoreSpecPattern\``)} configuration option was removed from the root in Cypress version \`10.0.0\`. Please update this option under each testing type property.

https://on.cypress.io/migration-guide`
default:
}
Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/integration/cypress_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1655,9 +1655,9 @@ describe('lib/cypress', () => {
// this should be overriden by the env argument
json.baseUrl = 'http://localhost:8080'

const { supportFile, ...rest } = json
const { supportFile, specPattern, ignoreSpecPattern, ...rest } = json

return settings.writeForTesting(this.todosPath, rest)
return settings.writeForTesting(this.todosPath, { ...rest, e2e: { supportFile, specPattern, ignoreSpecPattern } })
}).then(() => {
return cypress.start([
'--port=2121',
Expand Down
8 changes: 4 additions & 4 deletions packages/server/test/unit/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,25 +395,25 @@ describe('lib/config', () => {

context('ignoreSpecPattern', () => {
it('passes if a string', function () {
this.setup({ ignoreSpecPattern: '*.jsx' })
this.setup({ e2e: { ignoreSpecPattern: '*.jsx', supportFile: false } })

return this.expectValidationPasses()
})

it('passes if an array of strings', function () {
this.setup({ ignoreSpecPattern: ['*.jsx'] })
this.setup({ e2e: { ignoreSpecPattern: ['*.jsx'], supportFile: false } })

return this.expectValidationPasses()
})

it('fails if not a string or array', function () {
this.setup({ ignoreSpecPattern: 5 })
this.setup({ e2e: { ignoreSpecPattern: 5 } })

return this.expectValidationFails('be a string or an array of strings')
})

it('fails if not an array of strings', function () {
this.setup({ ignoreSpecPattern: [5] })
this.setup({ e2e: { ignoreSpecPattern: [5] } })
this.expectValidationFails('be a string or an array of strings')

return this.expectValidationFails('the value was: `[5]`')
Expand Down
21 changes: 21 additions & 0 deletions system-tests/__snapshots__/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,25 @@ There is both a \`cypress.config.js\` and a cypress.json file at the location be
Cypress no longer supports 'cypress.json' config, please remove it from your project.


`

exports['e2e config throws an error if supportFile is set on the root level 1'] = `
The \`supportFile\` configuration option was removed from the root in Cypress version \`10.0.0\`. Please update this option under each testing type property.

https://on.cypress.io/migration-guide

`

exports['e2e config throws an error if specPattern is set on the root level 1'] = `
The \`specPattern\` configuration option was removed from the root in Cypress version \`10.0.0\`. Please update this option under each testing type property.

https://on.cypress.io/migration-guide

`

exports['e2e config throws an error if ignoreSpecPattern is set on the root level 1'] = `
The \`ignoreSpecPattern\` configuration option was removed from the root in Cypress version \`10.0.0\`. Please update this option under each testing type property.

https://on.cypress.io/migration-guide

`
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
ignoreSpecPattern: 'src/**/*.cy.js',
e2e: {},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
specPattern: 'src/**/*.cy.js',
e2e: {},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
supportFile: 'cypress/support/e2e.js',
e2e: {},
}
36 changes: 36 additions & 0 deletions system-tests/test/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,40 @@ describe('e2e config', () => {
snapshot: true,
})
})

it('throws an error if supportFile is set on the root level', function () {
Fixtures.scaffoldProject('invalid-root-level-config')
Fixtures.projectPath('invalid-root-level-config')

return systemTests.exec(this, {
project: 'invalid-root-level-config',
configFile: 'invalid-supportFile.config.js',
expectedExitCode: 1,
snapshot: true,
})
})

it('throws an error if specPattern is set on the root level', function () {
Fixtures.scaffoldProject('invalid-root-level-config')
Fixtures.projectPath('invalid-root-level-config')

return systemTests.exec(this, {
project: 'invalid-root-level-config',
configFile: 'invalid-specPattern.config.js',
expectedExitCode: 1,
snapshot: true,
})
})

it('throws an error if ignoreSpecPattern is set on the root level', function () {
Fixtures.scaffoldProject('invalid-root-level-config')
Fixtures.projectPath('invalid-root-level-config')

return systemTests.exec(this, {
project: 'invalid-root-level-config',
configFile: 'invalid-ignoreSpecPattern.config.js',
expectedExitCode: 1,
snapshot: true,
})
})
})