Skip to content

Commit 237097a

Browse files
authored
Merge pull request #459 from swiftwasm/yt/expose-playwright-launch-options
PackageToJS: Expose Playwright Launch Options in test harness
2 parents a31b50d + d4044cf commit 237097a

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

Examples/Testing/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ llvm-cov show -instr-profile=.build/plugins/PackageToJS/outputs/PackageTests/def
3131
```console
3232
npx serve .build/coverage/html
3333
```
34+
## Customize test harness
35+
36+
See [./run-tests-with-browser-options.mjs](./run-tests-with-browser-options.mjs) for an example of customizing the test harness to run tests with specific browser options.
37+
38+
```console
39+
node run-tests-with-browser-options.mjs
40+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Import the generated test harness function
2+
import { testBrowser } from "./.build/plugins/PackageToJS/outputs/PackageTests/test.js"
3+
4+
// Execute the test with custom browser options
5+
async function runTest(args) {
6+
const exitCode = await testBrowser({
7+
args: args,
8+
playwright: {
9+
browser: "chromium",
10+
launchOptions: {
11+
headless: false,
12+
}
13+
}
14+
});
15+
if (exitCode !== 0) {
16+
process.exit(exitCode);
17+
}
18+
}
19+
// Run XCTest test suites
20+
await runTest([]);
21+
// Run Swift Testing test suites
22+
await runTest(["--testing-library", "swift-testing"]);
23+
process.exit(0);

Plugins/PackageToJS/Templates/test.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ export type SetupOptionsFn = (
99

1010
export function testBrowser(
1111
options: {
12+
/** Path to the prelude script to be injected before tests run */
1213
preludeScript?: string,
14+
/** Command-line arguments to pass to the test runner */
1315
args?: string[],
16+
/** Options for Playwright browser */
17+
playwright?: {
18+
browser?: string,
19+
launchOptions?: import("playwright").LaunchOptions
20+
}
1421
}
1522
): Promise<number>
1623

Plugins/PackageToJS/Templates/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Please run the following command to install it:
9696
process.exit(1);
9797
}
9898
})();
99-
const browser = await playwright.chromium.launch();
99+
const browser = await playwright[options.playwright?.browser ?? "chromium"].launch(options.playwright?.launchOptions ?? {});
100100
const context = await browser.newContext();
101101
const page = await context.newPage();
102102

0 commit comments

Comments
 (0)