Skip to content

Commit

Permalink
fix for test-runner missing console errors in examples (#606)
Browse files Browse the repository at this point in the history
Signed-off-by: hanbollar <[email protected]>

NOTE: TESTS WILL NOT PASS AFTER THIS COMMIT since this newly is exposing some errors we were missing before --> another pr will follow this that will fix the failures (need to go into mrjs on some things)
  • Loading branch information
hanbollar authored May 2, 2024
1 parent becfcbd commit d0a3ffa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![The MRjs logo, an indigo and purple bowtie.](https://docs.mrjs.io/static/mrjs-logo.svg)

An extensible library of Web Components for the spatial web.

[![npm run build](https://github.com/Volumetrics-io/mrjs/actions/workflows/build.yml/badge.svg)](https://github.com/Volumetrics-io/mrjs/actions/workflows/build.yml) [![npm run test](https://github.com/Volumetrics-io/mrjs/actions/workflows/test.yml/badge.svg)](https://github.com/Volumetrics-io/mrjs/actions/workflows/test.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Volumetrics-io/mrjs/blob/main/LICENSE)
Expand Down
35 changes: 22 additions & 13 deletions __tests__/examplesTesting.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@ const fileNames = ['../index', 'anchors', 'audio', 'debug', 'embed', 'images', '
describe('Test the Examples', () => {
let browser;
let page;
let errors = [];

beforeAll(async () => {
browser = await puppeteer.launch({ headless: "new" });
browser = await puppeteer.launch({ headless: true });
page = await browser.newPage();

// Listen for console errors right after creating the page
page.on('console', msg => {
if (msg.type() === 'error') {
errors.push(msg.text());
console.error(`Console error: ${msg.text()}`);
}
});

// Catch unhandled promise rejections
page.on('pageerror', error => {
errors.push(error.toString());
console.error(`Unhandled error: ${error}`);
});
});

afterAll(async () => {
Expand All @@ -20,18 +35,13 @@ describe('Test the Examples', () => {

fileNames.forEach(fileName => {
test(`Page ${fileName} should load with no console errors`, async () => {
let errors = [];

page.on('console', msg => {
if (msg.type() === 'error') {
errors.push(msg.text());
}
});
// Reset errors array for each file
errors = [];

// Define your HTML content from the sample
let htmlContent = await fs.readFile(`./dist/examples/${fileName}.html`, 'utf8');
console.log(`Running test on: ./dist/examples/${fileName}.html`);
// Modify the src and style tag to be for this example.

// Adjust script and link paths
htmlContent = htmlContent.replace(
`<script src="/mr.js"></script>`,
`<script src="../dist/mr.js"></script>`);
Expand All @@ -40,10 +50,9 @@ describe('Test the Examples', () => {
`<link rel="stylesheet" type="text/css" href="./dist/examples/${fileName}-style.css" />`);

await page.setContent(htmlContent);
await page.waitForTimeout(1000); // wait for a second to allow all scripts to execute

if (errors.length > 0) {
console.log(`Console Errors in ${fileName}:`, errors);
}
// Assertions can be placed here if needed
expect(errors).toHaveLength(0);
});
});
Expand Down

0 comments on commit d0a3ffa

Please sign in to comment.