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

fix(recorder): allow node to close gracefully #2817

Merged
merged 1 commit into from
Jul 2, 2020
Merged
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion src/debug/recorderController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class RecorderController {
private _performingAction = false;
private _pageAliases = new Map<Page, string>();
private _lastPopupOrdinal = 0;
private _timers = new Set<NodeJS.Timeout>();

constructor(context: BrowserContextBase, output: Writable) {
this._output = new TerminalOutput(output || process.stdout);
Expand All @@ -49,6 +50,12 @@ export class RecorderController {
page.on(Events.Page.FrameNavigated, (frame: frames.Frame) => this._onFrameNavigated(frame));
page.on(Events.Page.Popup, (popup: Page) => this._onPopup(page, popup));
});

context.once(Events.BrowserContext.Close, () => {
for (const timer of this._timers)
clearTimeout(timer);
this._timers.clear();
});
}

private async _performAction(frame: frames.Frame, action: actions.Action) {
Expand All @@ -70,7 +77,11 @@ export class RecorderController {
if (action.name === 'select')
await frame.selectOption(action.selector, action.options);
this._performingAction = false;
setTimeout(() => action.committed = true, 5000);
const timer = setTimeout(() => {
action.committed = true;
this._timers.delete(timer);
}, 5000);
this._timers.add(timer);
}

private async _recordAction(frame: frames.Frame, action: actions.Action) {
Expand Down