Skip to content

Commit

Permalink
feat: show better error message if testing type is not configured (#2…
Browse files Browse the repository at this point in the history
…2000)

* feat: show better error message if testing type is not configured

* Add tests

* Update tests

* Fix some tests

* Fix some tests

* Fix test

* Fix tests

* Update packages/errors/src/errors.ts

Co-authored-by: Jennifer Shehane <jennifer@cypress.io>

* Update with code review

* Fix test

* Add on link

Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
  • Loading branch information
estrada9166 and jennifer-shehane authored Jun 7, 2022
1 parent b24a77d commit e5c1f91
Show file tree
Hide file tree
Showing 24 changed files with 139 additions and 7 deletions.
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ commands:
command: |
if [[ -f cypress.json ]]; then
rm -rf cypress.json
echo 'module.exports = {}' > cypress.config.js
echo 'module.exports = { e2e: {} }' > cypress.config.js
fi
- run:
name: Rename support file
Expand Down Expand Up @@ -2211,7 +2211,7 @@ jobs:
CYPRESS_INTERNAL_FORCE_SCAFFOLD: "1"
command: |
rm -rf cypress.json
echo 'module.exports = {}' > cypress.config.js
echo 'module.exports = { e2e: {} }' > cypress.config.js
- run:
name: Rename support file
working_directory: test-binary
Expand Down
4 changes: 4 additions & 0 deletions packages/data-context/src/data/ProjectLifecycleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,10 @@ export class ProjectLifecycleManager {
return
}

if (this.ctx.isRunMode && this.loadedConfigFile && !this.isTestingTypeConfigured(testingType)) {
return this.ctx.onError(getError('TESTING_TYPE_NOT_CONFIGURED', testingType))
}

if (this.ctx.isRunMode || (this.isTestingTypeConfigured(testingType) && !(this.ctx.coreData.forceReconfigureProject && this.ctx.coreData.forceReconfigureProject[testingType]))) {
this._configManager.loadTestingType()
}
Expand Down
43 changes: 43 additions & 0 deletions packages/errors/__snapshot-html__/TESTING_TYPE_NOT_CONFIGURED.html

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

10 changes: 10 additions & 0 deletions packages/errors/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,16 @@ export const AllCypressErrors = {
the devServer config as a ${fmt.highlight(devServerConfigFile)} option.
`
},

TESTING_TYPE_NOT_CONFIGURED: (testingType: TestingType) => {
return errTemplate`
The testing type selected (${fmt.highlight(testingType)}) is not configured in your config file.
Please run ‘cypress open’ and choose your testing type to automatically update your configuration file.
https://on.cypress.io/configuration
`
},
} 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 @@ -1167,5 +1167,10 @@ describe('visual error templates', () => {
default: ['vite', '/dev/project', ['vite.config.js', 'vite.config.ts']],
}
},
TESTING_TYPE_NOT_CONFIGURED: () => {
return {
default: ['component'],
}
},
})
})
1 change: 1 addition & 0 deletions packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ enum ErrorTypeEnum {
SETUP_NODE_EVENTS_INVALID_EVENT_NAME_ERROR
SETUP_NODE_EVENTS_IS_NOT_FUNCTION
SUPPORT_FILE_NOT_FOUND
TESTING_TYPE_NOT_CONFIGURED
TESTS_DID_NOT_START_FAILED
TESTS_DID_NOT_START_RETRYING
TEST_FILES_RENAMED
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
exports['testing type not configured error on run mode / reports correct exit code when failing attempting to run e2e'] = `
The testing type selected (e2e) is not configured in your config file.
Please run ‘cypress open’ and choose your testing type to automatically update your configuration file.
https://on.cypress.io/configuration
`

exports['testing type not configured error on run mode / reports correct exit code when failing attempting to run component'] = `
The testing type selected (component) is not configured in your config file.
Please run ‘cypress open’ and choose your testing type to automatically update your configuration file.
https://on.cypress.io/configuration
`
4 changes: 3 additions & 1 deletion system-tests/projects/busted-support-file/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = {}
module.exports = {
e2e: {},
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module.exports = {
component: {
baseUrl: 'https://foo.com',
devServer: {
framework: 'create-react-app',
bundler: 'webpack',
},
},
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module.exports = {
component: {
experimentalSessionAndOrigin: true,
devServer: {
framework: 'create-react-app',
bundler: 'webpack',
},
},
}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = {}
module.exports = {
e2e: {},
}
4 changes: 3 additions & 1 deletion system-tests/projects/ts-proj-4-5/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { defineConfig } from 'cypress'

export default defineConfig({})
export default defineConfig({
e2e: {},
})
4 changes: 3 additions & 1 deletion system-tests/projects/ts-proj/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = {}
module.exports = {
e2e: {},
}
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
module.exports = {}
module.exports = {
e2e: {},
}
2 changes: 2 additions & 0 deletions system-tests/test/cookies_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ describe('e2e cookies', () => {
https: true,
}],
settings: {
e2e: {},
hosts: {
'*.foo.com': '127.0.0.1',
'*.bar.net': '127.0.0.1',
Expand Down Expand Up @@ -339,6 +340,7 @@ describe('cross-origin cookies, set:cookies', () => {
'*.bar.net': '127.0.0.1',
'*.cypress.test': '127.0.0.1',
},
e2e: {},
},

})
Expand Down
1 change: 1 addition & 0 deletions system-tests/test/cy_origin_error_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('e2e cy.origin errors', () => {
onServer,
}],
settings: {
e2e: {},
hosts: {
'*.foobar.com': '127.0.0.1',
},
Expand Down
1 change: 1 addition & 0 deletions system-tests/test/cy_origin_retries_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('e2e cy.origin retries', () => {
hosts: {
'*.foobar.com': '127.0.0.1',
},
e2e: {},
},
})

Expand Down
2 changes: 2 additions & 0 deletions system-tests/test/form_submissions_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('e2e forms', () => {
context('<form> submissions', () => {
systemTests.setup({
settings: {
e2e: {},
env: {
PATH_TO_LARGE_IMAGE: pathToLargeImage,
},
Expand Down Expand Up @@ -149,6 +150,7 @@ describe('e2e forms', () => {
systemTests.it('passes with http on localhost', {
config: {
baseUrl: `http://localhost:${HTTP_PORT}`,
e2e: {},
},
spec: 'form_submission_multipart.cy.js',
snapshot: true,
Expand Down
1 change: 1 addition & 0 deletions system-tests/test/session_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe('e2e sessions', () => {
hosts: {
'*.foo.com': '127.0.0.1',
},
e2e: {},
},
})

Expand Down
1 change: 1 addition & 0 deletions system-tests/test/stdout_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('e2e stdout', () => {
'www.apple.com': '127.0.0.1',
'*.cypress.io': '127.0.0.1',
},
e2e: {},
},
})

Expand Down
19 changes: 19 additions & 0 deletions system-tests/test/testing_type_not_configured_error_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const systemTests = require('../lib/system-tests').default

describe('testing type not configured error on run mode', () => {
systemTests.setup()

systemTests.it('reports correct exit code when failing attempting to run e2e', {
project: 'simple-ct',
testingType: 'e2e',
snapshot: true,
expectedExitCode: 1,
})

systemTests.it('reports correct exit code when failing attempting to run component', {
project: 'e2e',
testingType: 'component',
snapshot: true,
expectedExitCode: 1,
})
})
1 change: 1 addition & 0 deletions system-tests/test/viewport_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('e2e viewport', () => {
settings: {
viewportWidth: 800,
viewportHeight: 600,
e2e: {},
},
})

Expand Down
3 changes: 3 additions & 0 deletions system-tests/test/visit_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('e2e visit', () => {
settings: {
responseTimeout: 500,
pageLoadTimeout: 1000,
e2e: {},
},
servers: {
port: 3434,
Expand Down Expand Up @@ -194,6 +195,7 @@ describe('e2e visit', () => {
systemTests.setup({
settings: {
responseTimeout: 2000,
e2e: {},
},
servers: {
port: 3434,
Expand All @@ -213,6 +215,7 @@ describe('e2e visit', () => {
systemTests.setup({
settings: {
pageLoadTimeout: 1000,
e2e: {},
},
servers: {
port: 3434,
Expand Down
1 change: 1 addition & 0 deletions system-tests/test/web_security_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('e2e web security', () => {
'*.bar.com': '127.0.0.1',
'*.foobar.com': '127.0.0.1',
},
e2e: {},
},
})

Expand Down

2 comments on commit e5c1f91

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e5c1f91 Jun 7, 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.1.0/linux-x64/develop-e5c1f91652647f796710b6308ae2984977434220/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on e5c1f91 Jun 7, 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.1.0/darwin-x64/develop-e5c1f91652647f796710b6308ae2984977434220/cypress.tgz

Please sign in to comment.