-
Notifications
You must be signed in to change notification settings - Fork 7
/
run-tests
executable file
·33 lines (28 loc) · 917 Bytes
/
run-tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env node
const path = require('path');
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const fileName = process.argv[2] || 'index.html';
// Open NMEA Generator inside a headless browser.
try {
await page.goto(`file:${path.join(__dirname, fileName)}`);
await page.waitForTimeout(1000);
} catch (error) {
console.error(`Could not open file: '${fileName}'.`);
process.exit(1);
}
// Use console messages to detect test failure/success.
page.on('console', (message) => {
const testResult = message.text();
if (testResult.startsWith('[FAIL]')) {
console.error(testResult);
process.exit(1);
}
console.log(testResult);
});
// Tests are executed by invoking runTests() inside the browser.
await page.evaluate('runTests()');
await browser.close();
})();