mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(page): consoleMessage.location() should work with workers (#3752)
This patch: - refactors consoleMessage.location() implementation to make it work for workers - re-writes tests to avoid 5 second delay
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Log Entry Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
fetch('http://wat')
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Log Entry Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
console.warn('wat')
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
11
test/assets/consolelog.html
Normal file
11
test/assets/consolelog.html
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>console.log test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
console.log('yellow')
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -322,16 +322,12 @@ module.exports.addTests = function({testRunner, expect, headless}) {
|
||||
expect(message.text()).toContain('No \'Access-Control-Allow-Origin\'');
|
||||
expect(message.type()).toEqual('error');
|
||||
});
|
||||
it('should show correct additional info when console event emitted for logEntry', async({page, server}) => {
|
||||
let message = null;
|
||||
page.on('console', msg => {
|
||||
message = msg;
|
||||
});
|
||||
await Promise.all([
|
||||
page.goto(server.PREFIX + '/console-message-1.html'),
|
||||
it('should have location when fetch fails', async({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
const [message] = await Promise.all([
|
||||
waitEvent(page, 'console'),
|
||||
page.setContent(`<script>fetch('http://wat');</script>`),
|
||||
]);
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
expect(message.text()).toContain(`ERR_NAME_NOT_RESOLVED`);
|
||||
expect(message.type()).toEqual('error');
|
||||
expect(message.location()).toEqual({
|
||||
@@ -339,22 +335,18 @@ module.exports.addTests = function({testRunner, expect, headless}) {
|
||||
lineNumber: undefined
|
||||
});
|
||||
});
|
||||
it('should show correct additional info when console event emitted for consoleAPI', async({page, server}) => {
|
||||
let message = null;
|
||||
page.on('console', msg => {
|
||||
message = msg;
|
||||
});
|
||||
await Promise.all([
|
||||
page.goto(server.PREFIX + '/console-message-2.html'),
|
||||
it('should have location for console API calls', async({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
const [message] = await Promise.all([
|
||||
waitEvent(page, 'console'),
|
||||
page.goto(server.PREFIX + '/consolelog.html'),
|
||||
]);
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
expect(message.text()).toContain(`wat`);
|
||||
expect(message.type()).toEqual('warning');
|
||||
expect(message.text()).toBe('yellow');
|
||||
expect(message.type()).toBe('log');
|
||||
expect(message.location()).toEqual({
|
||||
url: `http://localhost:${server.PORT}/console-message-2.html`,
|
||||
url: server.PREFIX + '/consolelog.html',
|
||||
lineNumber: 7,
|
||||
columnNumber: 16
|
||||
columnNumber: 14,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
const utils = require('./utils');
|
||||
const {waitEvent} = utils;
|
||||
|
||||
module.exports.addTests = function({testRunner, expect}) {
|
||||
const {describe, xdescribe, fdescribe} = testRunner;
|
||||
@@ -29,10 +31,16 @@ module.exports.addTests = function({testRunner, expect}) {
|
||||
expect(error.message).toContain('Most likely the worker has been closed.');
|
||||
});
|
||||
it('should report console logs', async function({page}) {
|
||||
const logPromise = new Promise(x => page.on('console', x));
|
||||
await page.evaluate(() => new Worker(`data:text/javascript,console.log(1)`));
|
||||
const log = await logPromise;
|
||||
expect(log.text()).toBe('1');
|
||||
const [message] = await Promise.all([
|
||||
waitEvent(page, 'console'),
|
||||
page.evaluate(() => new Worker(`data:text/javascript,console.log(1)`)),
|
||||
]);
|
||||
expect(message.text()).toBe('1');
|
||||
expect(message.location()).toEqual({
|
||||
url: 'data:text/javascript,console.log(1)',
|
||||
lineNumber: 0,
|
||||
columnNumber: 8,
|
||||
});
|
||||
});
|
||||
it('should have JSHandles for console logs', async function({page}) {
|
||||
const logPromise = new Promise(x => page.on('console', x));
|
||||
|
||||
Reference in New Issue
Block a user