Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: check for console.{error, log, warn} during initial loading #426

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading