Skip to content

Commit 3696384

Browse files
authored
Merge pull request #284 from cuthbertLab/types-for-tests
Add better types for tests
2 parents a243f23 + ade37f7 commit 3696384

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

tests/run_qunit_playwright.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
import { chromium } from '@playwright/test';
1+
import { chromium, type Browser, type Page } from '@playwright/test';
22

33
/**
44
* Loads the Vite-served QUnit page in headless Chromium and exits nonzero on failures.
55
*/
66
async function main(): Promise<void> {
7-
const browser = await chromium.launch();
8-
const page = await browser.newPage();
7+
const browser: Browser = await chromium.launch();
8+
const page: Page = await browser.newPage();
99

1010
// Assumes vite dev server is running on 5173
11-
await page.goto('http://localhost:5173/tests/', {waitUntil: 'domcontentloaded'});
11+
await page.goto(
12+
'http://localhost:5173/tests/',
13+
{waitUntil: 'domcontentloaded'},
14+
);
1215

13-
// Wait for QUnit to finish
14-
await page.waitForFunction(() => (window as any).__qunit_done__ === true, null, {timeout: 120_000});
16+
// Wait up to 2 minutes for QUnit to finish. See types/qunit-globals.d.ts for the added python dunders
17+
await page.waitForFunction(
18+
() => globalThis.__qunit_done__, // wait until this is Truthy
19+
null,
20+
{timeout: 120_000}, // in ms
21+
);
1522

1623
const { results, failures } = await page.evaluate(() => ({
17-
results: (window as any).__qunit_results__,
18-
failures: (window as any).__qunit_failures__ ?? [],
24+
results: globalThis.__qunit_results__,
25+
failures: globalThis.__qunit_failures__ ?? [],
1926
}));
2027
await browser.close();
2128

tests/runner.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as music21 from '../src/main';
77
// Import the test registry
88
import m21_tests from './loadAll';
99

10-
1110
type QUnit_fail = {
1211
module: string;
1312
name: string;
@@ -100,7 +99,7 @@ QUnit.testDone(details => {
10099
QUnit.start();
101100

102101
QUnit.done(details => {
103-
(globalThis as any).__qunit_done__ = true;
104-
(globalThis as any).__qunit_results__ = details;
105-
(globalThis as any).__qunit_failures__ = qunit_failures;
102+
globalThis.__qunit_done__ = true;
103+
globalThis.__qunit_results__ = details;
104+
globalThis.__qunit_failures__ = qunit_failures;
106105
});

tests/types/qunit-globals.d.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export {};
2+
3+
declare global {
4+
interface GlobalThis {
5+
__qunit_done__?: boolean;
6+
__qunit_results__?: QUnit.DoneDetails;
7+
__qunit_failures__?: QUnit.TestDoneDetails[];
8+
}
9+
}

0 commit comments

Comments
 (0)