Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Examples/Testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ llvm-cov show -instr-profile=.build/plugins/PackageToJS/outputs/PackageTests/def
```console
npx serve .build/coverage/html
```
## Customize test harness

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.

```console
node run-tests-with-browser-options.mjs
```
23 changes: 23 additions & 0 deletions Examples/Testing/run-tests-with-browser-options.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Import the generated test harness function
import { testBrowser } from "./.build/plugins/PackageToJS/outputs/PackageTests/test.js"

// Execute the test with custom browser options
async function runTest(args) {
const exitCode = await testBrowser({
args: args,
playwright: {
browser: "chromium",
launchOptions: {
headless: false,
}
}
});
if (exitCode !== 0) {
process.exit(exitCode);
}
}
// Run XCTest test suites
await runTest([]);
// Run Swift Testing test suites
await runTest(["--testing-library", "swift-testing"]);
process.exit(0);
7 changes: 7 additions & 0 deletions Plugins/PackageToJS/Templates/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ export type SetupOptionsFn = (

export function testBrowser(
options: {
/** Path to the prelude script to be injected before tests run */
preludeScript?: string,
/** Command-line arguments to pass to the test runner */
args?: string[],
/** Options for Playwright browser */
playwright?: {
browser?: string,
launchOptions?: import("playwright").LaunchOptions
}
}
): Promise<number>

Expand Down
2 changes: 1 addition & 1 deletion Plugins/PackageToJS/Templates/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Please run the following command to install it:
process.exit(1);
}
})();
const browser = await playwright.chromium.launch();
const browser = await playwright[options.playwright?.browser ?? "chromium"].launch(options.playwright?.launchOptions ?? {});
const context = await browser.newContext();
const page = await context.newPage();

Expand Down