Skip to content

Commit

Permalink
fix(recorder): allow node to close gracefully (#2817)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelEinbinder authored Jul 2, 2020
1 parent cb0c037 commit f484b20
Showing 1 changed file with 12 additions and 1 deletion.
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

0 comments on commit f484b20

Please sign in to comment.