mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-14 13:22:37 +00:00
Run React tests when the shell uses NODE_ENV=production (#6572)
* fix(tests): run React tests from production shells Vitest preserves an inherited NODE_ENV, selecting React without its test APIs. Pin the environment before dependency resolution and worker startup in both test entry points. Co-authored-by: Ivan Malison <IvanMalison@gmail.com> * test(app): expect zero edits for a pure staged rename The rename patch correction on main preserves unchanged content. Keep the discard journey intact and update its obsolete added-line assertion. --------- Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com> Co-authored-by: Ivan Malison <IvanMalison@gmail.com>
This commit is contained in:
co-authored by
Ivan Malison
parent
a3f75aa9e4
commit
b412374f0c
@@ -683,7 +683,7 @@ test("discarding a staged rename restores its source path", async ({ page }) =>
|
|||||||
|
|
||||||
const panel = page.getByTestId("working-diff-panel").filter({ visible: true });
|
const panel = page.getByTestId("working-diff-panel").filter({ visible: true });
|
||||||
const renamedHeader = diffHeaderForPath(panel, "src/zz-renamed.ts");
|
const renamedHeader = diffHeaderForPath(panel, "src/zz-renamed.ts");
|
||||||
await expect(renamedHeader).toHaveAccessibleName("src/zz-renamed.ts, +1, -0");
|
await expect(renamedHeader).toHaveAccessibleName("src/zz-renamed.ts, +0, -0");
|
||||||
const renamedToggle = renamedHeader.getByTestId(/^diff-file-\d+-toggle$/);
|
const renamedToggle = renamedHeader.getByTestId(/^diff-file-\d+-toggle$/);
|
||||||
const toggleTestId = await renamedToggle.getAttribute("data-testid");
|
const toggleTestId = await renamedToggle.getAttribute("data-testid");
|
||||||
expect(toggleTestId).not.toBeNull();
|
expect(toggleTestId).not.toBeNull();
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { spawnSync } from "node:child_process";
|
||||||
|
import { createRequire } from "node:module";
|
||||||
|
import path from "node:path";
|
||||||
|
import { fileURLToPath } from "node:url";
|
||||||
|
import { expect, it } from "vitest";
|
||||||
|
|
||||||
|
const appDir = fileURLToPath(new URL(".", import.meta.url));
|
||||||
|
const rootDir = path.resolve(appDir, "../..");
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
const vitestEntry = path.join(path.dirname(require.resolve("vitest/package.json")), "vitest.mjs");
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
{
|
||||||
|
name: "root",
|
||||||
|
cwd: rootDir,
|
||||||
|
args: ["packages/app/src/screens/workspace/use-mounted-tab-set.test.ts"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "app",
|
||||||
|
cwd: appDir,
|
||||||
|
args: ["--project", "unit", "src/screens/workspace/use-mounted-tab-set.test.ts"],
|
||||||
|
},
|
||||||
|
])(
|
||||||
|
"$name tests can render React when the shell exports NODE_ENV=production",
|
||||||
|
({ cwd, args }) => {
|
||||||
|
const result = spawnSync(process.execPath, [vitestEntry, "run", ...args], {
|
||||||
|
cwd,
|
||||||
|
env: { ...process.env, NODE_ENV: "production" },
|
||||||
|
encoding: "utf8",
|
||||||
|
timeout: 30_000,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.error).toBeUndefined();
|
||||||
|
expect(result.status, result.stdout + result.stderr).toBe(0);
|
||||||
|
},
|
||||||
|
40_000,
|
||||||
|
);
|
||||||
@@ -3,6 +3,9 @@ import { playwright } from "@vitest/browser-playwright";
|
|||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
|
||||||
|
// Set this before Vite resolves dependencies and Vitest starts its workers.
|
||||||
|
process.env.NODE_ENV = "test";
|
||||||
|
|
||||||
const appNodeModules = path.resolve(__dirname, "node_modules");
|
const appNodeModules = path.resolve(__dirname, "node_modules");
|
||||||
const rootNodeModules = path.resolve(__dirname, "../../node_modules");
|
const rootNodeModules = path.resolve(__dirname, "../../node_modules");
|
||||||
const resolvePackageEntry = (packageName: string) => {
|
const resolvePackageEntry = (packageName: string) => {
|
||||||
@@ -26,6 +29,7 @@ export default defineConfig({
|
|||||||
"src/**/*.{test,spec}.{ts,tsx}",
|
"src/**/*.{test,spec}.{ts,tsx}",
|
||||||
"native-release-version.test.ts",
|
"native-release-version.test.ts",
|
||||||
"app.config.test.ts",
|
"app.config.test.ts",
|
||||||
|
"vitest-environment.test.ts",
|
||||||
],
|
],
|
||||||
setupFiles: [path.resolve(__dirname, "vitest.setup.ts")],
|
setupFiles: [path.resolve(__dirname, "vitest.setup.ts")],
|
||||||
exclude: [...configDefaults.exclude, "e2e/**", "src/**/*.browser.{test,spec}.{ts,tsx}"],
|
exclude: [...configDefaults.exclude, "e2e/**", "src/**/*.browser.{test,spec}.{ts,tsx}"],
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import fs from "node:fs";
|
|||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { configDefaults, defineConfig } from "vitest/config";
|
import { configDefaults, defineConfig } from "vitest/config";
|
||||||
|
|
||||||
|
// React's test APIs require its development build, even in a production shell.
|
||||||
|
process.env.NODE_ENV = "test";
|
||||||
|
|
||||||
const appDir = path.resolve(__dirname, "packages/app");
|
const appDir = path.resolve(__dirname, "packages/app");
|
||||||
const appNodeModules = path.resolve(appDir, "node_modules");
|
const appNodeModules = path.resolve(appDir, "node_modules");
|
||||||
const rootNodeModules = path.resolve(__dirname, "node_modules");
|
const rootNodeModules = path.resolve(__dirname, "node_modules");
|
||||||
|
|||||||
Reference in New Issue
Block a user