diff --git a/src/config.ts b/src/config.ts index 2f46fd76..8cc82d74 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,5 @@ import * as path from "@std/path"; -import { MODE, type Mode } from "./runtime/server/mod.ts"; +import type { Mode } from "./runtime/server/mod.ts"; export interface FreshPlugin { name: string; @@ -69,7 +69,7 @@ export function normalizeConfig(options: FreshConfig): ResolvedFreshConfig { }, basePath: options.basePath ?? "", staticDir: options.staticDir ?? path.join(root, "static"), - mode: MODE, + mode: "production", }; } diff --git a/src/dev/builder.ts b/src/dev/builder.ts index bce57670..0934b1df 100644 --- a/src/dev/builder.ts +++ b/src/dev/builder.ts @@ -70,6 +70,8 @@ export class Builder implements FreshBuilder { .use(devErrorOverlay()) .mountApp("*", app); + devApp.config.mode = "development"; + setBuildCache( devApp, new MemoryBuildCache( @@ -97,6 +99,7 @@ export class Builder implements FreshBuilder { this.#options.target, ), ); + return await this.#build(app, false); } @@ -117,7 +120,9 @@ export class Builder implements FreshBuilder { // Ignore } - const buildCache = getBuildCache(app)! as MemoryBuildCache | DiskBuildCache; + const buildCache = getBuildCache(app)! as + | MemoryBuildCache + | DiskBuildCache; const runtimePath = dev ? "../runtime/client/dev.ts" diff --git a/src/dev/mod.ts b/src/dev/mod.ts index ec59712e..818a37ab 100644 --- a/src/dev/mod.ts +++ b/src/dev/mod.ts @@ -1,10 +1,6 @@ -import { setMode } from "../runtime/server/mod.ts"; - export { Builder, type FreshBuilder } from "./builder.ts"; export { type OnTransformArgs, type OnTransformOptions, type TransformFn, } from "./file_transformer.ts"; - -setMode("development"); diff --git a/src/runtime/server/mod.ts b/src/runtime/server/mod.ts index 6909a30c..99a9ee03 100644 --- a/src/runtime/server/mod.ts +++ b/src/runtime/server/mod.ts @@ -1,9 +1,4 @@ /** * The mode Fresh can run in. */ -export type Mode = "development" | "build" | "production"; -export let MODE: Mode = "production"; - -export function setMode(mode: Mode) { - MODE = mode; -} +export type Mode = "development" | "production"; diff --git a/www/main_test.ts b/www/main_test.ts index 49d8f624..54e81c86 100644 --- a/www/main_test.ts +++ b/www/main_test.ts @@ -2,6 +2,7 @@ import VERSIONS from "../versions.json" with { type: "json" }; import { app } from "./main.ts"; import { buildProd, withBrowserApp } from "../tests/test_utils.tsx"; import { expect } from "@std/expect"; +import { retry } from "@std/async/retry"; const handler = await app.handler(); @@ -17,62 +18,64 @@ Deno.test("CORS should not set on GET /fresh-badge.svg", async () => { Deno.test({ name: "shows version selector", fn: async () => { - await withBrowserApp(app, async (page, address) => { - await page.goto(`${address}/docs`); - await page.waitForSelector("#version"); + await retry(async () => { + await withBrowserApp(app, async (page, address) => { + await page.goto(`${address}/docs`); + await page.waitForSelector("#version"); - // Check that we redirected to the first page - await page.waitForFunction(() => { - const url = new URL(window.location.href); - return url.pathname === "/docs/introduction"; - }); - - // Wait for version selector to be enabled - await page.waitForSelector("#version:not([disabled])"); - - const options = await page - .locator("#version") - .evaluate((el) => { - return Array.from(el.options).map((option) => ({ - value: option.value, - label: option.textContent, - })); + // Check that we redirected to the first page + await page.waitForFunction(() => { + const url = new URL(window.location.href); + return url.pathname === "/docs/introduction"; }); - expect(options).toEqual([ - { - value: "canary", - label: "canary", - }, - { - value: "latest", - label: VERSIONS[0], - }, - ]); + // Wait for version selector to be enabled + await page.waitForSelector("#version:not([disabled])"); - const selectValue = await page - .locator("#version") - .evaluate((el) => el.value); - expect(selectValue).toEqual("latest"); + const options = await page + .locator("#version") + .evaluate((el) => { + return Array.from(el.options).map((option) => ({ + value: option.value, + label: option.textContent, + })); + }); - // Go to canary page - await page.evaluate(() => { - const el = document.querySelector("#version") as HTMLSelectElement; - el.value = "canary"; - el.dispatchEvent(new Event("change")); - }); + expect(options).toEqual([ + { + value: "canary", + label: "canary", + }, + { + value: "latest", + label: VERSIONS[0], + }, + ]); - await new Promise((r) => setTimeout(r, 1000)); + const selectValue = await page + .locator("#version") + .evaluate((el) => el.value); + expect(selectValue).toEqual("latest"); - await page.waitForSelector("#version:not([disabled])"); - const selectValue2 = await page - .locator("#version") - .evaluate((el) => el.value); - expect(selectValue2).toEqual("canary"); + // Go to canary page + await page.evaluate(() => { + const el = document.querySelector("#version") as HTMLSelectElement; + el.value = "canary"; + el.dispatchEvent(new Event("change")); + }); - await page.waitForFunction(() => { - const url = new URL(window.location.href); - return url.pathname === "/docs/canary/introduction"; + await new Promise((r) => setTimeout(r, 1000)); + + await page.waitForSelector("#version:not([disabled])"); + const selectValue2 = await page + .locator("#version") + .evaluate((el) => el.value); + expect(selectValue2).toEqual("canary"); + + await page.waitForFunction(() => { + const url = new URL(window.location.href); + return url.pathname === "/docs/canary/introduction"; + }); }); }); },