-
Notifications
You must be signed in to change notification settings - Fork 219
/
Copy pathindex.test.js
34 lines (30 loc) · 996 Bytes
/
index.test.js
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
import { test, expect } from "@playwright/test";
import { build } from "esbuild";
// Convert the source file from commonjs to a browser script.
const result = await build({
entryPoints: ["index.js"],
bundle: true,
platform: "browser",
external: ["node:crypto"],
write: false,
});
const source = new TextDecoder().decode(result.outputFiles[0].contents);
// https://playwright.dev/docs/network#modify-requests
test("browser", async ({ page }) => {
// Patch the API endpoint to work around CORS for now.
await page.route(
"https://api.replicate.com/v1/predictions",
async (route) => {
// Fetch original response.
const response = await route.fetch();
// Add a prefix to the title.
return route.fulfill({ response });
}
);
await page.addScriptTag({ content: source });
const result = await page.evaluate(
(token) => window.main(token),
[process.env.REPLICATE_API_TOKEN]
);
expect(result).toBe("hello there, Betty Browser");
});