Skip to content

Commit 31bda1c

Browse files
committed
Put config resolving in separate test
1 parent daa891b commit 31bda1c

File tree

4 files changed

+53
-35
lines changed

4 files changed

+53
-35
lines changed

packages/cli-v3/e2e/index.test.ts

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { execa, execaNode } from "execa";
1+
import { execa } from "execa";
22
import { readFileSync } from "node:fs";
33
import { rename, rm } from "node:fs/promises";
44
import { join, resolve } from "node:path";
55

66
import { typecheckProject } from "../src/commands/deploy";
7-
import { readConfig } from "../src/utilities/configFiles";
7+
import { readConfig, ReadConfigFileResult } from "../src/utilities/configFiles";
88
import { compile } from "./compile";
99
import { Metafile } from "esbuild";
1010
import { Loglevel, LogLevelSchema, PackageManager, PackageManagerSchema } from ".";
@@ -52,13 +52,8 @@ try {
5252
if (testCases.length > 0) {
5353
console.log(`Using ${packageManager}`);
5454

55-
describe.each(testCases)("fixture $name", async ({ name, skipTypecheck }) => {
55+
describe.each(testCases)("fixture $name", async ({ name, skipTypecheck }: TestCase) => {
5656
const fixtureDir = resolve(join(process.cwd(), "e2e/fixtures", name));
57-
const resolvedConfig = await readConfig(fixtureDir, { cwd: fixtureDir });
58-
59-
if (resolvedConfig.status === "error") {
60-
throw new Error(`cannot resolve config in directory ${fixtureDir}`);
61-
}
6257

6358
beforeAll(async () => {
6459
await rm(resolve(join(fixtureDir, ".trigger")), { force: true, recursive: true });
@@ -109,32 +104,47 @@ if (testCases.length > 0) {
109104
{ timeout: 60_000 }
110105
);
111106

112-
if (!skipTypecheck) {
113-
test("typechecks", async () => {
107+
test("resolves config", async () => {
108+
await expect(
109+
(async () => {
110+
global.resolvedConfig = await readConfig(fixtureDir, { cwd: fixtureDir });
111+
})()
112+
).resolves.not.toThrowError();
113+
114+
expect(global.resolvedConfig).not.toBe("error");
115+
});
116+
117+
describe("with resolved config", () => {
118+
test.skipIf(skipTypecheck)("typechecks", async () => {
119+
expect(global.resolvedConfig.status).not.toBe("error");
120+
114121
await expect(
115-
(async () => await typecheckProject(resolvedConfig.config))()
122+
(async () =>
123+
await typecheckProject((global.resolvedConfig as ReadConfigFileResult).config))()
116124
).resolves.not.toThrowError();
117125
});
118-
}
119126

120-
let entrypointMetadata: Metafile["outputs"]["out/stdin.js"];
121-
let workerMetadata: Metafile["outputs"]["out/stdin.js"];
127+
let entrypointMetadata: Metafile["outputs"]["out/stdin.js"];
128+
let workerMetadata: Metafile["outputs"]["out/stdin.js"];
122129

123-
test(
124-
"compiles",
125-
async () => {
126-
await expect(
127-
(async () => {
128-
const { entryPointMetaOutput, metaOutput } = await compile({
129-
resolvedConfig,
130-
});
131-
entrypointMetadata = entryPointMetaOutput;
132-
workerMetadata = metaOutput;
133-
})()
134-
).resolves.not.toThrowError();
135-
},
136-
{ timeout: 60_000 }
137-
);
130+
test(
131+
"compiles",
132+
async () => {
133+
expect(global.resolvedConfig.status).not.toBe("error");
134+
135+
await expect(
136+
(async () => {
137+
const { entryPointMetaOutput, metaOutput } = await compile({
138+
resolvedConfig: global.resolvedConfig,
139+
});
140+
entrypointMetadata = entryPointMetaOutput;
141+
workerMetadata = metaOutput;
142+
})()
143+
).resolves.not.toThrowError();
144+
},
145+
{ timeout: 60_000 }
146+
);
147+
});
138148
});
139149
} else if (process.env.MOD) {
140150
throw new Error(`Unknown fixture '${process.env.MOD}'`);

packages/cli-v3/e2e/vite.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { configDefaults, defineConfig } from "vitest/config";
22

33
export default defineConfig({
44
test: {
5+
setupFiles: ["e2e/vitest.d.ts"],
56
globals: true,
67
exclude: [...configDefaults.exclude, "src/**/*"],
78
},

packages/cli-v3/e2e/vitest.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { ReadConfigResult } from "../src/utilities/configFiles";
2+
3+
declare global {
4+
var resolvedConfig: ReadConfigResult;
5+
}

packages/cli-v3/src/utilities/configFiles.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ export type ReadConfigOptions = {
118118
cwd?: string;
119119
};
120120

121+
export type ReadConfigFileResult = {
122+
status: "file";
123+
config: ResolvedConfig;
124+
path: string;
125+
module?: any;
126+
};
127+
121128
export type ReadConfigResult =
122-
| {
123-
status: "file";
124-
config: ResolvedConfig;
125-
path: string;
126-
module?: any;
127-
}
129+
| ReadConfigFileResult
128130
| {
129131
status: "in-memory";
130132
config: ResolvedConfig;

0 commit comments

Comments
 (0)