Repository navigation
fix(electron): end a video recording in its close time #2503
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2583fd7
fix(electron): keep no empty video when ffmpeg fails before it writes…
kdy1 7438fa0
fix(electron): drop a video snapshot of a window that loaded another …
kdy1 85ae0b7
fix(electron): end a recording in its close time when the encoder has…
kdy1 effdb37
fix(electron): end a recording whose window never answers the start o…
kdy1 18b07de
chore(electron): add a changeset for the video recording fixes
kdy1 7c920cc
fix(electron): bound the end of a screencast when the recording stops
kdy1 a55cb4f
fix(electron): start no screencast for a window switch the end of the…
kdy1 d20f0ba
chore(electron): name a busy main process in the video changeset
kdy1 518aaaf
docs(electron): reword the comment on the window switch wait
kdy1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@e2e-dev/electron': patch | ||
| --- | ||
|
|
||
| A video recording ends in its close time when ffmpeg stops reading frames, a window never answers the start of its screencast, or the app's main process is too busy to answer the end of it; each used to hold the end of the test for good. A recording whose ffmpeg fails before it writes any video fails with `ENGINE_FAILURE` and leaves no empty file, and a capture of a window that loaded a page outside the app's directory while it was taken is dropped. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import { tmpdir } from 'node:os'; | ||
| import path from 'node:path'; | ||
| import { afterEach, describe, expect, it } from 'vitest'; | ||
| import type { PageTarget } from '../../src/page.ts'; | ||
| import { Recorder } from '../../src/video.ts'; | ||
|
|
||
| /** A call the test answers when it chooses. */ | ||
| interface Held { | ||
| readonly answer: () => void; | ||
| } | ||
|
|
||
| /** | ||
| * The part of a page target a recording drives: its DevTools session, which | ||
| * answers every call at once unless the test holds that method, and whether | ||
| * a screencast runs on it. | ||
| */ | ||
| class FakePage { | ||
| recording = false; | ||
| readonly generation = 0; | ||
| readonly sent: string[] = []; | ||
| listeners = 0; | ||
| private readonly holds = new Map<string, Held[]>(); | ||
|
|
||
| readonly session = { | ||
| send: (method: string): Promise<unknown> => { | ||
| this.sent.push(method); | ||
| const answer = method === 'Page.getLayoutMetrics' ? { cssVisualViewport: { clientWidth: 100, clientHeight: 100 } } : method === 'Page.captureScreenshot' ? { data: 'AAAA' } : {}; | ||
| const held = this.holds.get(method)?.shift(); | ||
| if (held === undefined) return Promise.resolve(answer); | ||
| return new Promise((resolve) => { | ||
| (held as { answer: () => void }).answer = () => resolve(answer); | ||
| }); | ||
| }, | ||
| on: (): (() => void) => { | ||
| this.listeners += 1; | ||
| let on = true; | ||
| return () => { | ||
| if (on) this.listeners -= 1; | ||
| on = false; | ||
| }; | ||
| }, | ||
| }; | ||
|
|
||
| /** Holds the next call of `method` until the returned `answer` is called. */ | ||
| hold(method: string): Held { | ||
| const held: { answer: () => void } = { answer: () => undefined }; | ||
| this.holds.set(method, [...(this.holds.get(method) ?? []), held]); | ||
| return { answer: () => held.answer() }; | ||
| } | ||
|
|
||
| isClosed(): boolean { | ||
| return false; | ||
| } | ||
|
|
||
| asTarget(): PageTarget { | ||
| return this as unknown as PageTarget; | ||
| } | ||
| } | ||
|
|
||
| const directories: string[] = []; | ||
|
|
||
| afterEach(() => { | ||
| for (const directory of directories.splice(0)) rmSync(directory, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| const wait = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms)); | ||
|
|
||
| describe.skipIf(process.platform === 'win32')('Recorder', () => { | ||
| it('starts no screencast for a window switch that the end of the recording left waiting', async () => { | ||
| const directory = mkdtempSync(path.join(tmpdir(), 'e2e-electron-video-')); | ||
| directories.push(directory); | ||
| // An encoder that takes every frame and writes nothing. | ||
| const encoder = path.join(directory, 'ffmpeg.sh'); | ||
| writeFileSync(encoder, '#!/bin/sh\ncat > /dev/null\n', { mode: 0o755 }); | ||
| const one = new FakePage(); | ||
| const two = new FakePage(); | ||
| const startOne = one.hold('Page.startScreencast'); | ||
| const recorder = new Recorder(encoder, directory, 'video.webm', () => true); | ||
| recorder.follow(one.asTarget()); | ||
| recorder.follow(two.asTarget()); | ||
| const stopping = recorder.stop(); | ||
| // The switch to the first window ends a second into the two the recording's end waits; the switch to the second then waits on the first's stop past them. | ||
| const stopOne = one.hold('Page.stopScreencast'); | ||
| await wait(1000); | ||
| startOne.answer(); | ||
| await stopping; | ||
| stopOne.answer(); | ||
| await wait(100); | ||
| expect(two.sent).not.toContain('Page.startScreencast'); | ||
| expect(two.recording).toBe(false); | ||
| expect(two.listeners).toBe(0); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.