Skip to content

Commit 054be5b

Browse files
tests: check for console.{error, log, warn} during initial loading (#426)
1 parent cb89d33 commit 054be5b

File tree

4 files changed

+43
-42
lines changed

4 files changed

+43
-42
lines changed

example/webpack/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": "true",
33
"description": "An example using GraphQL-Voyager",
44
"scripts": {
5-
"start": "webpack-dev-server --config webpack.config.js --mode=development",
5+
"start": "webpack-dev-server --config webpack.config.js --mode=production",
66
"test": "tsc"
77
},
88
"dependencies": {

example/webpack/webpack.config.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ module.exports = {
44
devServer: {
55
port: 9090,
66
allowedHosts: 'all',
7-
static: {
8-
directory: __dirname,
9-
},
10-
liveReload: true,
7+
static: { directory: __dirname },
8+
// needed to prevent info messages during integration tests
9+
client: { logging: 'warn' },
1110
},
11+
// disable hints since Voyager is too big :(
12+
performance: { hints: false },
1213
resolve: {
1314
extensions: ['.mjs', '.ts', '.tsx', '.js'],
1415
},

tests/PageObjectModel.ts

+35-34
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,41 @@ export async function gotoVoyagerPage(
1111
page: Page,
1212
searchParams?: VoyagerURLParams,
1313
) {
14+
// Add error/console checkers before we open Voyager page to track errors during loading
15+
page.on('pageerror', (error) => {
16+
throw error;
17+
});
18+
page.on('requestfailed', (request) => {
19+
throw new Error(request.url() + ' ' + request.failure()?.errorText);
20+
});
21+
page.on('response', (response) => {
22+
if (response.status() != 200) {
23+
throw new Error(
24+
`${response.url()}: ${response.status()} ${response.statusText()}`,
25+
);
26+
}
27+
});
28+
page.on('console', (message) => {
29+
const type = message.type();
30+
const text = message.text();
31+
const { url, lineNumber } = message.location();
32+
const location = `${url}:${lineNumber}`;
33+
34+
switch (type) {
35+
case 'timeEnd':
36+
if (text.startsWith('graphql-voyager: Rendering SVG:')) {
37+
return;
38+
}
39+
break;
40+
case 'log':
41+
if (text.startsWith('graphql-voyager: SVG cached')) {
42+
return;
43+
}
44+
break;
45+
}
46+
throw new Error(`[${type.toUpperCase()}] at '${location}': ${text}`);
47+
});
48+
1449
const search = new URLSearchParams();
1550
if (searchParams?.url != null) {
1651
search.append('url', searchParams.url);
@@ -56,40 +91,6 @@ class PlaywrightVoyagerPage {
5691
});
5792

5893
this.changeSchemaDialog = new PlaywrightChangeSchemaDialog(page);
59-
60-
page.on('pageerror', (error) => {
61-
throw error;
62-
});
63-
page.on('requestfailed', (request) => {
64-
throw new Error(request.url() + ' ' + request.failure()?.errorText);
65-
});
66-
page.on('response', (response) => {
67-
if (response.status() != 200) {
68-
throw new Error(
69-
`${response.url()}: ${response.status()} ${response.statusText()}`,
70-
);
71-
}
72-
});
73-
page.on('console', (message) => {
74-
const type = message.type();
75-
const text = message.text();
76-
const { url, lineNumber } = message.location();
77-
const location = `${url}:${lineNumber}`;
78-
79-
switch (type) {
80-
case 'timeEnd':
81-
if (text.startsWith('graphql-voyager: Rendering SVG:')) {
82-
return;
83-
}
84-
break;
85-
case 'log':
86-
if (text.startsWith('graphql-voyager: SVG cached')) {
87-
return;
88-
}
89-
break;
90-
}
91-
throw new Error(`[${type.toUpperCase()}] at '${location}': ${text}`);
92-
});
9394
}
9495

9596
async waitForGraphToBeLoaded(): Promise<void> {

webpack.config.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ const BANNER = `GraphQL Voyager - Represent any GraphQL API as an interactive gr
1515

1616
const baseConfig: webpack.Configuration = {
1717
devtool: 'source-map',
18-
performance: {
19-
hints: false,
20-
},
18+
// disable hints since Voyager is too big :(
19+
performance: { hints: false },
2120
resolve: {
2221
extensions: ['.ts', '.tsx', '.mjs', '.js', '.json', '.css', '.svg'],
2322
alias: { '../../worker': '../../worker-dist' },

0 commit comments

Comments
 (0)