test: run crash tests in separate worker (#21759)

Running crash tests in its own worker should ensure that the browser
logs from different tests are not interleaved:

<img width="1088" alt="image"
src="https://user-images.githubusercontent.com/9798949/225965857-9152a88e-a775-4935-955a-dd7e6b88409a.png">
This commit is contained in:
Yury Semikhatsky 2023-03-17 10:36:01 -07:00 committed by GitHub
parent 49ce561244
commit 98befd8a16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,28 +15,34 @@
* limitations under the License. * limitations under the License.
*/ */
import { test as it, expect } from './pageTest'; import { contextTest as testBase, expect } from '../config/browserTest';
function crash({ page, toImpl, browserName, platform, mode }: any) { const test = testBase.extend<{ crash: () => void }>({
crash: async ({ page, toImpl, browserName }, run) => {
run(() => {
if (browserName === 'chromium') if (browserName === 'chromium')
page.goto('chrome://crash').catch(e => {}); page.goto('chrome://crash').catch(e => {});
else if (browserName === 'webkit') else if (browserName === 'webkit')
toImpl(page)._delegate._session.send('Page.crash', {}).catch(e => {}); toImpl(page)._delegate._session.send('Page.crash', {}).catch(e => {});
else if (browserName === 'firefox') else if (browserName === 'firefox')
toImpl(page)._delegate._session.send('Page.crash', {}).catch(e => {}); toImpl(page)._delegate._session.send('Page.crash', {}).catch(e => {});
});
} }
});
it.describe('', () => { // Force a separate worker to avoid messing up with other tests.
it('should emit crash event when page crashes', async ({ page, toImpl, browserName, platform, mode }) => { test.use({ launchOptions: {} });
test('should emit crash event when page crashes', async ({ page, crash }) => {
await page.setContent(`<div>This page should crash</div>`); await page.setContent(`<div>This page should crash</div>`);
crash({ page, toImpl, browserName, platform, mode }); crash();
const crashedPage = await new Promise(f => page.on('crash', f)); const crashedPage = await new Promise(f => page.on('crash', f));
expect(crashedPage).toBe(page); expect(crashedPage).toBe(page);
}); });
it('should throw on any action after page crashes', async ({ page, toImpl, browserName, platform, mode }) => { test('should throw on any action after page crashes', async ({ page, crash, browserName }) => {
await page.setContent(`<div>This page should crash</div>`); await page.setContent(`<div>This page should crash</div>`);
crash({ page, toImpl, browserName, platform, mode }); crash();
await page.waitForEvent('crash'); await page.waitForEvent('crash');
const err = await page.evaluate(() => {}).then(() => null, e => e); const err = await page.evaluate(() => {}).then(() => null, e => e);
expect(err).toBeTruthy(); expect(err).toBeTruthy();
@ -47,32 +53,31 @@ it.describe('', () => {
expect(err.message).toContain('Target crashed'); expect(err.message).toContain('Target crashed');
}); });
it('should cancel waitForEvent when page crashes', async ({ page, toImpl, browserName, platform, mode }) => { test('should cancel waitForEvent when page crashes', async ({ page, crash }) => {
await page.setContent(`<div>This page should crash</div>`); await page.setContent(`<div>This page should crash</div>`);
const promise = page.waitForEvent('response').catch(e => e); const promise = page.waitForEvent('response').catch(e => e);
crash({ page, toImpl, browserName, platform, mode }); crash();
const error = await promise; const error = await promise;
expect(error.message).toContain('Page crashed'); expect(error.message).toContain('Page crashed');
}); });
it('should cancel navigation when page crashes', async ({ server, page, toImpl, browserName, platform, mode }) => { test('should cancel navigation when page crashes', async ({ server, page, crash }) => {
await page.setContent(`<div>This page should crash</div>`); await page.setContent(`<div>This page should crash</div>`);
server.setRoute('/one-style.css', () => {}); server.setRoute('/one-style.css', () => {});
const promise = page.goto(server.PREFIX + '/one-style.html').catch(e => e); const promise = page.goto(server.PREFIX + '/one-style.html').catch(e => e);
await page.waitForNavigation({ waitUntil: 'domcontentloaded' }); await page.waitForNavigation({ waitUntil: 'domcontentloaded' });
crash({ page, toImpl, browserName, platform, mode }); crash();
const error = await promise; const error = await promise;
expect(error.message).toContain('Navigation failed because page crashed'); expect(error.message).toContain('Navigation failed because page crashed');
}); });
it('should be able to close context when page crashes', async ({ isAndroid, isElectron, isWebView2, page, toImpl, browserName, platform, mode }) => { test('should be able to close context when page crashes', async ({ isAndroid, isElectron, isWebView2, page, crash }) => {
it.skip(isAndroid); test.skip(isAndroid);
it.skip(isElectron); test.skip(isElectron);
it.skip(isWebView2, 'Page.close() is not supported in WebView2'); test.skip(isWebView2, 'Page.close() is not supported in WebView2');
await page.setContent(`<div>This page should crash</div>`); await page.setContent(`<div>This page should crash</div>`);
crash({ page, toImpl, browserName, platform, mode }); crash();
await page.waitForEvent('crash'); await page.waitForEvent('crash');
await page.context().close(); await page.context().close();
}); });
});