|
1 | 1 | import VERSIONS from "../versions.json" with { type: "json" }; |
2 | | -import { app } from "./main.ts"; |
3 | 2 | import { |
4 | | - buildProd, |
5 | | - withBrowserApp, |
| 3 | + withBrowser, |
| 4 | + withChildProcessServer, |
6 | 5 | } from "../packages/fresh/tests/test_utils.tsx"; |
7 | 6 | import { expect } from "@std/expect"; |
8 | 7 | import { retry } from "@std/async/retry"; |
| 8 | +import { buildVite } from "../packages/plugin-vite/tests/test_utils.ts"; |
9 | 9 |
|
10 | | -const applyCache = await buildProd({ root: import.meta.dirname! }); |
11 | | -applyCache(app); |
12 | | - |
13 | | -const handler = app.handler(); |
| 10 | +const result = await buildVite(import.meta.dirname!); |
14 | 11 |
|
15 | 12 | Deno.test("CORS should not set on GET /fresh-badge.svg", async () => { |
16 | | - const req = new Request("http://localhost/fresh-badge.svg"); |
17 | | - const resp = await handler(req); |
18 | | - await resp?.body?.cancel(); |
19 | | - |
20 | | - expect(resp.headers.get("cross-origin-resource-policy")).toEqual(null); |
| 13 | + await withChildProcessServer( |
| 14 | + { |
| 15 | + cwd: result.tmp, |
| 16 | + args: ["serve", "-A", "--port", "0", "_fresh/server.js"], |
| 17 | + }, |
| 18 | + async (address) => { |
| 19 | + const resp = await fetch(`${address}/fresh-badge.svg`); |
| 20 | + await resp?.body?.cancel(); |
| 21 | + expect(resp.headers.get("cross-origin-resource-policy")).toEqual(null); |
| 22 | + }, |
| 23 | + ); |
21 | 24 | }); |
22 | 25 |
|
23 | 26 | Deno.test({ |
24 | 27 | name: "shows version selector", |
25 | 28 | fn: async () => { |
26 | 29 | await retry(async () => { |
27 | | - await withBrowserApp(app, async (page, address) => { |
28 | | - await page.goto(`${address}/docs`); |
29 | | - await page.waitForSelector("#version"); |
| 30 | + await withChildProcessServer( |
| 31 | + { |
| 32 | + cwd: result.tmp, |
| 33 | + args: ["serve", "-A", "--port", "0", "_fresh/server.js"], |
| 34 | + }, |
| 35 | + async (address) => { |
| 36 | + await withBrowser(async (page) => { |
| 37 | + await page.goto(`${address}/docs`); |
| 38 | + await page.waitForSelector("#version"); |
30 | 39 |
|
31 | | - // Check that we redirected to the first page |
32 | | - await page.waitForFunction(() => { |
33 | | - const url = new URL(window.location.href); |
34 | | - return url.pathname === "/docs/introduction"; |
35 | | - }); |
| 40 | + // Check that we redirected to the first page |
| 41 | + await page.waitForFunction(() => { |
| 42 | + const url = new URL(window.location.href); |
| 43 | + return url.pathname === "/docs/introduction"; |
| 44 | + }); |
36 | 45 |
|
37 | | - // Wait for version selector to be enabled |
38 | | - await page.waitForSelector("#version:not([disabled])"); |
| 46 | + // Wait for version selector to be enabled |
| 47 | + await page.waitForSelector("#version:not([disabled])"); |
39 | 48 |
|
40 | | - const options = await page |
41 | | - .locator<HTMLSelectElement>("#version") |
42 | | - .evaluate((el) => { |
43 | | - return Array.from(el.options).map((option) => ({ |
44 | | - value: option.value, |
45 | | - label: option.textContent, |
46 | | - })); |
47 | | - }); |
| 49 | + const options = await page |
| 50 | + .locator<HTMLSelectElement>("#version") |
| 51 | + .evaluate((el) => { |
| 52 | + return Array.from(el.options).map((option) => ({ |
| 53 | + value: option.value, |
| 54 | + label: option.textContent, |
| 55 | + })); |
| 56 | + }); |
48 | 57 |
|
49 | | - expect(options).toEqual([ |
50 | | - { |
51 | | - value: "canary", |
52 | | - label: "canary", |
53 | | - }, |
54 | | - { |
55 | | - value: "latest", |
56 | | - label: VERSIONS[0], |
57 | | - }, |
58 | | - ]); |
| 58 | + expect(options).toEqual([ |
| 59 | + { |
| 60 | + value: "canary", |
| 61 | + label: "canary", |
| 62 | + }, |
| 63 | + { |
| 64 | + value: "latest", |
| 65 | + label: VERSIONS[0], |
| 66 | + }, |
| 67 | + ]); |
59 | 68 |
|
60 | | - const selectValue = await page |
61 | | - .locator<HTMLSelectElement>("#version") |
62 | | - .evaluate((el) => el.value); |
63 | | - expect(selectValue).toEqual("latest"); |
| 69 | + const selectValue = await page |
| 70 | + .locator<HTMLSelectElement>("#version") |
| 71 | + .evaluate((el) => el.value); |
| 72 | + expect(selectValue).toEqual("latest"); |
64 | 73 |
|
65 | | - // Go to canary page |
66 | | - await page.evaluate(() => { |
67 | | - const el = document.querySelector("#version") as HTMLSelectElement; |
68 | | - el.value = "canary"; |
69 | | - el.dispatchEvent(new Event("change")); |
70 | | - }); |
| 74 | + // Go to canary page |
| 75 | + await page.evaluate(() => { |
| 76 | + const el = document.querySelector( |
| 77 | + "#version", |
| 78 | + ) as HTMLSelectElement; |
| 79 | + el.value = "canary"; |
| 80 | + el.dispatchEvent(new Event("change")); |
| 81 | + }); |
71 | 82 |
|
72 | | - await new Promise((r) => setTimeout(r, 1000)); |
| 83 | + await new Promise((r) => setTimeout(r, 1000)); |
73 | 84 |
|
74 | | - await page.waitForSelector("#version:not([disabled])"); |
75 | | - const selectValue2 = await page |
76 | | - .locator<HTMLSelectElement>("#version") |
77 | | - .evaluate((el) => el.value); |
78 | | - expect(selectValue2).toEqual("canary"); |
| 85 | + await page.waitForSelector("#version:not([disabled])"); |
| 86 | + const selectValue2 = await page |
| 87 | + .locator<HTMLSelectElement>("#version") |
| 88 | + .evaluate((el) => el.value); |
| 89 | + expect(selectValue2).toEqual("canary"); |
79 | 90 |
|
80 | | - await page.waitForFunction(() => { |
81 | | - const url = new URL(window.location.href); |
82 | | - return url.pathname === "/docs/canary/introduction"; |
83 | | - }); |
84 | | - }); |
| 91 | + await page.waitForFunction(() => { |
| 92 | + const url = new URL(window.location.href); |
| 93 | + return url.pathname === "/docs/canary/introduction"; |
| 94 | + }); |
| 95 | + }); |
| 96 | + }, |
| 97 | + ); |
85 | 98 | }); |
86 | 99 | }, |
87 | 100 | }); |
0 commit comments