Skip to content

Commit

Permalink
tests: check for console.{error, log, warn} during initial loading
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Oct 5, 2024
1 parent f16c8cc commit d50f3ca
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion example/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": "true",
"description": "An example using GraphQL-Voyager",
"scripts": {
"start": "webpack-dev-server --config webpack.config.js --mode=development",
"start": "webpack-dev-server --config webpack.config.js --mode=production",
"test": "tsc"
},
"dependencies": {
Expand Down
9 changes: 5 additions & 4 deletions example/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ module.exports = {
devServer: {
port: 9090,
allowedHosts: 'all',
static: {
directory: __dirname,
},
liveReload: true,
static: { directory: __dirname },
// needed to prevent info messages during integration tests
client: { logging: 'warn' },
},
// disable hints since Voyager is too big :(
performance: { hints: false, },
resolve: {
extensions: ['.mjs', '.ts', '.tsx', '.js'],
},
Expand Down
69 changes: 35 additions & 34 deletions tests/PageObjectModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,41 @@ export async function gotoVoyagerPage(
page: Page,
searchParams?: VoyagerURLParams,
) {
// Add error/console checkers before we open Voyager page to track errors during loading
page.on('pageerror', (error) => {
throw error;
});
page.on('requestfailed', (request) => {
throw new Error(request.url() + ' ' + request.failure()?.errorText);
});
page.on('response', (response) => {
if (response.status() != 200) {
throw new Error(
`${response.url()}: ${response.status()} ${response.statusText()}`,
);
}
});
page.on('console', (message) => {
const type = message.type();
const text = message.text();
const { url, lineNumber } = message.location();
const location = `${url}:${lineNumber}`;

switch (type) {
case 'timeEnd':
if (text.startsWith('graphql-voyager: Rendering SVG:')) {
return;
}
break;
case 'log':
if (text.startsWith('graphql-voyager: SVG cached')) {
return;
}
break;
}
throw new Error(`[${type.toUpperCase()}] at '${location}': ${text}`);
});

const search = new URLSearchParams();
if (searchParams?.url != null) {
search.append('url', searchParams.url);
Expand Down Expand Up @@ -56,40 +91,6 @@ class PlaywrightVoyagerPage {
});

this.changeSchemaDialog = new PlaywrightChangeSchemaDialog(page);

page.on('pageerror', (error) => {
throw error;
});
page.on('requestfailed', (request) => {
throw new Error(request.url() + ' ' + request.failure()?.errorText);
});
page.on('response', (response) => {
if (response.status() != 200) {
throw new Error(
`${response.url()}: ${response.status()} ${response.statusText()}`,
);
}
});
page.on('console', (message) => {
const type = message.type();
const text = message.text();
const { url, lineNumber } = message.location();
const location = `${url}:${lineNumber}`;

switch (type) {
case 'timeEnd':
if (text.startsWith('graphql-voyager: Rendering SVG:')) {
return;
}
break;
case 'log':
if (text.startsWith('graphql-voyager: SVG cached')) {
return;
}
break;
}
throw new Error(`[${type.toUpperCase()}] at '${location}': ${text}`);
});
}

async waitForGraphToBeLoaded(): Promise<void> {
Expand Down
5 changes: 2 additions & 3 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ const BANNER = `GraphQL Voyager - Represent any GraphQL API as an interactive gr

const baseConfig: webpack.Configuration = {
devtool: 'source-map',
performance: {
hints: false,
},
// disable hints since Voyager is too big :(
performance: { hints: false },
resolve: {
extensions: ['.ts', '.tsx', '.mjs', '.js', '.json', '.css', '.svg'],
alias: { '../../worker': '../../worker-dist' },
Expand Down

0 comments on commit d50f3ca

Please sign in to comment.