Skip to content

Commit

Permalink
Addressing PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jculvey committed Feb 6, 2024
1 parent 35a1a7e commit 0535c9e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[vars]
TEST = "C3_TEST"
TEST = "C3_TEST"
50 changes: 25 additions & 25 deletions packages/create-cloudflare/e2e-tests/frameworks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ type FrameworkTestConfig = RunnerConfig & {
unsupportedOSs?: string[];
verifyDev?: {
route: string;
expectedToken: string;
expectedText: string;
};
verifyBuild?: {
outputDir: string;
script: string;
route: string;
expectedToken: string;
expectedText: string;
};
};

Expand All @@ -58,7 +58,7 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
unsupportedOSs: ["win32"],
verifyDeploy: {
route: "/",
expectedToken: "Hello, Astronaut!",
expectedText: "Hello, Astronaut!",
},
},
docusaurus: {
Expand All @@ -68,15 +68,15 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
timeout: LONG_TIMEOUT,
verifyDeploy: {
route: "/",
expectedToken: "Dinosaurs are cool",
expectedText: "Dinosaurs are cool",
},
},
angular: {
testCommitMessage: true,
timeout: LONG_TIMEOUT,
verifyDeploy: {
route: "/",
expectedToken: "Congratulations! Your app is running.",
expectedText: "Congratulations! Your app is running.",
},
},
gatsby: {
Expand All @@ -91,14 +91,14 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
timeout: LONG_TIMEOUT,
verifyDeploy: {
route: "/",
expectedToken: "Gatsby!",
expectedText: "Gatsby!",
},
},
hono: {
testCommitMessage: false,
verifyDeploy: {
route: "/",
expectedToken: "Hello Hono!",
expectedText: "Hello Hono!",
},
},
qwik: {
Expand All @@ -113,17 +113,17 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
unsupportedPms: ["yarn"],
verifyDeploy: {
route: "/",
expectedToken: "Welcome to Qwik",
expectedText: "Welcome to Qwik",
},
verifyDev: {
route: "/test",
expectedToken: "C3_TEST",
expectedText: "C3_TEST",
},
verifyBuild: {
outputDir: "./dist",
script: "build",
route: "/test",
expectedToken: "C3_TEST",
expectedText: "C3_TEST",
},
},
remix: {
Expand All @@ -132,7 +132,7 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
unsupportedPms: ["yarn"],
verifyDeploy: {
route: "/",
expectedToken: "Welcome to Remix",
expectedText: "Welcome to Remix",
},
},
next: {
Expand All @@ -146,15 +146,15 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
quarantine: true,
verifyDeploy: {
route: "/",
expectedToken: "Create Next App",
expectedText: "Create Next App",
},
},
nuxt: {
testCommitMessage: true,
timeout: LONG_TIMEOUT,
verifyDeploy: {
route: "/",
expectedToken: "Welcome to Nuxt!",
expectedText: "Welcome to Nuxt!",
},
},
react: {
Expand All @@ -163,7 +163,7 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
timeout: LONG_TIMEOUT,
verifyDeploy: {
route: "/",
expectedToken: "React App",
expectedText: "React App",
},
},
solid: {
Expand All @@ -186,7 +186,7 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
unsupportedOSs: ["win32"],
verifyDeploy: {
route: "/",
expectedToken: "Hello world",
expectedText: "Hello world",
},
},
svelte: {
Expand All @@ -209,15 +209,15 @@ const frameworkTests: Record<string, FrameworkTestConfig> = {
unsupportedPms: ["npm"],
verifyDeploy: {
route: "/",
expectedToken: "SvelteKit app",
expectedText: "SvelteKit app",
},
},
vue: {
testCommitMessage: true,
unsupportedOSs: ["win32"],
verifyDeploy: {
route: "/",
expectedToken: "Vite App",
expectedText: "Vite App",
},
},
};
Expand Down Expand Up @@ -308,7 +308,7 @@ describe.concurrent(`E2E: Web frameworks`, () => {
// Make a request to the deployed project and verify it was successful
await verifyDeployment(
`${deploymentUrl}${verifyDeploy.route}`,
verifyDeploy.expectedToken
verifyDeploy.expectedText
);

// Copy over any test fixture files
Expand Down Expand Up @@ -372,15 +372,15 @@ const runCli = async (

const verifyDeployment = async (
deploymentUrl: string,
expectedToken: string
expectedText: string
) => {
await retry({ times: 5 }, async () => {
await new Promise((resolve) => setTimeout(resolve, 1000)); // wait a second
await sleep(1000);
const res = await fetch(deploymentUrl);
const body = await res.text();
if (!body.includes(expectedToken)) {
if (!body.includes(expectedText)) {
throw new Error(
`Deployed page (${deploymentUrl}) didn't contain expected string: "${expectedToken}"`
`Deployed page (${deploymentUrl}) didn't contain expected string: "${expectedText}"`
);
}
});
Expand Down Expand Up @@ -435,7 +435,7 @@ const verifyDevScript = async (
// end up camped and cause future runs to fail
await sleep(1000);

expect(body).toContain(verifyDev.expectedToken);
expect(body).toContain(verifyDev.expectedText);
};

const verifyBuildScript = async (
Expand All @@ -449,7 +449,7 @@ const verifyBuildScript = async (
return;
}

const { outputDir, script, route, expectedToken } = verifyBuild;
const { outputDir, script, route, expectedText } = verifyBuild;

// Run the build script
const { name: pm, npx } = detectPackageManager();
Expand Down Expand Up @@ -488,5 +488,5 @@ const verifyBuildScript = async (
await sleep(1000);

// Verify expectation after killing the process so that it exits cleanly in case of failure
expect(body).toContain(expectedToken);
expect(body).toContain(expectedText);
};
2 changes: 1 addition & 1 deletion packages/create-cloudflare/e2e-tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export type RunnerConfig = {
timeout?: number;
verifyDeploy?: {
route: string;
expectedToken: string;
expectedText: string;
};
};

Expand Down
11 changes: 6 additions & 5 deletions packages/create-cloudflare/e2e-tests/workers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { join } from "path";
import { retry } from "helpers/command";
import { sleep } from "helpers/common";
import { readToml } from "helpers/files";
import { fetch } from "undici";
import { beforeAll, beforeEach, describe, expect, test } from "vitest";
Expand Down Expand Up @@ -28,14 +29,14 @@ const workerTemplates: WorkerTestConfig[] = [
template: "hello-world",
verifyDeploy: {
route: "/",
expectedToken: "Hello World!",
expectedText: "Hello World!",
},
},
{
template: "common",
verifyDeploy: {
route: "/",
expectedToken: "Try making requests to:",
expectedText: "Try making requests to:",
},
},
{
Expand All @@ -51,7 +52,7 @@ const workerTemplates: WorkerTestConfig[] = [
promptHandlers: [],
verifyDeploy: {
route: "/",
expectedToken: "SwaggerUI",
expectedText: "SwaggerUI",
},
},
];
Expand Down Expand Up @@ -132,7 +133,7 @@ describe

const { verifyDeploy } = template;
if (verifyDeploy && deployedUrl) {
await verifyDeployment(deployedUrl, verifyDeploy.expectedToken);
await verifyDeployment(deployedUrl, verifyDeploy.expectedText);
}
} finally {
clean(name);
Expand Down Expand Up @@ -185,7 +186,7 @@ const verifyDeployment = async (
expectedString: string
) => {
await retry({ times: 5 }, async () => {
await new Promise((resolve) => setTimeout(resolve, 1000)); // wait a second
await sleep(1000);
const res = await fetch(deploymentUrl);
const body = await res.text();
if (!body.includes(expectedString)) {
Expand Down
22 changes: 13 additions & 9 deletions packages/create-cloudflare/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,34 +368,38 @@ const downloadRemoteTemplate = async (src: string) => {
};

export const updatePackageName = async (ctx: C3Context) => {
const s = spinner();
s.start("Updating name in `package.json`");

// Update package.json with project name
const placeholderNames = ["<TBD>", "TBD", ""];
const pkgJsonPath = resolve(ctx.project.path, "package.json");
const pkgJson = readJSON(pkgJsonPath);

if (placeholderNames.includes(pkgJson.name)) {
pkgJson.name = ctx.project.name;
if (!placeholderNames.includes(pkgJson.name)) {
return;
}

const s = spinner();
s.start("Updating name in `package.json`");

pkgJson.name = ctx.project.name;

writeJSON(pkgJsonPath, pkgJson);
s.stop(`${brandColor("updated")} ${dim("`package.json`")}`);
};

export const updatePackageScripts = async (ctx: C3Context) => {
if (!ctx.template.transformPackageJson) {
return;
}

const s = spinner();
s.start("Updating `package.json` scripts");

const pkgJsonPath = resolve(ctx.project.path, "package.json");
let pkgJson = readJSON(pkgJsonPath);

// Run any transformers defined by the template
if (ctx.template.transformPackageJson) {
const transformed = await ctx.template.transformPackageJson(pkgJson);
pkgJson = deepmerge(pkgJson, transformed);
}
const transformed = await ctx.template.transformPackageJson(pkgJson);
pkgJson = deepmerge(pkgJson, transformed);

writeJSON(pkgJsonPath, pkgJson);
s.stop(`${brandColor("updated")} ${dim("`package.json`")}`);
Expand Down

0 comments on commit 0535c9e

Please sign in to comment.