Skip to content

Commit

Permalink
feat: remove testFiles reference (#20565)
Browse files Browse the repository at this point in the history
* feat: remove testFiles reference

* feat: remove testFiles reference

* Fix test/TS
  • Loading branch information
estrada9166 committed Mar 11, 2022
1 parent 31ed4dd commit 5670344
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 35 deletions.
8 changes: 0 additions & 8 deletions cli/schema/cypress.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@
"default": 10000,
"description": "Slow test threshold in milliseconds. Only affects the visual output of some reporters. For example, the spec reporter will display the test time in yellow if over the threshold. See https://on.cypress.io/configuration#Timeouts"
},
"testFiles": {
"type": [
"string",
"array"
],
"default": "**/*.*",
"description": "A String or Array of string glob patterns of the test files to load. See https://on.cypress.io/configuration#Global"
},
"watchForFileChanges": {
"type": "boolean",
"default": true,
Expand Down
12 changes: 0 additions & 12 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2622,12 +2622,6 @@ declare namespace Cypress {
* @default {}
*/
env: { [key: string]: any }
/**
* A String or Array of glob patterns used to ignore test files that would otherwise be shown in your list of tests. Cypress uses minimatch with the options: {dot: true, matchBase: true}. We suggest using http://globtester.com to test what files would match.
* @default "*.hot-update.js"
* @deprecated use `excludeSpecPattern` instead
*/
ignoreTestFiles: string | string[]
/**
* A String or Array of glob patterns used to ignore test files that would otherwise be shown in your list of tests. Cypress uses minimatch with the options: {dot: true, matchBase: true}. We suggest using http://globtester.com to test what files would match.
* @default "*.hot-update.js"
Expand Down Expand Up @@ -2866,12 +2860,6 @@ declare namespace Cypress {
* Glob pattern to determine what test files to load.
*/
specPattern: string | string[]
/**
* Glob pattern to determine what test files to load.
*
* @deprecated Use `specPattern` under `component` or `e2e`
*/
testFiles: string | string[]
/**
* The user agent the browser sends in all request headers.
*/
Expand Down
2 changes: 1 addition & 1 deletion npm/angular/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Enable component testing in `cypress.config.js`.
module.exports = {
"component": {
"componentFolder": "src/app",
"testFiles": "**/*cy-spec.ts"
"specPattern": "**/*cy-spec.ts"
}
}
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exports['injects guessed next.js template cypress.config.ts'] = `
export default {
componentFolder: "src",
testFiles: "**/*.spec.{js,ts,jsx,tsx}"
specPattern: "**/*.spec.{js,ts,jsx,tsx}"
};
`
Expand All @@ -22,7 +22,7 @@ module.exports = (on, config) => {
exports['Injected overridden webpack template cypress.config.ts'] = `
export default {
componentFolder: "cypress/component",
testFiles: "**/*.spec.{js,ts,jsx,tsx}"
specPattern: "**/*.spec.{js,ts,jsx,tsx}"
};
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ describe('init component tests script', () => {
expect(JSON.stringify(injectedCode.default, null, 2)).to.equal(JSON.stringify(
{
componentFolder: 'cypress/component',
testFiles: '**/*.spec.{js,ts,jsx,tsx}',
specPattern: '**/*.spec.{js,ts,jsx,tsx}',
},
null,
2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ async function injectAndShowCypressConfig (
) {
const configToInject = {
componentFolder,
testFiles: '**/*.spec.{js,ts,jsx,tsx}',
specPattern: '**/*.spec.{js,ts,jsx,tsx}',
}

await injectOrShowConfigCode(() => insertValuesInConfigFile(cypressJsonPath, configToInject), {
Expand Down
4 changes: 2 additions & 2 deletions npm/react/examples/find-webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ Next, create a `cypress.json` with some basic configuration:
```json
{
"component": {
"testFiles": "**/*.test.{js,ts,jsx,tsx}",
"specPattern": "**/*.test.{js,ts,jsx,tsx}",
"componentFolder": "src"
}
}
```

Here we are adding some Component Testing specific options, hence the `"component"` key. `"componentFolder"` is where all the components and tests are located, and `"testFiles"` is the pattern to search for test files.
Here we are adding some Component Testing specific options, hence the `"component"` key. `"componentFolder"` is where all the components and tests are located, and `"specPattern"` is the pattern to search for test files.

The last thing we need to is tell Cypress to use `@cypress/webpack-dev-server` for component tests. Plugins are explained in detail in the [Cypress documentation](https://on.cypress.io/installing-plugins). By default plugins are loaded from `cypress/plugins/index.js`. Create that file and add:

Expand Down
2 changes: 1 addition & 1 deletion npm/vite-dev-server/cypress/new-signature/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = (on, config) => {
)
})

config.testFiles = '**/smoke.spec.ts'
config.component.specPattern = '**/smoke.spec.ts'

return config
}
3 changes: 2 additions & 1 deletion packages/config/__snapshots__/index_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ exports['src/index .getBreakingKeys returns list of breaking config keys 1'] = [
"experimentalShadowDomSupport",
"firefoxGcInterval",
"nodeVersion",
"nodeVersion"
"nodeVersion",
"testFiles"
]

exports['src/index .getDefaultValues returns list of public config keys 1'] = {
Expand Down
5 changes: 5 additions & 0 deletions packages/config/lib/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ export const breakingOptions: Array<BreakingOption> = [
errorKey: 'NODE_VERSION_DEPRECATION_BUNDLED',
isWarning: true,
},
{
name: 'testFiles',
errorKey: 'TEST_FILES_DEPRECATION',
isWarning: false,
},
]

export const breakingRootOptions: Array<BreakingOption> = [
Expand Down
7 changes: 6 additions & 1 deletion packages/data-context/src/sources/migration/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type ConfigOptions = {
component: Record<string, unknown>
}

type ResolvedConfigOptions = Cypress.ResolvedConfigOptions & {
testFiles: string | string[]
ignoreTestFiles: string | string[]
}

/**
* config format pre-10.0
*/
Expand Down Expand Up @@ -361,7 +366,7 @@ export function reduceConfig (cfg: OldCypressConfig): ConfigOptions {
}

if (key === 'e2e' || key === 'component') {
const value = val as Cypress.ResolvedConfigOptions
const value = val as ResolvedConfigOptions

if (!value) {
return acc
Expand Down
53 changes: 53 additions & 0 deletions packages/errors/__snapshot-html__/TEST_FILES_DEPRECATION.html

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

21 changes: 21 additions & 0 deletions packages/errors/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,27 @@ export const AllCypressErrors = {
`
},

TEST_FILES_DEPRECATION: (errShape: BreakingErrResult) => {
const code = errPartial`
{
e2e: {
specPattern: '...',
},
component: {
specPattern: '...',
},
}`

return errTemplate`\
The ${fmt.highlight(errShape.name)} configuration option is now invalid when set on the config object in ${fmt.cypressVersion(`10.0.0`)}.
It is now renamed to ${fmt.highlight('specPattern')} and configured separately as a testing type property: ${fmt.highlightSecondary('e2e.specPattern')} and ${fmt.highlightSecondary('component.specPattern')}
${fmt.code(code)}
https://on.cypress.io/migration-guide`
},

} as const

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down
5 changes: 5 additions & 0 deletions packages/errors/test/unit/visualSnapshotErrors_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,5 +1101,10 @@ describe('visual error templates', () => {
default: ['custom.config.js', 'custom.json'],
}
},
TEST_FILES_DEPRECATION: () => {
return {
default: [{ name: 'testFiles', configFile: '/path/to/cypress.config.js.ts' }],
}
},
})
})
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 @@ -411,15 +411,15 @@ describe('lib/cypress', () => {
})
})

it('runs project by limiting spec files via config.testFiles string glob pattern', function () {
it('runs project by limiting spec files via config.e2e.specPattern string glob pattern', function () {
return cypress.start([`--run-project=${this.todosPath}`, `--config={"e2e":{"specPattern":"${this.todosPath}/tests/test2.coffee"}}`])
.then(() => {
expect(browsers.open).to.be.calledWithMatch(ELECTRON_BROWSER, { url: 'http://localhost:8888/__/#/specs/runner?file=tests/test2.coffee' })
this.expectExitWith(0)
})
})

it('runs project by limiting spec files via config.testFiles as a JSON array of string glob patterns', function () {
it('runs project by limiting spec files via config.e2e.specPattern as a JSON array of string glob patterns', function () {
return cypress.start([`--run-project=${this.todosPath}`, '--config={"e2e":{"specPattern":["**/test2.coffee","**/test1.js"]}}'])
.then(() => {
expect(browsers.open).to.be.calledWithMatch(ELECTRON_BROWSER, { url: 'http://localhost:8888/__/#/specs/runner?file=tests/test2.coffee' })
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface FullConfig extends Partial<Cypress.RuntimeConfigOptions & Cypre
// and are required when creating a project.
export type ReceivedCypressOptions =
Pick<Cypress.RuntimeConfigOptions, 'hosts' | 'projectName' | 'clientRoute' | 'devServerPublicPathRoute' | 'namespace' | 'report' | 'socketIoCookie' | 'configFile' | 'isTextTerminal' | 'isNewProject' | 'proxyUrl' | 'browsers' | 'browserUrl' | 'socketIoRoute' | 'arch' | 'platform' | 'spec' | 'specs' | 'browser' | 'version' | 'remote'>
& Pick<Cypress.ResolvedConfigOptions, 'chromeWebSecurity' | 'supportFolder' | 'experimentalSourceRewriting' | 'fixturesFolder' | 'reporter' | 'reporterOptions' | 'screenshotsFolder' | 'pluginsFile' | 'supportFile' | 'baseUrl' | 'viewportHeight' | 'viewportWidth' | 'port' | 'experimentalInteractiveRunEvents' | 'userAgent' | 'downloadsFolder' | 'env' | 'testFiles' | 'excludeSpecPattern' | 'specPattern'> // TODO: Figure out how to type this better.
& Pick<Cypress.ResolvedConfigOptions, 'chromeWebSecurity' | 'supportFolder' | 'experimentalSourceRewriting' | 'fixturesFolder' | 'reporter' | 'reporterOptions' | 'screenshotsFolder' | 'pluginsFile' | 'supportFile' | 'baseUrl' | 'viewportHeight' | 'viewportWidth' | 'port' | 'experimentalInteractiveRunEvents' | 'userAgent' | 'downloadsFolder' | 'env' | 'excludeSpecPattern' | 'specPattern'> // TODO: Figure out how to type this better.

export interface SampleConfigFile{
status: 'changes' | 'valid' | 'skipped' | 'error'
Expand Down
20 changes: 20 additions & 0 deletions system-tests/__snapshots__/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,23 @@ Please remove this option or add this as an e2e testing type property: e2e.baseU
https://on.cypress.io/migration-guide
`

exports['e2e config throws an error if testFiles is set on the config file 1'] = `
The testFiles configuration option is now invalid when set on the config object in Cypress version 10.0.0.
It is now renamed to specPattern and configured separately as a testing type property: e2e.specPattern and component.specPattern
{
e2e: {
specPattern: '...',
},
component: {
specPattern: '...',
},
}
https://on.cypress.io/migration-guide
`
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
testFiles: 'cypress/support/e2e.js',
e2e: {},
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
'pluginsFile': false,
'fixturesFolder': 'cypress/e2e',
'testFiles': '**/*spec.js',
'e2e': {
'supportFile': false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { devServer } = require('@cypress/webpack-dev-server')
module.exports = {
component: {
supportFile: false,
testFiles: '**/*cy-spec.{js,jsx,ts,tsx}',
specPattern: '**/*cy-spec.{js,jsx,ts,tsx}',
componentFolder: 'src',
devServer,
devServerConfig: {
Expand Down
11 changes: 11 additions & 0 deletions system-tests/test/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,15 @@ describe('e2e config', () => {
snapshot: true,
})
})

it('throws an error if testFiles is set on the config file', async function () {
await Fixtures.scaffoldProject('invalid-root-level-config')

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

3 comments on commit 5670344

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5670344 Mar 11, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.0/linux-x64/10.0-release-567034459089d9d53dfab5556cb9369fb335c3db/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5670344 Mar 11, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.0/darwin-x64/10.0-release-567034459089d9d53dfab5556cb9369fb335c3db/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 5670344 Mar 11, 2022

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 platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.0.0/win32-x64/10.0-release-567034459089d9d53dfab5556cb9369fb335c3db/cypress.tgz

Please sign in to comment.