Skip to content

Commit 9a873ab

Browse files
committed
fix and update tests
1 parent 41fcbd9 commit 9a873ab

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

packages/wrangler/e2e/types.test.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,43 @@ describe("types", () => {
9696
"FAKE RUNTIME",
9797
].join("\n")
9898
);
99-
console.log(
100-
[
101-
file[0],
102-
file[1],
103-
"FAKE ENV",
104-
"// Begin runtime types",
105-
"FAKE RUNTIME",
106-
].join("\n")
107-
);
10899

109100
await helper.run(`wrangler types`);
110101

111102
const file2 = (await readFile(typesPath)).toString();
112103

113-
expect(file2).toMatchInlineSnapshot(`
114-
"// Generated by Wrangler by running \`wrangler types\` (hash: e82ba4d7b995dd9ca6fb0332d81f889b)
115-
// Runtime types generated with [email protected] 2023-01-01 no_global_navigator,nodejs_compat
116-
// eslint-disable-next-line @typescript-eslint/no-empty-interface,@typescript-eslint/no-empty-object-type
117-
interface Env {
118-
}
104+
// regenerates env types
105+
expect(file2).toContain("interface Env {");
106+
// uses cached runtime types
107+
expect(file2).toContain("// Begin runtime types");
108+
expect(file2).toContain("FAKE RUNTIME");
109+
});
119110

120-
// Begin runtime types
121-
FAKE RUNTIME"
122-
`);
111+
it("should prompt you to update types if they've been changed", async () => {
112+
const helper = new WranglerE2ETestHelper();
113+
await helper.seed(seed);
114+
await helper.run(`wrangler types`);
115+
seed["wrangler.toml"] = dedent`
116+
name = "test-worker"
117+
main = "src/index.ts"
118+
compatibility_date = "2023-01-01"
119+
compatibility_flags = ["nodejs_compat", "no_global_navigator"]
120+
[vars]
121+
BEEP = "BOOP"
122+
`;
123+
await helper.seed(seed);
124+
const worker = helper.runLongLived("wrangler dev");
125+
await worker.readUntil(/ It looks like your types might be out of date./);
126+
seed["wrangler.toml"] = dedent`
127+
name = "test-worker"
128+
main = "src/index.ts"
129+
compatibility_date = "2023-01-01"
130+
compatibility_flags = ["nodejs_compat"]
131+
[vars]
132+
BEEP = "BOOP"
133+
ASDf = "ADSfadsf"
134+
`;
135+
await helper.seed(seed);
136+
await worker.readUntil(/ It looks like your types might be out of date./);
123137
});
124138
});

packages/wrangler/src/type-generation/helpers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const checkTypesDiff = async (config: Config, entry: Entry) => {
1111
}
1212
let maybeExistingTypesFile: string[];
1313
try {
14+
// Note: this checks the default location only
1415
maybeExistingTypesFile = readFileSync(
1516
"./worker-configuration.d.ts",
1617
"utf-8"
@@ -56,7 +57,8 @@ export const checkTypesDiff = async (config: Config, entry: Entry) => {
5657
const envOutOfDate = existingEnvHeader && maybeExistingHash !== newHash;
5758
const runtimeOutOfDate =
5859
existingRuntimeHeader && existingRuntimeHeader !== newRuntimeHeader;
59-
if (envOutOfDate && runtimeOutOfDate) {
60+
61+
if (envOutOfDate || runtimeOutOfDate) {
6062
logger.log(
6163
"❓ It looks like your types might be out of date. Have you updated your config file since last running `wrangler types`?"
6264
);

0 commit comments

Comments
 (0)