-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathsupport.ts
More file actions
63 lines (57 loc) · 1.8 KB
/
Copy pathsupport.ts
File metadata and controls
63 lines (57 loc) · 1.8 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
import { BrowserContext, Page, expect } from "@playwright/test";
import path from "path";
export const waitForRubyVM = async (page: Page) => {
await page.waitForFunction(() => window["rubyVM"]);
};
export const setupDebugLog = (context: BrowserContext) => {
if (process.env.DEBUG) {
context.on("request", (request) =>
console.log(">>", request.method(), request.url()),
);
context.on("response", (response) =>
console.log("<<", response.status(), response.url()),
);
context.on("console", (msg) => console.log("LOG:", msg.text()));
}
};
export const setupProxy = (context: BrowserContext) => {
const cdnPattern =
/cdn.jsdelivr.net\/npm\/@ruby\/.+@.+\/dist\/(.+)/;
context.route(cdnPattern, (route) => {
const request = route.request();
console.log(">> [MOCK]", request.method(), request.url());
const relativePath = request.url().match(cdnPattern)[1];
const mockedPath = path.join(
process.env.RUBY_NPM_PACKAGE_ROOT,
"dist",
relativePath,
);
route.fulfill({
path: mockedPath,
});
});
};
export const { setupUncaughtExceptionRejection, expectUncaughtException } =
(() => {
const rejectUncaughtException = (err: Error) => {
expect(err).toEqual(undefined);
};
return {
setupUncaughtExceptionRejection: (page: Page) => {
page.on("pageerror", rejectUncaughtException);
},
expectUncaughtException: (page: Page) => {
page.off("pageerror", rejectUncaughtException);
},
};
})();
export const resolveBinding = async (page: Page, name: string) => {
let checkResolved;
const resolvedValue = new Promise((resolve) => {
checkResolved = resolve;
});
await page.exposeBinding(name, async (source, v) => {
checkResolved(v);
});
return async () => await resolvedValue;
};