mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-03 22:02:08 +03:00
Turbopack (stable in Next 16) becomes the code default in the three entry points that previously required an explicit OMNIROUTE_USE_TURBOPACK=1: - scripts/build/build-next-isolated.mjs (production build) - scripts/dev/run-next.mjs (dev server) - scripts/dev/run-next-playwright.mjs (playwright dev runner) OMNIROUTE_USE_TURBOPACK=0 remains the webpack escape hatch (Windows / native-binding / bundler-compat issues), and only the documented '0' opts out — junk values keep the default. Benchmarked on this codebase (same tree, Next 16.2.9): webpack 1035s vs Turbopack 539s on a 32-core box; ~20min vs 6min59s on ubuntu-latest. Artifact validated end-to-end (standalone smoke + e2e/package-artifact/ electron-package-smoke CI jobs, Docker amd64+arm64 builds clean with the v3.8.27 ImportTracer panic gone on 16.2.9). TDD: tests/unit/build-bundler-default-turbopack.test.ts (new) + run-next-playwright.test.ts extended with the unset-env default case; both red before the flip, green after. ENVIRONMENT.md updated.
129 lines
3.6 KiB
TypeScript
129 lines
3.6 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
const playwrightRunner = await import("../../scripts/dev/run-next-playwright.mjs");
|
|
|
|
test("resolvePlaywrightAppBackupDir uses a per-run backup when a stale backup already exists", () => {
|
|
const cwd = "/tmp/omniroute-playwright-runner";
|
|
|
|
assert.equal(
|
|
playwrightRunner.resolvePlaywrightAppBackupDir({
|
|
cwd,
|
|
baseBackupExists: false,
|
|
appDirExists: true,
|
|
pid: 123,
|
|
now: 456,
|
|
}),
|
|
path.join(cwd, "app.__qa_backup")
|
|
);
|
|
|
|
assert.equal(
|
|
playwrightRunner.resolvePlaywrightAppBackupDir({
|
|
cwd,
|
|
baseBackupExists: true,
|
|
appDirExists: true,
|
|
pid: 123,
|
|
now: 456,
|
|
}),
|
|
path.join(cwd, "app.__qa_backup.123.456")
|
|
);
|
|
});
|
|
|
|
test("shouldUseWebpackForPlaywrightDev only opts into webpack when turbopack is disabled", () => {
|
|
assert.equal(
|
|
playwrightRunner.shouldUseWebpackForPlaywrightDev({
|
|
mode: "dev",
|
|
env: { OMNIROUTE_USE_TURBOPACK: "1" },
|
|
}),
|
|
false
|
|
);
|
|
|
|
assert.equal(
|
|
playwrightRunner.shouldUseWebpackForPlaywrightDev({
|
|
mode: "dev",
|
|
env: { OMNIROUTE_USE_TURBOPACK: "0" },
|
|
}),
|
|
true
|
|
);
|
|
|
|
assert.equal(
|
|
playwrightRunner.shouldUseWebpackForPlaywrightDev({
|
|
mode: "start",
|
|
env: { OMNIROUTE_USE_TURBOPACK: "1" },
|
|
}),
|
|
false
|
|
);
|
|
|
|
// Turbopack is the default: an unset env var must NOT fall back to webpack.
|
|
assert.equal(
|
|
playwrightRunner.shouldUseWebpackForPlaywrightDev({
|
|
mode: "dev",
|
|
env: {},
|
|
}),
|
|
false
|
|
);
|
|
});
|
|
|
|
test("standalone asset helpers detect and rehydrate missing standalone static assets", () => {
|
|
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-playwright-assets-"));
|
|
const standaloneServerPath = path.join(tempRoot, ".next", "standalone", "server.js");
|
|
const rootStaticDirPath = path.join(tempRoot, ".next", "static");
|
|
const standaloneStaticDirPath = path.join(tempRoot, ".next", "standalone", ".next", "static");
|
|
const rootPublicDirPath = path.join(tempRoot, "public");
|
|
const standalonePublicDirPath = path.join(tempRoot, ".next", "standalone", "public");
|
|
|
|
fs.mkdirSync(path.dirname(standaloneServerPath), { recursive: true });
|
|
fs.writeFileSync(standaloneServerPath, "server");
|
|
fs.mkdirSync(rootStaticDirPath, { recursive: true });
|
|
fs.mkdirSync(rootPublicDirPath, { recursive: true });
|
|
fs.writeFileSync(path.join(rootStaticDirPath, "chunk.js"), "console.log('chunk');");
|
|
fs.writeFileSync(path.join(rootPublicDirPath, "favicon.svg"), "<svg />");
|
|
|
|
assert.equal(
|
|
playwrightRunner.standaloneAssetsNeedSync({
|
|
standaloneServerPath,
|
|
rootStaticDirPath,
|
|
standaloneStaticDirPath,
|
|
}),
|
|
true
|
|
);
|
|
|
|
const logs = [];
|
|
const changed = playwrightRunner.syncStandaloneRuntimeAssets({
|
|
standaloneServerPath,
|
|
rootStaticDirPath,
|
|
standaloneStaticDirPath,
|
|
rootPublicDirPath,
|
|
standalonePublicDirPath,
|
|
log: {
|
|
log(message) {
|
|
logs.push(message);
|
|
},
|
|
},
|
|
});
|
|
|
|
assert.equal(changed, true);
|
|
assert.equal(
|
|
fs.readFileSync(path.join(standaloneStaticDirPath, "chunk.js"), "utf8"),
|
|
"console.log('chunk');"
|
|
);
|
|
assert.equal(
|
|
fs.readFileSync(path.join(standalonePublicDirPath, "favicon.svg"), "utf8"),
|
|
"<svg />"
|
|
);
|
|
assert.equal(
|
|
playwrightRunner.standaloneAssetsNeedSync({
|
|
standaloneServerPath,
|
|
rootStaticDirPath,
|
|
standaloneStaticDirPath,
|
|
}),
|
|
false
|
|
);
|
|
assert.match(logs[0] || "", /Rehydrated standalone static\/public assets/);
|
|
|
|
fs.rmSync(tempRoot, { recursive: true, force: true });
|
|
});
|