test: convert functions to async & eliminate duplicates (#37316)
test: convert functions to async Co-authored-by: Milan Burda <miburda@microsoft.com>
This commit is contained in:
parent
969665eaa2
commit
f97d68c4bf
24 changed files with 225 additions and 343 deletions
|
@ -1,10 +1,10 @@
|
|||
import { expect } from 'chai';
|
||||
import * as http from 'http';
|
||||
import * as path from 'path';
|
||||
import { AddressInfo } from 'net';
|
||||
import { BrowserWindow } from 'electron/main';
|
||||
import { closeAllWindows } from './lib/window-helpers';
|
||||
import { emittedOnce, emittedUntil } from './lib/events-helpers';
|
||||
import { listen } from './lib/spec-helpers';
|
||||
|
||||
describe('debugger module', () => {
|
||||
const fixtures = path.resolve(__dirname, 'fixtures');
|
||||
|
@ -138,9 +138,9 @@ describe('debugger module', () => {
|
|||
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
||||
res.end('\u0024');
|
||||
});
|
||||
await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));
|
||||
|
||||
w.loadURL(`http://127.0.0.1:${(server.address() as AddressInfo).port}`);
|
||||
const { url } = await listen(server);
|
||||
w.loadURL(url);
|
||||
// If we do this synchronously, it's fast enough to attach and enable
|
||||
// network capture before the load. If we do it before the loadURL, for
|
||||
// some reason network capture doesn't get enabled soon enough and we get
|
||||
|
@ -155,19 +155,17 @@ describe('debugger module', () => {
|
|||
expect(body).to.equal('\u0024');
|
||||
});
|
||||
|
||||
it('does not crash for invalid unicode characters in message', (done) => {
|
||||
try {
|
||||
w.webContents.debugger.attach();
|
||||
} catch (err) {
|
||||
done(`unexpected error : ${err}`);
|
||||
}
|
||||
it('does not crash for invalid unicode characters in message', async () => {
|
||||
w.webContents.debugger.attach();
|
||||
|
||||
w.webContents.debugger.on('message', (event, method) => {
|
||||
// loadingFinished indicates that page has been loaded and it did not
|
||||
// crash because of invalid UTF-8 data
|
||||
if (method === 'Network.loadingFinished') {
|
||||
done();
|
||||
}
|
||||
const loadingFinished = new Promise<void>(resolve => {
|
||||
w.webContents.debugger.on('message', (event, method) => {
|
||||
// loadingFinished indicates that page has been loaded and it did not
|
||||
// crash because of invalid UTF-8 data
|
||||
if (method === 'Network.loadingFinished') {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
server = http.createServer((req, res) => {
|
||||
|
@ -175,10 +173,11 @@ describe('debugger module', () => {
|
|||
res.end('\uFFFF');
|
||||
});
|
||||
|
||||
server.listen(0, '127.0.0.1', () => {
|
||||
w.webContents.debugger.sendCommand('Network.enable');
|
||||
w.loadURL(`http://127.0.0.1:${(server.address() as AddressInfo).port}`);
|
||||
});
|
||||
const { url } = await listen(server);
|
||||
w.webContents.debugger.sendCommand('Network.enable');
|
||||
w.loadURL(url);
|
||||
|
||||
await loadingFinished;
|
||||
});
|
||||
|
||||
it('uses empty sessionId by default', async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue