test: do not trigger unhandled promise rejections (#22922)

This commit is contained in:
Cheng Zhao 2020-04-01 22:45:39 +09:00 коммит произвёл GitHub
Родитель e6f2605ad0
Коммит 14051ff945
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 9 добавлений и 7 удалений

Просмотреть файл

@ -135,16 +135,16 @@ describe('webRequest module', () => {
await ajax(defaultURL + 'serverRedirect'); await ajax(defaultURL + 'serverRedirect');
}); });
it('works with file:// protocol', (done) => { it('works with file:// protocol', async () => {
ses.webRequest.onBeforeRequest((details, callback) => { ses.webRequest.onBeforeRequest((details, callback) => {
callback({ cancel: true }); callback({ cancel: true });
done();
}); });
ajax(url.format({ const fileURL = url.format({
pathname: path.join(fixturesPath, 'blank.html').replace(/\\/g, '/'), pathname: path.join(fixturesPath, 'blank.html').replace(/\\/g, '/'),
protocol: 'file', protocol: 'file',
slashes: true slashes: true
})); });
await expect(ajax(fileURL)).to.eventually.be.rejectedWith('404');
}); });
}); });
@ -207,22 +207,24 @@ describe('webRequest module', () => {
await ajax(defaultURL); await ajax(defaultURL);
}); });
it('works with file:// protocol', (done) => { it('works with file:// protocol', async () => {
const requestHeaders = { const requestHeaders = {
Test: 'header' Test: 'header'
}; };
let onSendHeadersCalled = false;
ses.webRequest.onBeforeSendHeaders((details, callback) => { ses.webRequest.onBeforeSendHeaders((details, callback) => {
callback({ requestHeaders: requestHeaders }); callback({ requestHeaders: requestHeaders });
}); });
ses.webRequest.onSendHeaders((details) => { ses.webRequest.onSendHeaders((details) => {
expect(details.requestHeaders).to.deep.equal(requestHeaders); expect(details.requestHeaders).to.deep.equal(requestHeaders);
done(); onSendHeadersCalled = true;
}); });
ajax(url.format({ await ajax(url.format({
pathname: path.join(fixturesPath, 'blank.html').replace(/\\/g, '/'), pathname: path.join(fixturesPath, 'blank.html').replace(/\\/g, '/'),
protocol: 'file', protocol: 'file',
slashes: true slashes: true
})); }));
expect(onSendHeadersCalled).to.be.true();
}); });
}); });