mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
added warning check on browser tests
This commit is contained in:
parent
1e73cabcf8
commit
12377cc72c
1 changed files with 26 additions and 5 deletions
|
@ -30,11 +30,16 @@ if (!fs.existsSync(browserPath)) {
|
||||||
// Set up the environment and run examples
|
// Set up the environment and run examples
|
||||||
beforeAll(async () => results = await runExamplesBrowser(totalUpdates));
|
beforeAll(async () => results = await runExamplesBrowser(totalUpdates));
|
||||||
|
|
||||||
it('all examples run without throwing error', () => {
|
it('all examples run without throwing error or warning', () => {
|
||||||
if (results.error) {
|
if (results.error) {
|
||||||
console.error(results.error);
|
console.error(results.error);
|
||||||
expect(!results.error).toBe(true);
|
expect(Boolean(results.error)).toBe(false);
|
||||||
} else {
|
}
|
||||||
|
if (results.warns) {
|
||||||
|
console.error(results.warns);
|
||||||
|
expect(results.warns.size).toBe(0);
|
||||||
|
}
|
||||||
|
if (!results.error && !results.warns) {
|
||||||
for (const example of examples) {
|
for (const example of examples) {
|
||||||
expect(results[example].id).toBe(example);
|
expect(results[example].id).toBe(example);
|
||||||
expect(results[example].timestamp).toBeGreaterThan(0);
|
expect(results[example].timestamp).toBeGreaterThan(0);
|
||||||
|
@ -49,15 +54,29 @@ const runExamplesBrowser = async updates => {
|
||||||
const browser = await puppeteer.launch({ executablePath: browserPath });
|
const browser = await puppeteer.launch({ executablePath: browserPath });
|
||||||
const page = await browser.newPage();
|
const page = await browser.newPage();
|
||||||
const results = {};
|
const results = {};
|
||||||
|
let example;
|
||||||
|
|
||||||
// Load local demo page and catch errors
|
// Load local demo page and catch errors
|
||||||
let pageError;
|
let pageError;
|
||||||
|
let pageWarns;
|
||||||
|
|
||||||
const onPageError = error => pageError = error;
|
const onPageError = error => pageError = error;
|
||||||
|
const onPageConsole = async message => {
|
||||||
|
const type = message.type();
|
||||||
|
if (example && type === 'error' || type === 'warning') {
|
||||||
|
const log = `[${example}] ${message.type()} ${message.text()}`;
|
||||||
|
pageWarns = pageWarns || new Set();
|
||||||
|
pageWarns.add(log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
page.addListener('pageerror', onPageError);
|
page.addListener('pageerror', onPageError);
|
||||||
|
page.addListener('console', onPageConsole);
|
||||||
|
|
||||||
await page.goto(demoPagePath).catch(onPageError);
|
await page.goto(demoPagePath).catch(onPageError);
|
||||||
|
|
||||||
// For every example
|
// For every example
|
||||||
for (const example of examples) {
|
for (example of examples) {
|
||||||
// Bail on error
|
// Bail on error
|
||||||
if (pageError) {
|
if (pageError) {
|
||||||
break;
|
break;
|
||||||
|
@ -93,5 +112,7 @@ const runExamplesBrowser = async updates => {
|
||||||
// Tear down
|
// Tear down
|
||||||
await browser.close();
|
await browser.close();
|
||||||
|
|
||||||
return pageError ? { error: pageError } : results;
|
results.error = pageError;
|
||||||
|
results.warns = pageWarns;
|
||||||
|
return results;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue