Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/angry-parents-post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-cloudflare": patch
---

Graduate Workers + Assets hello world templates from experimental status
24 changes: 10 additions & 14 deletions packages/create-cloudflare/e2e-tests/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
);

expect(project.path).toExist();
expect(output).toContain(`category Hello World example`);
expect(output).toContain(`type Hello World Worker`);
expect(output).toContain(`category Hello World Starter`);
expect(output).toContain(`type Worker + Assets`);
expect(output).toContain(`lang TypeScript`);
expect(output).toContain(`no git`);
expect(output).toContain(`no deploy`);
},
);
Expand Down Expand Up @@ -128,7 +127,6 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
expect(project.path).toExist();
expect(output).toContain(`type Scheduled Worker (Cron Trigger)`);
expect(output).toContain(`lang JavaScript`);
expect(output).toContain(`no git`);
Copy link
Contributor Author

@emily-shen emily-shen Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this is failing now - I would've expected this to start failing after #8290. This question definitely isn't there if you pass in --no-git on c3 latest, so it's not a result of this PR. Were the tests just cached all that time? 😬

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps because these tests were skipped in experimental mode?

describe.skipIf(experimental || ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the no git thing applies regardless of whether experimental, so they should have have been failing in the experimental:false runs too 🤔

expect(output).toContain(`no deploy`);
},
);
Expand Down Expand Up @@ -179,9 +177,8 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
);

expect(project.path).toExist();
expect(output).toContain(`type Hello World Worker`);
expect(output).toContain(`type Worker + Assets`);
expect(output).toContain(`lang TypeScript`);
expect(output).toContain(`no git`);
expect(output).toContain(`no deploy`);
} finally {
fs.rmSync(existingFilePath, {
Expand Down Expand Up @@ -272,8 +269,8 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
);

expect(project.path).toExist();
expect(output).toContain(`category Hello World example`);
expect(output).toContain(`type Hello World Worker`);
expect(output).toContain(`category Hello World Starter`);
expect(output).toContain(`type Worker only`);
expect(output).toContain(`lang Python`);
},
);
Expand Down Expand Up @@ -379,15 +376,15 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
matcher: /What would you like to start with\?/,
input: {
type: "select",
target: "Hello World example",
target: "Hello World Starter",
assertDefaultSelection: "Framework Starter",
},
},
{
matcher: /Which template would you like to use\?/,
input: {
type: "select",
target: "Hello World Worker Using Durable Objects",
target: "Worker + Durable Objects",
},
},
{
Expand All @@ -401,9 +398,8 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
matcher: /Which template would you like to use\?/,
input: {
type: "select",
target: "Hello World Worker",
assertDefaultSelection:
"Hello World Worker Using Durable Objects",
target: "Worker only",
assertDefaultSelection: "Worker + Durable Objects",
},
},
{
Expand All @@ -418,7 +414,7 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
);

expect(project.path).toExist();
expect(output).toContain(`type Hello World Worker`);
expect(output).toContain(`type Worker only`);
expect(output).toContain(`lang JavaScript`);
},
);
Expand Down
57 changes: 29 additions & 28 deletions packages/create-cloudflare/e2e-tests/workers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,35 @@ type WorkerTestConfig = RunnerConfig & {

function getWorkerTests(opts: { experimental: boolean }): WorkerTestConfig[] {
if (opts.experimental) {
// none currently
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

return [];
} else {
return [
{
template: "hello-world",
variants: ["ts", "js"],
verifyDeploy: {
route: "/",
expectedText: "Hello World!",
},
verifyPreview: {
route: "/",
expectedText: "Hello World!",
},
verifyTest: true,
},
{
template: "hello-world",
variants: ["python"],
verifyDeploy: {
route: "/",
expectedText: "Hello World!",
},
verifyPreview: {
route: "/",
expectedText: "Hello World!",
},
},
{
template: "hello-world-with-assets",
variants: ["ts", "js"],
Expand Down Expand Up @@ -78,34 +106,6 @@ function getWorkerTests(opts: { experimental: boolean }): WorkerTestConfig[] {
verifyPreview: null,
argv: ["--category", "hello-world"],
},
];
} else {
return [
{
template: "hello-world",
variants: ["ts", "js"],
verifyDeploy: {
route: "/",
expectedText: "Hello World!",
},
verifyPreview: {
route: "/",
expectedText: "Hello World!",
},
verifyTest: true,
},
{
template: "hello-world",
variants: ["python"],
verifyDeploy: {
route: "/",
expectedText: "Hello World!",
},
verifyPreview: {
route: "/",
expectedText: "Hello World!",
},
},
{
template: "common",
variants: ["ts", "js"],
Expand Down Expand Up @@ -155,6 +155,7 @@ describe
.skipIf(
getFrameworkToTest({ experimental }) ||
isQuarantineMode() ||
workerTests.length === 0 ||
process.platform === "win32",
)
.concurrent(`E2E: Workers templates`, () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/create-cloudflare/src/helpers/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ export const cliDefinition: ArgumentsDefinition = {
const experimental = Boolean(args?.["experimental"]);
if (experimental) {
return [
{ name: "hello-world", description: "Hello World example" },
{ name: "hello-world", description: "Hello World Starter" },
{ name: "web-framework", description: "Framework Starter" },
];
} else {
return [
{ name: "hello-world", description: "Hello World example" },
{ name: "hello-world", description: "Hello World Starter" },
{ name: "web-framework", description: "Framework Starter" },
{ name: "demo", description: "Application Starter" },
{
Expand Down
6 changes: 3 additions & 3 deletions packages/create-cloudflare/src/helpers/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const isUpdateAvailable = async () => {
export const C3_DEFAULTS: C3Args = {
projectName: new Haikunator().haikunate({ tokenHex: true }),
category: "hello-world",
type: "hello-world",
type: "hello-world-with-assets",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the default to worker + assets

Is it weird for the default to be in the middle of the list? is this list too many options?
Screenshot 2025-03-06 at 15 15 43

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for me.

framework: "analog",
experimental: false,
autoUpdate: true,
Expand All @@ -57,11 +57,11 @@ export const C3_DEFAULTS: C3Args = {
open: true,
lang: "ts",
template:
"cloudflare/workers-sdk/packages/create-cloudflare/templates/hello-world",
"cloudflare/workers-sdk/packages/create-cloudflare/templates/hello-world-with-assets",
};

export const WRANGLER_DEFAULTS = {
...C3_DEFAULTS,
type: "hello-world",
type: "hello-world-with-assets",
deploy: false,
};
28 changes: 14 additions & 14 deletions packages/create-cloudflare/src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ import {
writeJSON,
} from "helpers/files";
import astroTemplateExperimental from "templates-experimental/astro/c3";
import assetsOnlyTemplateExperimental from "templates-experimental/hello-world-assets-only/c3";
import helloWorldWithDurableObjectAssetsTemplateExperimental from "templates-experimental/hello-world-durable-object-with-assets/c3";
import helloWorldWithAssetsTemplateExperimental from "templates-experimental/hello-world-with-assets/c3";
import honoTemplateExperimental from "templates-experimental/hono/c3";
import nextTemplateExperimental from "templates-experimental/next/c3";
import qwikTemplateExperimental from "templates-experimental/qwik/c3";
Expand All @@ -34,8 +31,11 @@ import astroTemplate from "templates/astro/c3";
import commonTemplate from "templates/common/c3";
import docusaurusTemplate from "templates/docusaurus/c3";
import gatsbyTemplate from "templates/gatsby/c3";
import assetsOnlyTemplate from "templates/hello-world-assets-only/c3";
import helloWorldWithDurableObjectAssetsTemplate from "templates/hello-world-durable-object-with-assets/c3";
import helloWorldDurableObjectTemplate from "templates/hello-world-durable-object/c3";
import helloWorldTemplate from "templates/hello-world/c3";
import helloWorldWithAssetsTemplate from "templates/hello-world-with-assets/c3";
import helloWorldWorkerTemplate from "templates/hello-world/c3";
import honoTemplate from "templates/hono/c3";
import nextTemplate from "templates/next/c3";
import nuxtTemplate from "templates/nuxt/c3";
Expand Down Expand Up @@ -206,19 +206,18 @@ export function getFrameworkMap({ experimental = false }): TemplateMap {

export function getTemplateMap({ experimental = false }) {
if (experimental) {
return {
"hello-world-assets-only": assetsOnlyTemplateExperimental,
"hello-world-with-assets": helloWorldWithAssetsTemplateExperimental,
"hello-world-durable-object-with-assets":
helloWorldWithDurableObjectAssetsTemplateExperimental,
} as Record<string, TemplateConfig>;
return {} as Record<string, TemplateConfig>;
} else {
return {
"hello-world": helloWorldTemplate,
"hello-world": helloWorldWorkerTemplate,
"hello-world-assets-only": assetsOnlyTemplate,
"hello-world-with-assets": helloWorldWithAssetsTemplate,
"hello-world-durable-object": helloWorldDurableObjectTemplate,
"hello-world-durable-object-with-assets":
helloWorldWithDurableObjectAssetsTemplate,
common: commonTemplate,
scheduled: scheduledTemplate,
queues: queuesTemplate,
"hello-world-durable-object": helloWorldDurableObjectTemplate,
openapi: openapiTemplate,
"pre-existing": preExistingTemplate,
} as Record<string, TemplateConfig>;
Expand Down Expand Up @@ -366,9 +365,10 @@ export const createContext = async (

const categoryOptions = [
{
label: "Hello World example",
label: "Hello World Starter",
value: "hello-world",
description: "Select from barebones examples to get started with Workers",
description:
"Select from basic scaffolds to get started with Workers, Assets and Durable Objects",
},
{
label: "Framework Starter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import type { TemplateConfig } from "../../src/templates";
const config: TemplateConfig = {
configVersion: 1,
id: "hello-world-assets-only",
path: "templates-experimental/hello-world-assets-only",
displayName: "Hello World - Assets-only",
description: "Get started with a basic Worker that only serves static assets",
path: "templates/hello-world-assets-only",
displayName: "Assets only",
description:
"For static sites (including SPAs) or when using your own backend",
platform: "workers",
copyFiles: {
path: "./templates",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { TemplateConfig } from "../../src/templates";
const config: TemplateConfig = {
configVersion: 1,
id: "hello-world-durable-object-with-assets",
path: "templates-experimental/hello-world-durable-object-with-assets",
displayName: "Hello World - Worker Using Durable Objects with Assets",
path: "templates/hello-world-durable-object-with-assets",
displayName: "Worker + Durable Objects + Assets",
description:
"Get started with a basic stateful app to build projects like real-time chats, collaborative apps, and multiplayer games, which hosts assets",
"For full-stack applications requiring static assets, an API, and real-time coordination",
platform: "workers",
copyFiles: {
variants: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default {
configVersion: 1,
id: "hello-world-durable-object",
displayName: "Hello World Worker Using Durable Objects",
displayName: "Worker + Durable Objects",
description:
"Get started with a basic stateful app to build projects like real-time chats, collaborative apps, and multiplayer games",
"For multiplayer apps using WebSockets, or when you need synchronization",
platform: "workers",
copyFiles: {
variants: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export default {
configVersion: 1,
id: "hello-world-with-assets",
path: "templates-experimental/hello-world-with-assets",
displayName: "Hello World - Worker with Assets",
description:
"Get started with a basic Worker that also serves static assets, in the language of your choice",
path: "templates/hello-world-with-assets",
displayName: "Worker + Assets",
description: "For static sites with an API or server-side rendering (SSR)",
platform: "workers",
copyFiles: {
variants: {
Expand Down
5 changes: 3 additions & 2 deletions packages/create-cloudflare/templates/hello-world/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import type { TemplateConfig } from "../../src/templates";
export default {
configVersion: 1,
id: "hello-world",
displayName: "Hello World Worker",
description: "Get started with a basic Worker in the language of your choice",
displayName: "Worker only",
description:
"For processing requests, transforming responses, or API endpoints",
platform: "workers",
async configure(ctx) {
if (ctx.args.lang === "python") {
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/e2e/c3-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ describe.runIf(process.platform !== "win32")("c3 integration", () => {
});
const { url } = await worker.waitForReady();
const res = await fetch(url);
expect(await res.text()).toBe("Hello World!");
expect(await res.text()).toContain("Hello, World!");
});
});
Loading