Skip to content

Commit 817fc58

Browse files
committed
Check expectToBeTrue
1 parent ca5d201 commit 817fc58

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import Testing
2+
import JavaScriptKit
23

34
@Test func expectToBeTrue() async throws {
4-
#expect(Bool(true))
5+
let expectToBeTrue = #require(JSObject.global.expectToBeTrue.function)
6+
let result = expectToBeTrue.callAsFunction().boolean
7+
#expect(result == true)
8+
}
9+
10+
enum TestError: Error {
11+
case nilResult(String)
512
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import XCTest
2-
// import JavaScriptKit
2+
import JavaScriptKit
33

44
final class CheckTests: XCTestCase {
55
func testExpectToBeTrue() async throws {
6-
// let expectToBeTrue = JSObject.global.expectToBeTrue.function!
7-
// let result = await expectToBeTrue().boolean
8-
// guard let result else { return XCTFail("expectToBeTrue() returned nil") }
9-
// XCTAssertTrue(result)
10-
XCTAssertTrue(true)
6+
guard let expectToBeTrue = JSObject.global.expectToBeTrue.function
7+
else { return XCTFail("Function expectToBeTrue not found") }
8+
let result = expectToBeTrue().boolean
9+
guard let result
10+
else { return XCTFail("expectToBeTrue() returned nil") }
11+
XCTAssertTrue(result)
1112
}
1213
}

Plugins/PackageToJS/Templates/bin/test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,20 @@ Hint: This typically means that a continuation leak occurred.
9595
}
9696
},
9797
browser: async ({ preludeScript }) => {
98-
process.exit(await testBrowser({ preludeScript, inspect: args.values.inspect, args: testFrameworkArgs }));
98+
const onPageLoad = (page) => {
99+
page.exposeFunction("expectToBeTrue", () => {
100+
return true;
101+
});
102+
}
103+
const exitCode = await testBrowser({
104+
preludeScript,
105+
inspect: args.values.inspect,
106+
args: testFrameworkArgs,
107+
playwright: {
108+
onPageLoad
109+
}
110+
});
111+
process.exit(exitCode);
99112
}
100113
}
101114

Plugins/PackageToJS/Templates/test.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export function testBrowser(
1717
playwright?: {
1818
browser?: string,
1919
launchOptions?: import("playwright").LaunchOptions
20+
onPageLoad?: (page: import("playwright").Page) => Promise<void>
2021
}
2122
}
2223
): Promise<number>

Plugins/PackageToJS/Templates/test.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,8 @@ Please run the following command to install it:
9999
const browser = await playwright[options.playwright?.browser ?? "chromium"].launch(options.playwright?.launchOptions ?? {});
100100
const context = await browser.newContext();
101101
const page = await context.newPage();
102-
103-
104-
// Forward console messages in the page to the Node.js console
105-
page.on("console", (message) => {
106-
console.log(message.text());
107-
});
102+
// Allow the user to customize the page before it's loaded, for defining custom export functions
103+
if (options.playwright?.onPageLoad) { await options.playwright.onPageLoad(page); }
108104

109105
const onExit = new Promise((resolve) => {
110106
page.exposeFunction("exitTest", resolve);

0 commit comments

Comments
 (0)