-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathconsole.test.ts
More file actions
144 lines (134 loc) · 4.99 KB
/
console.test.ts
File metadata and controls
144 lines (134 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {before, describe, it} from 'node:test';
import {loadIssueDescriptions} from '../../src/issue-descriptions.js';
import {
getConsoleMessage,
listConsoleMessages,
} from '../../src/tools/console.js';
import {withBrowser} from '../utils.js';
describe('console', () => {
describe('list_console_messages', () => {
before(async () => {
await loadIssueDescriptions();
});
it('list messages', async () => {
await withBrowser(async (response, context) => {
await listConsoleMessages.handler({params: {}}, response, context);
assert.ok(response.includeConsoleData);
});
});
it('lists error messages', async () => {
await withBrowser(async (response, context) => {
const page = await context.newPage();
await page.setContent(
'<script>console.error("This is an error")</script>',
);
await listConsoleMessages.handler({params: {}}, response, context);
const formattedResponse = await response.handle('test', context);
const textContent = formattedResponse[0] as {text: string};
assert.ok(
textContent.text.includes('msgid=1 [error] This is an error'),
);
});
});
it('lists issues', async () => {
await withBrowser(async (response, context) => {
const page = await context.newPage();
const issuePromise = new Promise<void>(resolve => {
page.once('issue', () => {
resolve();
});
});
await page.setContent('<input type="text" name="username" />');
await issuePromise;
await listConsoleMessages.handler({params: {}}, response, context);
const formattedResponse = await response.handle('test', context);
const textContent = formattedResponse[0] as {text: string};
assert.ok(
textContent.text.includes(
`msgid=1 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
),
);
});
});
it('lists issues after a page reload', async () => {
await withBrowser(async (response, context) => {
const page = await context.newPage();
const issuePromise = new Promise<void>(resolve => {
page.once('issue', () => {
resolve();
});
});
await page.setContent('<input type="text" name="username" />');
await issuePromise;
await listConsoleMessages.handler({params: {}}, response, context);
{
const formattedResponse = await response.handle('test', context);
const textContent = formattedResponse[0] as {text: string};
assert.ok(
textContent.text.includes(
`msgid=1 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
),
);
}
const anotherIssuePromise = new Promise<void>(resolve => {
page.once('issue', () => {
resolve();
});
});
await page.reload();
await page.setContent('<input type="text" name="username" />');
await anotherIssuePromise;
{
const formattedResponse = await response.handle('test', context);
const textContent = formattedResponse[0] as {text: string};
assert.ok(
textContent.text.includes(
`msgid=2 [issue] An element doesn't have an autocomplete attribute (count: 1)`,
),
);
}
});
});
it('work with primitive unhandled errors', async () => {
await withBrowser(async (response, context) => {
const page = await context.newPage();
await page.setContent('<script>throw undefined;</script>');
await listConsoleMessages.handler({params: {}}, response, context);
const formattedResponse = await response.handle('test', context);
const textContent = formattedResponse[0] as {text: string};
assert.ok(
textContent.text.includes('msgid=1 [error] undefined (0 args)'),
);
});
});
});
describe('get_console_message', () => {
it('gets a specific console message', async () => {
await withBrowser(async (response, context) => {
const page = await context.newPage();
await page.setContent(
'<script>console.error("This is an error")</script>',
);
// The list is needed to populate the console messages in the context.
await listConsoleMessages.handler({params: {}}, response, context);
await getConsoleMessage.handler(
{params: {msgid: 1}},
response,
context,
);
const formattedResponse = await response.handle('test', context);
const textContent = formattedResponse[0] as {text: string};
assert.ok(
textContent.text.includes('msgid=1 [error] This is an error'),
'Should contain console message body',
);
});
});
});
});