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: Add before:run event #14238

Merged
merged 42 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
08ab021
handle deleted videos
chrisbreiding Dec 9, 2020
0321575
refactor before:browser:launch handling into own file
chrisbreiding Dec 9, 2020
8d139f0
implement before:spec event
chrisbreiding Dec 11, 2020
0ac5233
fix tests
chrisbreiding Dec 11, 2020
875605e
disable video to prevent flakiness
chrisbreiding Dec 11, 2020
028108b
Merge branch 'develop' into TR-543-before-spec-event
chrisbreiding Dec 11, 2020
d36d74f
Merge branch 'develop' into TR-543-before-spec-event
chrisbreiding Dec 14, 2020
c294bca
don't fire before:spec in interactive mode
chrisbreiding Dec 14, 2020
16226bc
add experimental flag for run events
chrisbreiding Dec 14, 2020
8519595
alphabetize
chrisbreiding Dec 14, 2020
27f75ca
add after:spec event
chrisbreiding Dec 14, 2020
34dd697
ensure config is an object
chrisbreiding Dec 15, 2020
9c1d771
Merge branch 'develop' into TR-543-before-spec-event
chrisbreiding Dec 15, 2020
97d6dde
add experimental flag to schema and types
chrisbreiding Dec 15, 2020
3c2e6fc
Merge branch 'TR-543-before-spec-event' into TR-544-after-spec-event
chrisbreiding Dec 15, 2020
95e8d16
update experimentalRunEvents descriptions
chrisbreiding Dec 15, 2020
6590fcc
Merge branch 'TR-544-after-spec-event' into TR-536-handled-deleted-vi…
chrisbreiding Dec 15, 2020
a7524ef
Merge branch 'develop' into TR-536-handled-deleted-videos
chrisbreiding Dec 16, 2020
38124a9
Merge branch 'develop' into TR-543-before-spec-event
chrisbreiding Dec 16, 2020
8497af8
Merge branch 'TR-543-before-spec-event' into TR-544-after-spec-event
chrisbreiding Dec 16, 2020
5bda8ba
Merge branch 'TR-544-after-spec-event' into TR-536-handled-deleted-vi…
chrisbreiding Dec 16, 2020
b6ade74
Merge branch 'TR-536-handled-deleted-videos' of github.com:cypress-io…
chrisbreiding Dec 16, 2020
ca59a74
add tests
chrisbreiding Dec 16, 2020
2b91bb1
update snapshot
chrisbreiding Dec 16, 2020
01312e9
update snapshots
chrisbreiding Dec 16, 2020
f49f934
Merge branch 'develop' into TR-544-after-spec-event
chrisbreiding Dec 17, 2020
82567aa
Merge branch 'TR-544-after-spec-event' into TR-536-handled-deleted-vi…
chrisbreiding Dec 17, 2020
679ba6e
update snapshot
chrisbreiding Dec 17, 2020
dcc236b
add types for spec events
chrisbreiding Dec 17, 2020
aef8c45
Merge branch 'TR-544-after-spec-event' into TR-536-handled-deleted-vi…
chrisbreiding Dec 17, 2020
be3b711
Merge branch 'develop' into TR-544-after-spec-event
chrisbreiding Dec 18, 2020
ef1a3e1
Merge branch 'TR-544-after-spec-event' into TR-536-handled-deleted-vi…
chrisbreiding Dec 18, 2020
9032fb6
turn off video for flaky test
chrisbreiding Dec 18, 2020
9d4ba21
Merge branch 'develop' into TR-536-handled-deleted-videos
chrisbreiding Dec 18, 2020
684867d
feat: Add before:run event
chrisbreiding Dec 18, 2020
96c0590
Merge branch 'develop' into TR-536-handled-deleted-videos
chrisbreiding Dec 18, 2020
23d05a2
Merge branch 'develop' into TR-536-handled-deleted-videos
chrisbreiding Dec 21, 2020
718c5cd
Merge branch 'TR-536-handled-deleted-videos' of github.com:cypress-io…
chrisbreiding Dec 21, 2020
967306b
revert change to shouldUploadVideo
chrisbreiding Dec 21, 2020
4b487d0
Merge branch 'develop' into TR-536-handled-deleted-videos
chrisbreiding Dec 21, 2020
ceca81a
Merge branch 'TR-536-handled-deleted-videos' into TR-538-before-run-e…
chrisbreiding Dec 21, 2020
39e798e
merged
chrisbreiding Dec 21, 2020
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
2 changes: 1 addition & 1 deletion cli/schema/cypress.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
"experimentalRunEvents": {
"type": "boolean",
"default": false,
"description": "Allows listening to the `before:spec` and `after:spec` events in the plugins file."
"description": "Allows listening to the `before:run`, `before:spec`, and `after:spec` events in the plugins file."
},
"experimentalSourceRewriting": {
"type": "boolean",
Expand Down
21 changes: 20 additions & 1 deletion cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2577,7 +2577,7 @@ declare namespace Cypress {
*/
firefoxGcInterval: Nullable<number | { runMode: Nullable<number>, openMode: Nullable<number> }>
/**
* Allows listening to the `before:spec` and `after:spec` events in the plugins file.
* Allows listening to the `before:run`, `before:spec`, and `after:spec` events in the plugins file.
* @default false
*/
experimentalRunEvents: boolean
Expand Down Expand Up @@ -4999,9 +4999,28 @@ declare namespace Cypress {
[key: string]: Task
}

interface SystemDetails {
osName: string
osVersion: string
}

interface BeforeRunDetails {
browser: Browser
config: ConfigOptions
cypressVersion: string
group?: string
parallel: boolean
runUrl?: string
specs: Spec[]
specPattern: string[]
system: SystemDetails
tag?: string
}

interface PluginEvents {
(action: 'after:screenshot', fn: (details: ScreenshotDetails) => void | AfterScreenshotReturnObject | Promise<AfterScreenshotReturnObject>): void
(action: 'after:spec', fn: (spec: Spec, results: CypressCommandLine.RunResult) => void | Promise<void>): void
(action: 'before:run', fn: (runDetails: BeforeRunDetails) => void | Promise<void>): void
(action: 'before:spec', fn: (spec: Spec) => void | Promise<void>): void
(action: 'before:browser:launch', fn: (browser: Browser, browserLaunchOptions: BrowserLaunchOptions) => void | BrowserLaunchOptions | Promise<BrowserLaunchOptions>): void
(action: 'file:preprocessor', fn: (file: FileObject) => string | Promise<string>): void
Expand Down
87 changes: 74 additions & 13 deletions packages/server/__snapshots__/4_plugin_run_events_spec.ts.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
exports['e2e plugin run events / fails if experimentalRunEvents is not enabled'] = `
The following validation error was thrown by your plugins file (\`/foo/bar/.projects/plugin-run-events/cypress/plugins/index.js\`).

Error: The \`before:spec\` event requires the experimentalRunEvents flag to be enabled.

To enable it, set \`"experimentalRunEvents": true\` in your cypress.json
[stack trace lines]
`

exports['e2e plugin run events / sends events'] = `

====================================================================================================
Expand All @@ -21,6 +12,8 @@ exports['e2e plugin run events / sends events'] = `
│ Experiments: experimentalRunEvents=true │
└────────────────────────────────────────────────────────────────────────────────────────────────┘

before:run: cypress/integration/run_events_spec_1.js electron
before:run is awaited

────────────────────────────────────────────────────────────────────────────────────────────────────

Expand All @@ -33,6 +26,8 @@ before:spec is awaited

1 passing

spec:end: cypress/integration/run_events_spec_1.js { tests: 1, passes: 1, failures: 0 }
after:spec is awaited

(Results)

Expand All @@ -48,8 +43,6 @@ before:spec is awaited
│ Spec Ran: run_events_spec_1.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘

spec:end: cypress/integration/run_events_spec_1.js { tests: 1, passes: 1, failures: 0 }
after:spec is awaited

────────────────────────────────────────────────────────────────────────────────────────────────────

Expand All @@ -62,6 +55,8 @@ before:spec is awaited

1 passing

spec:end: cypress/integration/run_events_spec_2.js { tests: 1, passes: 1, failures: 0 }
after:spec is awaited

(Results)

Expand All @@ -77,8 +72,6 @@ before:spec is awaited
│ Spec Ran: run_events_spec_2.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘

spec:end: cypress/integration/run_events_spec_2.js { tests: 1, passes: 1, failures: 0 }
after:spec is awaited

====================================================================================================

Expand All @@ -96,6 +89,74 @@ after:spec is awaited

`

exports['e2e plugin run events / handles video being deleted in after:spec'] = `

====================================================================================================

(Run Starting)

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (after_spec_deletes_video.js) │
│ Searched: cypress/integration/* │
│ Experiments: experimentalRunEvents=true │
└────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────

Running: after_spec_deletes_video.js (1 of 1)


✓ is true

1 passing

Warning: We could not find the video at the following path, so we were unable to process it.

Video path: /foo/bar/.projects/plugin-after-spec-deletes-video/cypress/videos/after_spec_deletes_video.js.mp4

This error will not alter the exit code.

(Results)

┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 1 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: false │
│ Duration: X seconds │
│ Spec Ran: after_spec_deletes_video.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘


====================================================================================================

(Run Finished)


Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ ✔ after_spec_deletes_video.js XX:XX 1 1 - - - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 1 1 - - -


`

exports['e2e plugin run events / fails if experimentalRunEvents is not enabled'] = `
The following validation error was thrown by your plugins file (\`/foo/bar/.projects/plugin-run-events/cypress/plugins/index.js\`).

Error: The \`before:run\` event requires the experimentalRunEvents flag to be enabled.

To enable it, set \`"experimentalRunEvents": true\` in your cypress.json
[stack trace lines]
`

exports['e2e plugin run events / fails run if event handler throws'] = `

====================================================================================================
Expand Down
36 changes: 18 additions & 18 deletions packages/server/__snapshots__/5_spec_isolation_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ exports['e2e spec_isolation fails [electron] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_failing_hook_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -523,7 +523,7 @@ exports['e2e spec_isolation fails [electron] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_failing_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -645,7 +645,7 @@ exports['e2e spec_isolation fails [electron] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_hooks_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -708,7 +708,7 @@ exports['e2e spec_isolation fails [electron] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_passing_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
}
],
"browserPath": "path/to/browser",
Expand Down Expand Up @@ -971,7 +971,7 @@ exports['e2e spec_isolation fails [chrome] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_failing_hook_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -1087,7 +1087,7 @@ exports['e2e spec_isolation fails [chrome] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_failing_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -1209,7 +1209,7 @@ exports['e2e spec_isolation fails [chrome] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_hooks_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -1272,7 +1272,7 @@ exports['e2e spec_isolation fails [chrome] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_passing_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
}
],
"browserPath": "path/to/browser",
Expand Down Expand Up @@ -1535,7 +1535,7 @@ exports['e2e spec_isolation fails [firefox] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_failing_hook_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -1651,7 +1651,7 @@ exports['e2e spec_isolation fails [firefox] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_failing_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -1773,7 +1773,7 @@ exports['e2e spec_isolation fails [firefox] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_hooks_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -1836,7 +1836,7 @@ exports['e2e spec_isolation fails [firefox] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_passing_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
}
],
"browserPath": "path/to/browser",
Expand Down Expand Up @@ -2157,7 +2157,7 @@ exports['e2e spec_isolation failing with retries enabled [electron] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_failing_hook_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -2281,7 +2281,7 @@ exports['e2e spec_isolation failing with retries enabled [electron] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_retrying_spec.js",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
}
],
"browserPath": "path/to/browser",
Expand Down Expand Up @@ -2602,7 +2602,7 @@ exports['e2e spec_isolation failing with retries enabled [chrome] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_failing_hook_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -2726,7 +2726,7 @@ exports['e2e spec_isolation failing with retries enabled [chrome] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_retrying_spec.js",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
}
],
"browserPath": "path/to/browser",
Expand Down Expand Up @@ -3047,7 +3047,7 @@ exports['e2e spec_isolation failing with retries enabled [firefox] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_failing_hook_spec.coffee",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
},
{
"stats": {
Expand Down Expand Up @@ -3171,7 +3171,7 @@ exports['e2e spec_isolation failing with retries enabled [firefox] 1'] = {
"absolute": "/foo/bar/.projects/e2e/cypress/integration/simple_retrying_spec.js",
"specType": "integration"
},
"shouldUploadVideo": true
"shouldUploadVideo": false
}
],
"browserPath": "path/to/browser",
Expand Down
15 changes: 1 addition & 14 deletions packages/server/__snapshots__/non_root_read_only_fs_spec.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ If you don't require screenshots or videos to be stored you can safely ignore th
────────────────────────────────────────────────────────────────────────────────────────────────────

Running: spec.js (1 of 1)
Warning: We failed to record the video.

This error will not alter the exit code.

Error: EACCES: permission denied, mkdir '/foo/bar/.projects/read-only-project-root/cypress/videos'


1) fails
Expand All @@ -53,19 +48,11 @@ Error: EACCES: permission denied, mkdir '/foo/bar/.projects/read-only-project-ro
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: true
│ Video: false
│ Duration: X seconds │
│ Spec Ran: spec.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘

Warning: We failed processing this video.

This error will not alter the exit code.

Error: ffmpeg exited with code 1: /foo/bar/.projects/read-only-project-root/cypress/videos/spec.js.mp4: No such file or directory

[stack trace lines]


====================================================================================================

Expand Down
7 changes: 7 additions & 0 deletions packages/server/lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ const getMsgByType = function (type, arg1 = {}, arg2, arg3) {
This error will not alter the exit code.

${arg1}`
case 'VIDEO_DOESNT_EXIST':
return stripIndent`\
Warning: We could not find the video at the following path, so we were unable to process it.

Video path: ${arg1}

This error will not alter the exit code.`
case 'CHROME_WEB_SECURITY_NOT_SUPPORTED':
return stripIndent`\
Your project has set the configuration option: \`chromeWebSecurity: false\`
Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/experiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface StringValues {
const _summaries: StringValues = {
experimentalComponentTesting: 'Framework-specific component testing, uses `componentFolder` to load component specs.',
experimentalFetchPolyfill: 'Polyfills `window.fetch` to enable Network spying and stubbing.',
experimentalRunEvents: 'Allows listening to the `before:spec` and `after:spec` events in the plugins file.',
experimentalRunEvents: 'Allows listening to the `before:run`, `before:spec`, and `after:spec` events in the plugins file.',
experimentalSourceRewriting: 'Enables AST-based JS/HTML rewriting. This may fix issues caused by the existing regex-based JS/HTML replacement algorithm.',
}

Expand Down
Loading