test: run script to help target discovery and reduce flakes (#44764)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Samuel Maddock <smaddock@slack-corp.com>
This commit is contained in:
trop[bot] 2024-11-20 16:25:21 -05:00 committed by GitHub
parent 8e03e1d4a9
commit 8255e4e8d2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -227,21 +227,26 @@ describe('debugger module', () => {
it('creates unique session id for each target', (done) => {
w.webContents.loadFile(path.join(__dirname, 'fixtures', 'sub-frames', 'debug-frames.html'));
w.webContents.debugger.attach();
let session: String;
let debuggerSessionId: string;
w.webContents.debugger.on('message', (event, ...args) => {
const [method, params, sessionId] = args;
if (method === 'Target.targetCreated') {
w.webContents.debugger.sendCommand('Target.attachToTarget', { targetId: params.targetInfo.targetId, flatten: true }).then(result => {
session = result.sessionId;
debuggerSessionId = result.sessionId;
w.webContents.debugger.sendCommand('Debugger.enable', {}, result.sessionId);
// Ensure debugger finds a script to pause to possibly reduce flaky
// tests.
w.webContents.mainFrame.executeJavaScript('void 0;');
});
}
if (method === 'Debugger.scriptParsed') {
expect(sessionId).to.equal(session);
if (sessionId === debuggerSessionId) {
w.webContents.debugger.detach();
done();
}
}
});
w.webContents.debugger.sendCommand('Target.setDiscoverTargets', { discover: true });
});