mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-14 13:22:37 +00:00
fix(app): keep typechecking after Expo generates environment types (#6656)
Expo declares NODE_ENV readonly after web startup. Preserve the early test environment setup with Object.assign and exercise the real configuration with Expo types in a failing-first compiler regression. Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
@@ -8,6 +9,35 @@ 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");
|
||||
const tsgoEntry = path.join(
|
||||
path.dirname(require.resolve("@typescript/native-preview/package.json")),
|
||||
"bin/tsgo.js",
|
||||
);
|
||||
|
||||
it("the test configuration typechecks with Expo's generated environment declaration", () => {
|
||||
const fixtureDir = mkdtempSync(path.join(appDir, ".vitest-expo-env-"));
|
||||
try {
|
||||
writeFileSync(path.join(fixtureDir, "expo-env.d.ts"), '/// <reference types="expo/types" />\n');
|
||||
writeFileSync(
|
||||
path.join(fixtureDir, "tsconfig.json"),
|
||||
JSON.stringify({
|
||||
extends: "../tsconfig.json",
|
||||
files: ["../vitest.config.ts", "expo-env.d.ts"],
|
||||
include: [],
|
||||
}),
|
||||
);
|
||||
const result = spawnSync(
|
||||
process.execPath,
|
||||
[tsgoEntry, "--noEmit", "--project", path.join(fixtureDir, "tsconfig.json")],
|
||||
{ cwd: appDir, encoding: "utf8", timeout: 30_000 },
|
||||
);
|
||||
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(result.status, result.stdout + result.stderr).toBe(0);
|
||||
} finally {
|
||||
rmSync(fixtureDir, { recursive: true, force: true });
|
||||
}
|
||||
}, 40_000);
|
||||
|
||||
it.each([
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@ import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
// Set this before Vite resolves dependencies and Vitest starts its workers.
|
||||
process.env.NODE_ENV = "test";
|
||||
Object.assign(process.env, { NODE_ENV: "test" });
|
||||
|
||||
const appNodeModules = path.resolve(__dirname, "node_modules");
|
||||
const rootNodeModules = path.resolve(__dirname, "../../node_modules");
|
||||
|
||||
Reference in New Issue
Block a user