|
1 | | -import { test, expect, Page } from '@playwright/test'; |
2 | | -import path from "path" |
3 | | -import { waitForRubyVM, setupDebugLog, setupProxy } from "../support" |
4 | | -import { readFileSync } from 'fs'; |
5 | | -import http from 'http'; |
6 | | -import https from 'https'; |
| 1 | +import { test, expect, Page } from "@playwright/test"; |
| 2 | +import path from "path"; |
| 3 | +import { waitForRubyVM, setupDebugLog, setupProxy } from "../support"; |
| 4 | +import { readFileSync } from "fs"; |
| 5 | +import http from "http"; |
| 6 | +import https from "https"; |
7 | 7 |
|
8 | 8 | test.beforeEach(async ({ context }) => { |
9 | 9 | setupDebugLog(context); |
10 | 10 | if (process.env.RUBY_NPM_PACKAGE_ROOT) { |
11 | 11 | setupProxy(context); |
12 | 12 | } else { |
13 | 13 | console.info("Testing against CDN deployed files"); |
14 | | - const packagePath = path.join(__dirname, "..", "..", "package.json") |
15 | | - const packageInfo = JSON.parse(readFileSync(packagePath, "utf-8")) |
16 | | - const version = packageInfo.version |
17 | | - const url = `https://registry.npmjs.org/ruby-head-wasm-wasi/${version}` |
18 | | - const response = await new Promise<http.IncomingMessage>((resolve, reject) => { |
19 | | - https.get(url, resolve).on("error", reject) |
20 | | - }) |
| 14 | + const packagePath = path.join(__dirname, "..", "..", "package.json"); |
| 15 | + const packageInfo = JSON.parse(readFileSync(packagePath, "utf-8")); |
| 16 | + const version = packageInfo.version; |
| 17 | + const url = `https://registry.npmjs.org/ruby-head-wasm-wasi/${version}`; |
| 18 | + const response = await new Promise<http.IncomingMessage>( |
| 19 | + (resolve, reject) => { |
| 20 | + https.get(url, resolve).on("error", reject); |
| 21 | + } |
| 22 | + ); |
21 | 23 | if (response.statusCode == 404) { |
22 | | - console.log(`ruby-head-wasm-wasi@${version} is not published yet, so skipping CDN tests`); |
| 24 | + console.log( |
| 25 | + `ruby-head-wasm-wasi@${version} is not published yet, so skipping CDN tests` |
| 26 | + ); |
23 | 27 | test.skip(); |
24 | 28 | } |
25 | 29 | } |
26 | | -}) |
| 30 | +}); |
27 | 31 |
|
28 | | -test('hello.html is healthy', async ({ page }) => { |
29 | | - const messages = [] |
30 | | - page.on("console", msg => messages.push(msg.text())) |
31 | | - await page.goto('/hello.html'); |
| 32 | +test("hello.html is healthy", async ({ page }) => { |
| 33 | + const messages = []; |
| 34 | + page.on("console", (msg) => messages.push(msg.text())); |
| 35 | + await page.goto("/hello.html"); |
32 | 36 |
|
33 | | - await waitForRubyVM(page) |
34 | | - expect(messages[messages.length - 1]).toEqual("Hello, world!\n") |
| 37 | + await waitForRubyVM(page); |
| 38 | + expect(messages[messages.length - 1]).toEqual("Hello, world!\n"); |
35 | 39 | }); |
36 | 40 |
|
37 | | -test('lucky.html is healthy', async ({ page }) => { |
38 | | - await page.goto('/lucky.html'); |
39 | | - await waitForRubyVM(page) |
40 | | - await page.getByRole('button', { name: 'Draw Omikuji' }).click() |
41 | | - const result = await page.locator("#result").textContent() |
| 41 | +test("lucky.html is healthy", async ({ page }) => { |
| 42 | + await page.goto("/lucky.html"); |
| 43 | + await waitForRubyVM(page); |
| 44 | + await page.getByRole("button", { name: "Draw Omikuji" }).click(); |
| 45 | + const result = await page.locator("#result").textContent(); |
42 | 46 |
|
43 | | - expect(result).toMatch(/(Lucky|Unlucky)/) |
| 47 | + expect(result).toMatch(/(Lucky|Unlucky)/); |
44 | 48 | }); |
45 | 49 |
|
46 | | -test('script-src/index.html is healthy', async ({ page }) => { |
47 | | - const messages = [] |
48 | | - page.on("console", msg => messages.push(msg.text())) |
49 | | - await page.goto('/script-src/index.html'); |
| 50 | +test("script-src/index.html is healthy", async ({ page }) => { |
| 51 | + const messages = []; |
| 52 | + page.on("console", (msg) => messages.push(msg.text())); |
| 53 | + await page.goto("/script-src/index.html"); |
50 | 54 |
|
51 | | - await waitForRubyVM(page) |
52 | | - const expected = "Hello, world!\n" |
| 55 | + await waitForRubyVM(page); |
| 56 | + const expected = "Hello, world!\n"; |
53 | 57 | while (messages[messages.length - 1] != expected) { |
54 | | - await page.waitForEvent("console") |
| 58 | + await page.waitForEvent("console"); |
55 | 59 | } |
56 | 60 | }); |
0 commit comments