-
-
Notifications
You must be signed in to change notification settings - Fork 843
Expand file tree
/
Copy pathbrowser.spec.js
More file actions
69 lines (61 loc) · 2.04 KB
/
browser.spec.js
File metadata and controls
69 lines (61 loc) · 2.04 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* Playwright spec for the QUnit browser tests.
*
* One test per QUnit suite (purify.js + purify.min.js). The browser is
* supplied by Playwright projects configured in playwright.config.js
* (chromium / firefox / webkit). Which projects run depends on the
* script invoked:
*
* npm test -> chromium only (via --project=chromium)
* npm run test:browser -> all three engines
*/
'use strict';
const { test } = require('@playwright/test');
const SUITES = [
{ label: 'purify.js', urlPath: '/test/browser/index.html' },
{ label: 'purify.min.js', urlPath: '/test/browser/index.min.html' },
];
async function runQUnitInPage(page, urlPath) {
await page.goto(urlPath);
await page.waitForFunction(() => window.__qunitDone__ === true, null, {
timeout: 120_000,
});
return page.evaluate(() => ({
passed: window.__qunitResult__.passed,
failed: window.__qunitResult__.failed,
total: window.__qunitResult__.total,
duration: window.__qunitResult__.runtime,
failures: window.__qunitFailures__ || [],
}));
}
function formatFailures(failures) {
if (!failures || failures.length === 0) return '';
const shown = failures.slice(0, 25);
const more =
failures.length > shown.length
? `\n ... and ${failures.length - shown.length} more`
: '';
return (
shown
.map((f) => {
const mod = f.module ? `${f.module} > ` : '';
return ` - ${mod}${f.name}\n expected: ${JSON.stringify(
f.expected
)}\n actual: ${JSON.stringify(f.actual)}`;
})
.join('\n') + more
);
}
for (const suite of SUITES) {
test(`${suite.label} — QUnit suite passes`, async ({ page }) => {
const result = await runQUnitInPage(page, suite.urlPath);
if (result.failed > 0) {
throw new Error(
`${result.failed}/${result.total} QUnit tests failed:\n${formatFailures(result.failures)}`
);
}
// eslint-disable-next-line no-console
console.log(
` ${suite.label}: ${result.passed}/${result.total} passed in ${result.duration} ms`
);
});
}