Skip to content

Commit 678bede

Browse files
committed
Merge branch 'develop' into 10.0-release
* develop: feat: gray out the path to system node in cypress run header (#20121) feat: redesign server errors (#20072) test: fix awesome-typescript-loader test and remove test-binary job (#20131) fix: Fix issues with stack traces and command log in Chrome 99 (#20049) fix: `cy.type(' ')` fires click event on button-like elements. (#20067) fix: `change`, `input` events are not fired when the same option is selected again. (#19623) build: publish vue3 on latest (#20099) chore: release @cypress/webpack-preprocessor-v5.11.1 chore: release @cypress/webpack-dev-server-v1.8.1 fix: detect newly added specs in dev-server compilation (#17950) chore: Remove pkg/driver //@ts-nocheck part 3 (#19837) chore: set up semantic-pull-request GitHub Action (#20091) chore: release @cypress/react-v5.12.2 fix: remove nullish coalescing in js files to support node 12 (#20094) docs: update @cypress/webpack-preprocessor links (#19902) refactor: use aliases instead of meta (#19566)
2 parents 8a6768f + 4b50f9e commit 678bede

File tree

263 files changed

+13897
-1028
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

263 files changed

+13897
-1028
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
* text=auto
22

33
*.json text eol=lf
4+
5+
packages/errors/__snapshot-html__/** linguist-generated=true

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Cached Theme Material Design.pak
1515

1616
# from data-context, compiled .js files
1717
packages/data-context/src/**/*.js
18+
packages/errors/src/**/*.js
19+
packages/errors/test/**/*.js
1820

1921
# from driver
2022
packages/driver/cypress/videos
@@ -61,6 +63,7 @@ packages/socket/lib/*.js
6163

6264
# from system-tests
6365
system-tests/.projects
66+
system-tests/.http-mitm-proxy
6467
system-tests/fixtures/large-img
6568

6669
# from npm/react
@@ -76,6 +79,11 @@ system-tests/fixtures/large-img
7679
# from runner-ct
7780
/packages/runner-ct/cypress/screenshots
7881

82+
# from errors
83+
/packages/errors/__snapshot-images__
84+
/packages/errors/__snapshot-md__
85+
/packages/errors/__snapshot-html-local__
86+
7987
# graphql, auto-generated
8088
/packages/launchpad/src/generated
8189
/packages/app/src/generated

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"i18n-ally.keystyle": "nested",
3737

3838
// Volar is the main extension that powers Vue's language features.
39-
"volar.autoCompleteRefs": false,
39+
// These are commented out because they slow down node development
40+
// "volar.autoCompleteRefs": false,
4041
// "volar.takeOverMode.enabled": true
4142
}

browser-versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"chrome:beta": "98.0.4758.80",
2+
"chrome:beta": "99.0.4844.27",
33
"chrome:stable": "98.0.4758.80"
44
}

circle.yml

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,7 @@ jobs:
997997
- run:
998998
name: Linting 🧹
999999
command: |
1000+
yarn clean
10001001
git clean -df
10011002
yarn lint
10021003
- run:
@@ -1098,12 +1099,14 @@ jobs:
10981099
# run type checking for each individual package
10991100
- run: yarn lerna run types
11001101
- verify-mocha-results:
1101-
expectedResultCount: 9
1102+
expectedResultCount: 10
11021103
- store_test_results:
11031104
path: /tmp/cypress
11041105
# CLI tests generate HTML files with sample CLI command output
11051106
- store_artifacts:
11061107
path: cli/test/html
1108+
- store_artifacts:
1109+
path: packages/errors/__snapshot-images__
11071110
- store-npm-logs
11081111

11091112
unit-tests-release:
@@ -1941,14 +1944,6 @@ jobs:
19411944
browser: "electron"
19421945
pull_request_id: 524
19431946

1944-
test-binary-against-awesome-typescript-loader:
1945-
<<: *defaults
1946-
steps:
1947-
- test-binary-against-repo:
1948-
repo: cypress-test-awesome-typescript-loader
1949-
browser: "electron"
1950-
pull_request_id: 8
1951-
19521947
test-binary-against-kitchensink-firefox:
19531948
<<: *defaults
19541949
resource_class: medium
@@ -2292,26 +2287,6 @@ linux-workflow: &linux-workflow
22922287
- test-binary-against-kitchensink:
22932288
requires:
22942289
- create-build-artifacts
2295-
# when working on a feature or a fix,
2296-
# you are probably working in a branch
2297-
# and you want to run a specific PR in the cypress-example-recipes
2298-
# against this branch. This workflow job includes
2299-
# the job but only when it runs on specific branch
2300-
# DO NOT DELETE THIS JOB BEFORE MERGING TO DEVELOP
2301-
# on "develop" this branch will be ignored anyway
2302-
# and someone else might use this job definition for another
2303-
# feature branch and would just update the branch filter
2304-
# - test-binary-against-recipe-pull-request:
2305-
# name: Test cypress run parsing
2306-
# filters:
2307-
# branches:
2308-
# only:
2309-
# - cli-to-module-api-7760
2310-
# requires:
2311-
# - create-build-artifacts
2312-
- test-binary-against-awesome-typescript-loader:
2313-
requires:
2314-
- create-build-artifacts
23152290
- test-binary-and-npm-against-other-projects:
23162291
context: test-runner:trigger-test-jobs
23172292
<<: *mainBuildFilters

guides/error-handling.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
## Error Handling in Cypress
2+
3+
Clear, consistent, errors are one of the important parts of the Cypress experience. When something goes wrong, there should be clear, actionable feedback for the user about exactly *what* went wrong, *where* it went wrong, and next steps on how to fix.
4+
5+
### @packages/errors
6+
7+
All error related logic for the server should be added to `@packages/errors`. This logic has been separated out from the `@packages/server` to enable strict type checking & use in other packages we have added in the `10.0-release` branch.
8+
9+
Summary of the Errors package:
10+
11+
- `errors.ts`: A key/value mapping of known errors to functions returning "ErrorTemplates", described below, also includes/re-exports several helper utilities:
12+
- `get` / `getError`: builds & retrieves the error as a `CypressError`, should be the main way we retrieve errors throughout Cypress. Aliased as `errors.get` for existing use in the server package
13+
- `throw` / `throwErr`: Get & throw the error, so we can spy/stub it in a test. Aliased as `errors.throw` for existing use in the server package
14+
- `logWarning`: Logs the error as a warning to the console, aliased as `errors.log` for existing use in the server package
15+
- `errTemplate.ts`: Tagged template literal formatting the error as described below
16+
- `stackUtils.ts`: Utilities for working with a stack trace, extended by the driver package
17+
18+
### errTemplate
19+
20+
The `errTemplate` is a tagged template literal. It allows us to maintain consistent behavior & formatting in our error messages, when we see a variable, we format it depending on the target environment.
21+
22+
The error message returns a message that defaults to being formatted for the terminal, and has a `forBrowser` method which returns the error message where the variables are wrapped in backticks '`' for Markdown display in the browser.
23+
24+
Return Value of `errTemplate` (`ErrTemplateResult`):
25+
26+
```ts
27+
{
28+
// Will always exist, this is the terminal-formatted error message
29+
message: string,
30+
// Will always exist, this is the browser-formatted error message
31+
messageMarkdown: string,
32+
details?: string, // Exists if there is `details()` call in the errTemplate
33+
originalError?: ErrorLike // Exists if an error was passed into the `details()`
34+
}
35+
```
36+
37+
#### Example:
38+
39+
```ts
40+
CANNOT_TRASH_ASSETS: (arg1: string) => {
41+
return errTemplate`\
42+
Warning: We failed to trash the existing run results.
43+
44+
This error will not alter the exit code.
45+
46+
${details(arg1)}`
47+
},
48+
```
49+
50+
In this case, `arg1` will be highlighted in yellow when printed to the terminal.
51+
52+
53+
```ts
54+
PLUGINS_FILE_ERROR: (arg1: string, arg2: Error) => {
55+
return errTemplate`\
56+
The plugins file is missing or invalid.
57+
58+
Your \`pluginsFile\` is set to ${arg1}, but either the file is missing, it contains a syntax error, or threw an error when required. The \`pluginsFile\` must be a \`.js\`, \`.ts\`, or \`.coffee\` file.
59+
60+
Or you might have renamed the extension of your \`pluginsFile\`. If that's the case, restart the test runner.
61+
62+
Please fix this, or set \`pluginsFile\` to \`false\` if a plugins file is not necessary for your project.
63+
64+
${details(arg2)}
65+
`
66+
},
67+
```
68+
69+
`arg1` will be highlighted in `blue` for the terminal, and wrapped in backticks when called with `forBrowser`. Details will be printed in `yellow` as a stack trace when printed to the terminal, or shown as a stack-trace in the browser.
70+
71+
### Error Wrapping
72+
73+
Any time we know about an edge case that is an error, we should define an error in `errors.ts`. This error should be retrieved by `getError`, which converts it to a `CypressError`.
74+
75+
The `CypressError` is an `Error` containing the message returned from the `errTemplate`. The `stack` is set to that of the `originalError` if it exists (i.e. the error object passed into `details`), otherwise it's the `stack` from where the `getError` / `throwError` is called.
76+
77+
78+
The `CypressError` has an `isCypressErr` prop which we use as a duck-type guard against exiting the process when logging exceptions. It also maintains a reference to the `originalError` if it exists.
79+
80+
### Child-Process Errors
81+
82+
All errors that occur in a child process spawned by Cypress should be sent over the `ipc` bridge using `util.serializeError`.
83+
84+
This ensures the `name`, `message`, `stack`, and any other relevant details are preserved and can be handled by the standard process of Cypress' error standardization / wrapping.
85+

npm/vite-dev-server/src/makeCypressPlugin.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ export const makeCypressPlugin = (
5555
base = config.base
5656
},
5757
async transformIndexHtml () {
58-
debug('transformIndexHtml with base', base)
5958
const indexHtmlPath = indexHtml ? resolve(projectRoot, indexHtml) : resolve(__dirname, '..', 'index.html')
6059
const indexHtmlContent = await readFile(indexHtmlPath, { encoding: 'utf8' })
6160
// find </body> last index

npm/vite-dev-server/src/resolveServerConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface StartDevServerOptions {
2525
indexHtml?: string
2626
}
2727

28-
export const resolveServerConfig = async ({ viteConfig, options, indexHtml }: StartDevServerOptions): Promise<InlineConfig> => {
28+
export const resolveServerConfig = async ({ viteConfig, options }: StartDevServerOptions): Promise<InlineConfig> => {
2929
const { projectRoot, supportFile, namespace } = options.config
3030

3131
const requiredOptions: InlineConfig = {

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"bump": "node ./scripts/binary.js bump",
1818
"check-node-version": "node scripts/check-node-version.js",
1919
"check-terminal": "node scripts/check-terminal.js",
20-
"clean": "lerna run clean --parallel --no-bail",
20+
"clean": "lerna run clean --parallel --no-bail || echo 'ok, errors while cleaning'",
2121
"check-ts": "gulp checkTs",
2222
"clean-deps": "find . -depth -name node_modules -type d -exec rm -rf {} \\;",
2323
"clean-untracked-files": "git clean -d -f",
@@ -28,6 +28,7 @@
2828
"cypress:open:debug": "node ./scripts/debug.js cypress:open",
2929
"precypress:run": "yarn ensure-deps",
3030
"cypress:run": "cypress run --dev",
31+
"cypress:run:ct": "cypress run-ct --dev",
3132
"precypress:run:debug": "yarn ensure-deps",
3233
"cypress:run:debug": "node ./scripts/debug.js cypress:run",
3334
"cypress:verify": "cypress verify --dev",
@@ -50,7 +51,7 @@
5051
"stop-only": "npx stop-only --skip .cy,.publish,.projects,node_modules,dist,dist-test,fixtures,lib,bower_components,src,__snapshots__ --exclude cypress-tests.ts,*only.cy.js",
5152
"stop-only-all": "yarn stop-only --folder packages",
5253
"pretest": "yarn ensure-deps",
53-
"test": "yarn lerna exec yarn test --scope cypress --scope \"'@packages/{config,data-context,electron,extension,https-proxy,launcher,net-stubbing,network,proxy,rewriter,socket}'\"",
54+
"test": "yarn lerna exec yarn test --scope cypress --scope \"'@packages/{config,errors,data-context,electron,extension,https-proxy,launcher,net-stubbing,network,proxy,rewriter,socket}'\"",
5455
"test-debug": "lerna exec yarn test-debug --ignore \"'@packages/{driver,root,static,web-config}'\"",
5556
"pretest-e2e": "yarn ensure-deps",
5657
"test-integration": "lerna exec yarn test-integration --ignore \"'@packages/{driver,root,static,web-config}'\"",
@@ -125,7 +126,6 @@
125126
"@typescript-eslint/eslint-plugin": "4.18.0",
126127
"@typescript-eslint/parser": "4.18.0",
127128
"@urql/introspection": "^0.3.0",
128-
"ansi-styles": "3.2.1",
129129
"arg": "4.1.2",
130130
"ascii-table": "0.0.9",
131131
"autobarrel": "^1.1.0",
@@ -213,7 +213,7 @@
213213
"snap-shot-it": "7.9.3",
214214
"start-server-and-test": "1.10.8",
215215
"stop-only": "3.0.1",
216-
"strip-ansi": "4.0.0",
216+
"strip-ansi": "6.0.0",
217217
"term-to-html": "1.2.0",
218218
"terminal-banner": "1.1.0",
219219
"through": "2.3.8",

0 commit comments

Comments
 (0)