Skip to content

Commit 34a9edc

Browse files
committed
update tests
1 parent 3723079 commit 34a9edc

File tree

5 files changed

+80
-47
lines changed

5 files changed

+80
-47
lines changed

packages/create-cloudflare/e2e-tests/frameworks.test.ts

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { detectPackageManager } from "helpers/packageManagers";
1313
import { retry } from "helpers/retry";
1414
import { sleep } from "helpers/sleep";
15+
import * as jsonc from "jsonc-parser";
1516
import { fetch } from "undici";
1617
import { beforeAll, describe, expect } from "vitest";
1718
import { deleteProject, deleteWorker } from "../scripts/common";
@@ -41,12 +42,9 @@ import type { Writable } from "stream";
4142

4243
type FrameworkTestConfig = RunnerConfig & {
4344
testCommitMessage: boolean;
45+
nodeCompat: boolean;
4446
unsupportedPms?: string[];
4547
unsupportedOSs?: string[];
46-
verifyBuildCfTypes?: {
47-
outputFile: string;
48-
envInterfaceName: string;
49-
};
5048
verifyBuild?: {
5149
outputDir: string;
5250
script: string;
@@ -180,11 +178,8 @@ describe.concurrent(
180178
project.path,
181179
logStream,
182180
);
183-
await verifyBuildCfTypesScript(
184-
frameworkConfig,
185-
project.path,
186-
logStream,
187-
);
181+
182+
await verifyTypes(testConfig, frameworkConfig, project.path);
188183
await verifyBuildScript(testConfig, project.path, logStream);
189184
} catch (e) {
190185
console.error("ERROR", e);
@@ -360,45 +355,53 @@ const verifyPreviewScript = async (
360355
}
361356
};
362357

363-
const verifyBuildCfTypesScript = async (
364-
{ workersTypes, typesPath, envInterfaceName }: TemplateConfig,
358+
const verifyTypes = async (
359+
{ nodeCompat }: FrameworkTestConfig,
360+
{
361+
workersTypes,
362+
typesPath = "./worker-configuration.d.ts",
363+
envInterfaceName = "Env",
364+
}: TemplateConfig,
365365
projectPath: string,
366-
logStream: Writable,
367366
) => {
368367
if (workersTypes === "none") {
369368
return;
370369
}
371370

372-
// Run the `cf-typegen` script to generate types for bindings in fixture
373-
const buildTypesProc = spawnWithLogging(
374-
[pm, "run", "cf-typegen"],
375-
{ cwd: projectPath },
376-
logStream,
377-
);
378-
379-
await waitForExit(buildTypesProc);
371+
const outputFileContent = readFile(join(projectPath, typesPath)).split("\n");
380372

381-
const outputFileContent = readFile(
382-
join(projectPath, typesPath ?? "worker-configuration.d.ts"),
383-
).split("\n");
384-
385-
// the file contains the env interface
386-
const hasEnvInterfacePre = outputFileContent.some(
373+
const hasEnvInterface = outputFileContent.some(
387374
(line) =>
388375
// old type gen - some framework templates pin older versions of wrangler
389-
line === `interface ${envInterfaceName ?? "Env"} {` ||
376+
line === `interface ${envInterfaceName} {` ||
390377
// new after importable env change
391-
line ===
392-
`interface ${envInterfaceName ?? "Env"} extends Cloudflare.Env {}`,
378+
line === `interface ${envInterfaceName} extends Cloudflare.Env {}`,
393379
);
394-
expect(hasEnvInterfacePre).toBe(true);
380+
expect(hasEnvInterface).toBe(true);
395381

396-
// if the types were installed, only the Env types will be present
382+
// if the runtime types were installed, they wont be in this file
397383
if (workersTypes === "generated") {
398384
expect(outputFileContent[2]).match(
399385
/\/\/ Runtime types generated with workerd@1\.\d{8}\.\d \d{4}-\d{2}-\d{2} ([a-z_]+,?)*/,
400386
);
401387
}
388+
389+
const tsconfigPath = join(projectPath, "tsconfig.json");
390+
const tsconfigTypes = jsonc.parse(readFile(tsconfigPath)).compilerOptions
391+
?.types;
392+
if (workersTypes === "generated") {
393+
expect(tsconfigTypes).toContain(typesPath);
394+
}
395+
if (workersTypes === "installed") {
396+
expect(
397+
tsconfigTypes.some((x: string) =>
398+
x.includes("@cloudflare/workers-types"),
399+
),
400+
).toBe(true);
401+
}
402+
if (nodeCompat) {
403+
expect(tsconfigTypes).toContain(`node`);
404+
}
402405
};
403406

404407
const verifyBuildScript = async (

packages/create-cloudflare/e2e-tests/frameworks/framework-test-config-experimental.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default function getFrameworkTestConfigExperimental() {
2525
route: "/",
2626
expectedText: "Hello world",
2727
},
28+
nodeCompat: true,
2829
},
2930
};
3031
}

packages/create-cloudflare/e2e-tests/frameworks/framework-test-config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default function getFrameworkTestConfig(pm: string) {
1616
expectedText: "Hello from Cloudflare",
1717
previewArgs: ["--host=127.0.0.1"],
1818
},
19+
nodeCompat: false,
1920
flags: ["--no-install", "--no-git-init"],
2021
},
2122
"astro:pages": {
@@ -36,6 +37,7 @@ export default function getFrameworkTestConfig(pm: string) {
3637
route: "/test",
3738
expectedText: "C3_TEST",
3839
},
40+
nodeCompat: true,
3941
flags: [
4042
"--skip-houston",
4143
"--no-install",
@@ -64,6 +66,7 @@ export default function getFrameworkTestConfig(pm: string) {
6466
route: "/test",
6567
expectedText: "C3_TEST",
6668
},
69+
nodeCompat: true,
6770
flags: [
6871
"--skip-houston",
6972
"--no-install",
@@ -88,6 +91,7 @@ export default function getFrameworkTestConfig(pm: string) {
8891
route: "/",
8992
expectedText: "Dinosaurs are cool",
9093
},
94+
nodeCompat: false,
9195
flags: [`--package-manager`, pm],
9296
promptHandlers: [
9397
// {
@@ -114,6 +118,7 @@ export default function getFrameworkTestConfig(pm: string) {
114118
route: "/",
115119
expectedText: "Dinosaurs are cool",
116120
},
121+
nodeCompat: false,
117122
flags: [`--package-manager`, pm],
118123
promptHandlers: [
119124
{
@@ -144,6 +149,7 @@ export default function getFrameworkTestConfig(pm: string) {
144149
route: "/api/v1/test",
145150
expectedText: "C3_TEST",
146151
},
152+
nodeCompat: false,
147153
flags: ["--skipTailwind"],
148154
},
149155
"angular:pages": {
@@ -160,6 +166,7 @@ export default function getFrameworkTestConfig(pm: string) {
160166
route: "/",
161167
expectedText: "Congratulations! Your app is running.",
162168
},
169+
nodeCompat: false,
163170
flags: ["--style", "sass"],
164171
},
165172
"angular:workers": {
@@ -176,6 +183,7 @@ export default function getFrameworkTestConfig(pm: string) {
176183
route: "/",
177184
expectedText: "Congratulations! Your app is running.",
178185
},
186+
nodeCompat: false,
179187
flags: ["--style", "sass"],
180188
},
181189
"gatsby:pages": {
@@ -197,6 +205,7 @@ export default function getFrameworkTestConfig(pm: string) {
197205
route: "/",
198206
expectedText: "Gatsby!",
199207
},
208+
nodeCompat: false,
200209
},
201210
"gatsby:workers": {
202211
argv: ["--platform", "workers"],
@@ -217,6 +226,7 @@ export default function getFrameworkTestConfig(pm: string) {
217226
route: "/",
218227
expectedText: "Gatsby!",
219228
},
229+
nodeCompat: false,
220230
},
221231
"hono:pages": {
222232
argv: ["--platform", "pages"],
@@ -230,6 +240,7 @@ export default function getFrameworkTestConfig(pm: string) {
230240
route: "/",
231241
expectedText: "Hello!",
232242
},
243+
nodeCompat: false,
233244
promptHandlers: [
234245
{
235246
matcher: /Do you want to install project dependencies\?/,
@@ -249,6 +260,7 @@ export default function getFrameworkTestConfig(pm: string) {
249260
route: "/message",
250261
expectedText: "Hello Hono!",
251262
},
263+
nodeCompat: false,
252264
promptHandlers: [
253265
{
254266
matcher: /Do you want to install project dependencies\?/,
@@ -275,6 +287,7 @@ export default function getFrameworkTestConfig(pm: string) {
275287
route: "/",
276288
expectedText: "Welcome to Qwik",
277289
},
290+
nodeCompat: true,
278291
},
279292
"qwik:workers": {
280293
argv: ["--platform", "workers"],
@@ -296,6 +309,7 @@ export default function getFrameworkTestConfig(pm: string) {
296309
route: "/",
297310
expectedText: "Welcome to Qwik",
298311
},
312+
nodeCompat: true,
299313
},
300314
"remix:pages": {
301315
argv: ["--platform", "pages"],
@@ -317,6 +331,7 @@ export default function getFrameworkTestConfig(pm: string) {
317331
route: "/test",
318332
expectedText: "C3_TEST",
319333
},
334+
nodeCompat: false,
320335
flags: ["--typescript", "--no-install", "--no-git-init"],
321336
},
322337
"remix:workers": {
@@ -333,6 +348,7 @@ export default function getFrameworkTestConfig(pm: string) {
333348
route: "/test",
334349
expectedText: "C3_TEST",
335350
},
351+
nodeCompat: false,
336352
flags: ["--typescript", "--no-install", "--no-git-init"],
337353
},
338354
"next:pages": {
@@ -356,6 +372,7 @@ export default function getFrameworkTestConfig(pm: string) {
356372
route: "/",
357373
expectedText: "Create Next App",
358374
},
375+
nodeCompat: true,
359376
flags: [
360377
"--typescript",
361378
"--no-install",
@@ -391,6 +408,7 @@ export default function getFrameworkTestConfig(pm: string) {
391408
route: "/",
392409
expectedText: "Create Next App",
393410
},
411+
nodeCompat: true,
394412
// see https://github.com/cloudflare/next-on-pages/blob/main/packages/next-on-pages/docs/supported.md#operating-systems
395413
unsupportedOSs: ["win32"],
396414
unsupportedPms: [
@@ -415,6 +433,7 @@ export default function getFrameworkTestConfig(pm: string) {
415433
route: "/",
416434
expectedText: "Welcome to Nuxt!",
417435
},
436+
nodeCompat: false,
418437
verifyPreview: {
419438
route: "/test",
420439
expectedText: "C3_TEST",
@@ -446,6 +465,7 @@ export default function getFrameworkTestConfig(pm: string) {
446465
route: "/test",
447466
expectedText: "C3_TEST",
448467
},
468+
nodeCompat: false,
449469
},
450470
"react:pages": {
451471
argv: ["--platform", "pages"],
@@ -466,6 +486,7 @@ export default function getFrameworkTestConfig(pm: string) {
466486
route: "/",
467487
expectedText: "Vite + React",
468488
},
489+
nodeCompat: false,
469490
},
470491
"react:workers": {
471492
argv: ["--platform", "workers"],
@@ -494,6 +515,7 @@ export default function getFrameworkTestConfig(pm: string) {
494515
// not actually running the client side JS.
495516
expectedText: "Vite + React + TS",
496517
},
518+
nodeCompat: false,
497519
},
498520
solid: {
499521
promptHandlers: [
@@ -518,6 +540,7 @@ export default function getFrameworkTestConfig(pm: string) {
518540
route: "/",
519541
expectedText: "Hello world",
520542
},
543+
nodeCompat: true,
521544
},
522545
"svelte:pages": {
523546
argv: ["--platform", "pages"],
@@ -546,6 +569,7 @@ export default function getFrameworkTestConfig(pm: string) {
546569
route: "/test",
547570
expectedText: "C3_TEST",
548571
},
572+
nodeCompat: false,
549573
},
550574
"svelte:workers": {
551575
argv: ["--platform", "workers"],
@@ -568,6 +592,7 @@ export default function getFrameworkTestConfig(pm: string) {
568592
route: "/test",
569593
expectedText: "C3_TEST",
570594
},
595+
nodeCompat: false,
571596
},
572597
"vue:pages": {
573598
argv: ["--platform", "pages"],
@@ -581,6 +606,7 @@ export default function getFrameworkTestConfig(pm: string) {
581606
route: "/",
582607
expectedText: "Vite App",
583608
},
609+
nodeCompat: false,
584610
flags: ["--ts"],
585611
},
586612
"vue:workers": {
@@ -596,6 +622,7 @@ export default function getFrameworkTestConfig(pm: string) {
596622
route: "/",
597623
expectedText: "Vite App",
598624
},
625+
nodeCompat: false,
599626
},
600627
};
601628
}

packages/create-cloudflare/src/__tests__/workers.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe("updateTsConfig", () => {
3838
test("installing workers types", async () => {
3939
ctx.template.workersTypes = "installed";
4040

41-
await updateTsConfig(ctx, false);
41+
await updateTsConfig(ctx, { usesNodeCompat: false });
4242

4343
expect(writeFile).toHaveBeenCalled();
4444

@@ -49,15 +49,15 @@ describe("updateTsConfig", () => {
4949

5050
test("tsconfig.json not found", async () => {
5151
vi.mocked(existsSync).mockImplementation(() => false);
52-
await updateTsConfig(ctx, false);
52+
await updateTsConfig(ctx, { usesNodeCompat: false });
5353
expect(writeFile).not.toHaveBeenCalled();
5454
});
5555

5656
test("latest entrypoint not found", async () => {
5757
ctx.template.workersTypes = "installed";
5858

5959
vi.mocked(getLatestTypesEntrypoint).mockReturnValue(null);
60-
await updateTsConfig(ctx, false);
60+
await updateTsConfig(ctx, { usesNodeCompat: false });
6161

6262
expect(writeFile).not.toHaveBeenCalled();
6363
});
@@ -68,7 +68,7 @@ describe("updateTsConfig", () => {
6868
() =>
6969
`{ "compilerOptions": { "types" : ["@cloudflare/workers-types/2021-03-20"]} }`,
7070
);
71-
await updateTsConfig(ctx, false);
71+
await updateTsConfig(ctx, { usesNodeCompat: false });
7272

7373
expect(vi.mocked(writeFile).mock.calls[0][1]).toContain(
7474
`"@cloudflare/workers-types/2021-03-20"`,
@@ -83,7 +83,7 @@ describe("updateTsConfig", () => {
8383
return "// Runtime types generated with workerd";
8484
}
8585
});
86-
await updateTsConfig(ctx, false);
86+
await updateTsConfig(ctx, { usesNodeCompat: false });
8787
expect(vi.mocked(writeFile).mock.calls[0][1]).not.toContain(
8888
`"@cloudflare/workers-types/2021-03-20"`,
8989
);
@@ -97,15 +97,15 @@ describe("updateTsConfig", () => {
9797
return "no runtime types here";
9898
}
9999
});
100-
await updateTsConfig(ctx, false);
100+
await updateTsConfig(ctx, { usesNodeCompat: false });
101101

102102
expect(vi.mocked(writeFile).mock.calls[0][1]).toContain(
103103
`"@cloudflare/workers-types/2021-03-20"`,
104104
);
105105
});
106106

107107
test("will add generated types file", async () => {
108-
await updateTsConfig(ctx, false);
108+
await updateTsConfig(ctx, { usesNodeCompat: false });
109109
expect(vi.mocked(writeFile).mock.calls[0][1]).toContain(
110110
`./worker-configuration.d.ts`,
111111
);

0 commit comments

Comments
 (0)