Skip to content

Commit

Permalink
No-c3-framework-deploy-tests (#6216)
Browse files Browse the repository at this point in the history
* add to known spell check words

* add preview script to docusaurus

* refactor C3 e2e tests

* C3: don't overwrite the template's wrangler.toml in e2e tests

* test: run C3 e2e tests locally without having to deploy to cloudflare

This still tests that the frameworks are generated, compile and can be run locally;
while avoiding the time-const, flakiness, and denial of external contributors from running the tests.

* fix up C3 e2e preview test for next experimental

* uncomment PNPM cache directory

* remove unnecessary console.log()
  • Loading branch information
petebacondarwin authored Oct 1, 2024
1 parent ce7db9d commit 5f8c584
Show file tree
Hide file tree
Showing 16 changed files with 390 additions and 278 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"cSpell.words": [
"Abortable",
"assetsignore",
"astro",
"cf-typegen",
"cfetch",
"chatgpt",
"clipboardy",
Expand All @@ -15,6 +17,7 @@
"filestat",
"haikunate",
"haikunator",
"Hono",
"httplogs",
"iarna",
"isolinear",
Expand All @@ -27,6 +30,7 @@
"mrbbot",
"mtls",
"nodeless",
"Nuxt",
"outdir",
"outfile",
"pgrep",
Expand Down
110 changes: 43 additions & 67 deletions packages/create-cloudflare/e2e-tests/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,42 @@
import { existsSync, mkdtempSync, realpathSync, rmSync } from "fs";
import { tmpdir } from "os";
import { join } from "path";
import {
afterEach,
beforeAll,
beforeEach,
describe,
expect,
test,
} from "vitest";
import { beforeAll, describe, expect } from "vitest";
import { version } from "../package.json";
import { getFrameworkToTest } from "./frameworkToTest";
import {
createTestLogStream,
isQuarantineMode,
keys,
recreateLogFolder,
runC3,
test,
} from "./helpers";
import type { WriteStream } from "fs";
import type { Suite } from "vitest";

const experimental = Boolean(process.env.E2E_EXPERIMENTAL);
const frameworkToTest = getFrameworkToTest({ experimental: false });

// Note: skipIf(frameworkToTest) makes it so that all the basic C3 functionality
// tests are skipped in case we are testing a specific framework
describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
"E2E: Basic C3 functionality ",
() => {
const tmpDirPath = realpathSync(mkdtempSync(join(tmpdir(), "c3-tests")));
const projectPath = join(tmpDirPath, "basic-tests");
let logStream: WriteStream;

describe
.skipIf(experimental || frameworkToTest || isQuarantineMode())
.concurrent("E2E: Basic C3 functionality ", () => {
beforeAll((ctx) => {
recreateLogFolder({ experimental }, ctx as Suite);
});

beforeEach((ctx) => {
rmSync(projectPath, { recursive: true, force: true });
logStream = createTestLogStream({ experimental }, ctx);
});

afterEach(() => {
if (existsSync(projectPath)) {
rmSync(projectPath, { recursive: true });
}
});

test("--version", async () => {
test({ experimental })("--version", async ({ logStream }) => {
const { output } = await runC3(["--version"], [], logStream);
expect(output).toEqual(version);
});

test("--version with positionals", async () => {
const argv = ["foo", "bar", "baz", "--version"];
const { output } = await runC3(argv, [], logStream);
expect(output).toEqual(version);
});
test({ experimental })(
"--version with positionals",
async ({ logStream }) => {
const argv = ["foo", "bar", "baz", "--version"];
const { output } = await runC3(argv, [], logStream);
expect(output).toEqual(version);
},
);

test("--version with flags", async () => {
test({ experimental })("--version with flags", async ({ logStream }) => {
const argv = [
"foo",
"--type",
Expand All @@ -71,11 +48,11 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
expect(output).toEqual(version);
});

test.skipIf(process.platform === "win32")(
test({ experimental }).skipIf(process.platform === "win32")(
"Using arrow keys + enter",
async () => {
async ({ logStream, project }) => {
const { output } = await runC3(
[projectPath],
[project.path],
[
{
matcher: /What would you like to start with\?/,
Expand All @@ -101,7 +78,7 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
logStream,
);

expect(projectPath).toExist();
expect(project.path).toExist();
expect(output).toContain(`category Hello World example`);
expect(output).toContain(`type Hello World Worker`);
expect(output).toContain(`lang TypeScript`);
Expand All @@ -110,16 +87,16 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
},
);

test.skipIf(process.platform === "win32")(
test({ experimental }).skipIf(process.platform === "win32")(
"Typing custom responses",
async () => {
async ({ logStream, project }) => {
const { output } = await runC3(
[],
[
{
matcher:
/In which directory do you want to create your application/,
input: [projectPath, keys.enter],
input: [project.path, keys.enter],
},
{
matcher: /What would you like to start with\?/,
Expand All @@ -145,19 +122,19 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
logStream,
);

expect(projectPath).toExist();
expect(project.path).toExist();
expect(output).toContain(`type Scheduled Worker (Cron Trigger)`);
expect(output).toContain(`lang JavaScript`);
expect(output).toContain(`no git`);
expect(output).toContain(`no deploy`);
},
);

test.skipIf(process.platform === "win32")(
test({ experimental }).skipIf(process.platform === "win32")(
"Mixed args and interactive",
async () => {
async ({ logStream, project }) => {
const { output } = await runC3(
[projectPath, "--ts", "--no-deploy"],
[project.path, "--ts", "--no-deploy"],
[
{
matcher: /What would you like to start with\?/,
Expand All @@ -175,20 +152,20 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
logStream,
);

expect(projectPath).toExist();
expect(project.path).toExist();
expect(output).toContain(`type Hello World Worker`);
expect(output).toContain(`lang TypeScript`);
expect(output).toContain(`no git`);
expect(output).toContain(`no deploy`);
},
);

test.skipIf(process.platform === "win32")(
test({ experimental }).skipIf(process.platform === "win32")(
"Cloning remote template with full GitHub URL",
async () => {
async ({ logStream, project }) => {
const { output } = await runC3(
[
projectPath,
project.path,
"--template=https://github.com/cloudflare/templates/worker-router",
"--no-deploy",
"--git=false",
Expand All @@ -207,13 +184,13 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
},
);

test.skipIf(process.platform === "win32")(
test({ experimental }).skipIf(process.platform === "win32")(
"Inferring the category, type and language if the type is `hello-world-python`",
async () => {
async ({ logStream, project }) => {
// The `hello-world-python` template is now the python variant of the `hello-world` template
const { output } = await runC3(
[
projectPath,
project.path,
"--type=hello-world-python",
"--no-deploy",
"--git=false",
Expand All @@ -222,18 +199,18 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
logStream,
);

expect(projectPath).toExist();
expect(project.path).toExist();
expect(output).toContain(`category Hello World example`);
expect(output).toContain(`type Hello World Worker`);
expect(output).toContain(`lang Python`);
},
);

test.skipIf(process.platform === "win32")(
test({ experimental }).skipIf(process.platform === "win32")(
"Selecting template by description",
async () => {
async ({ logStream, project }) => {
const { output } = await runC3(
[projectPath, "--no-deploy", "--git=false"],
[project.path, "--no-deploy", "--git=false"],
[
{
matcher: /What would you like to start with\?/,
Expand All @@ -257,17 +234,17 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
logStream,
);

expect(projectPath).toExist();
expect(project.path).toExist();
expect(output).toContain(`category Application Starter`);
expect(output).toContain(`type API starter (OpenAPI compliant)`);
},
);

test.skipIf(process.platform === "win32")(
test({ experimental }).skipIf(process.platform === "win32")(
"Going back and forth between the category, type, framework and lang prompts",
async () => {
async ({ logStream, project }) => {
const { output } = await runC3(
[projectPath, "--git=false", "--no-deploy"],
[project.path, "--git=false", "--no-deploy"],
[
{
matcher: /What would you like to start with\?/,
Expand Down Expand Up @@ -355,10 +332,9 @@ describe.skipIf(experimental || frameworkToTest || isQuarantineMode())(
logStream,
);

expect(projectPath).toExist();
expect(project.path).toExist();
expect(output).toContain(`type Hello World Worker`);
expect(output).toContain(`lang JavaScript`);
},
);
},
);
});

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export const onGet: RequestHandler = async ({ platform, json }) => {
return;
}

json(200, { value: platform.env["TEST"], success: true });
json(200, { value: (platform.env as any)["TEST"], success: true });
};

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 5f8c584

Please sign in to comment.