From f2a80088867ffe335c9072f1d7911b9332f150cc Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 16 Sep 2024 21:23:24 +0100 Subject: [PATCH 1/2] granular c3 caching --- .github/actions/run-c3-e2e/action.yml | 2 +- package.json | 22 +++++------ .../e2e-tests/definitions.ts | 20 ++++++++++ .../e2e-tests/frameworks.test.ts | 31 +++++++-------- tools/e2e/runIndividualE2ETests.ts | 38 +++++++++++++++++++ 5 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 packages/create-cloudflare/e2e-tests/definitions.ts create mode 100644 tools/e2e/runIndividualE2ETests.ts diff --git a/.github/actions/run-c3-e2e/action.yml b/.github/actions/run-c3-e2e/action.yml index 39901629bdf3..a2a16c1d3265 100644 --- a/.github/actions/run-c3-e2e/action.yml +++ b/.github/actions/run-c3-e2e/action.yml @@ -49,7 +49,7 @@ runs: - name: E2E Tests id: run-e2e shell: bash - run: pnpm run test:e2e --filter create-cloudflare + run: pnpm run test:e2e:create-cloudflare env: CLOUDFLARE_API_TOKEN: ${{ inputs.apiToken }} CLOUDFLARE_ACCOUNT_ID: ${{ inputs.accountId }} diff --git a/package.json b/package.json index 3cc736d1ed6d..d092b96675cc 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,7 @@ "author": "wrangler@cloudflare.com", "scripts": { "build": "dotenv -- turbo build", - "check": "pnpm check:fixtures && pnpm check:deployments && node lint-turbo.mjs && dotenv -- turbo check:lint check:type check:format type:tests", - "check:deployments": "node -r esbuild-register tools/deployments/deploy-non-npm-packages.ts check", + "check": "pnpm check:fixtures && node lint-turbo.mjs && dotenv -- turbo check:lint check:type check:format type:tests", "check:fixtures": "node -r esbuild-register tools/deployments/ensure-fixtures-are-not-deployable.ts", "check:format": "prettier . --check --ignore-unknown", "check:lint": "dotenv -- turbo check:lint", @@ -24,6 +23,7 @@ "test": "vitest run --no-file-parallelism && dotenv -- turbo test --filter=wrangler --filter=miniflare --filter=kv-asset-handler --filter=@cloudflare/vitest-pool-workers --filter=@cloudflare/vitest-pool-workers-examples", "test:ci": "dotenv -- turbo test:ci", "test:e2e": "dotenv -- turbo test:e2e", + "test:e2e:create-cloudflare": "node -r esbuild-register tools/e2e/runIndividualE2ETests.ts", "test:e2e:wrangler": "node -r esbuild-register tools/e2e/runIndividualE2EFiles.ts", "test:watch": "turbo test:watch", "type:tests": "dotenv -- turbo type:tests" @@ -33,7 +33,7 @@ "@changesets/changelog-github": "^0.5.0", "@changesets/cli": "^2.27.1", "@changesets/parse": "^0.4.0", - "@cloudflare/workers-types": "^4.20240909.0", + "@cloudflare/workers-types": "^4.20240620.0", "@ianvs/prettier-plugin-sort-imports": "4.2.1", "@manypkg/cli": "^0.21.4", "@turbo/gen": "^1.10.13", @@ -47,20 +47,18 @@ "prettier": "^3.2.5", "prettier-plugin-packagejson": "^2.2.18", "rimraf": "^5.0.1", - "tree-kill": "^1.2.2", "turbo": "^1.10.14", "typescript": "^5.5.2", "vite": "^5.0.12", - "vitest": "catalog:default" + "vitest": "^1.2.2" }, - "packageManager": "pnpm@9.10.0", + "packageManager": "pnpm@9.1.3", "engines": { "node": ">=18.20.0", - "pnpm": "^9.10.0" + "pnpm": "^9.1.3" }, "volta": { - "node": "18.20.2", - "pnpm": "9.10.0" + "node": "18.20.2" }, "pnpm": { "peerDependencyRules": { @@ -76,15 +74,13 @@ "@types/react-tabs>@types/react": "^18", "@types/react-transition-group>@types/react": "^18", "@cloudflare/elements>@types/react": "^18", - "capnpc-ts>typescript": "4.2.4", - "vitest>@types/node": "$@types/node" + "capnpc-ts>typescript": "5.5.2" }, "patchedDependencies": { "ink@3.2.0": "patches/ink@3.2.0.patch", "@cloudflare/component-listbox@1.10.6": "patches/@cloudflare__component-listbox@1.10.6.patch", "capnp-ts@0.7.0": "patches/capnp-ts@0.7.0.patch", - "pg@8.11.3": "patches/pg@8.11.3.patch", - "toucan-js@3.3.1": "patches/toucan-js@3.3.1.patch" + "pg@8.11.3": "patches/pg@8.11.3.patch" } } } diff --git a/packages/create-cloudflare/e2e-tests/definitions.ts b/packages/create-cloudflare/e2e-tests/definitions.ts new file mode 100644 index 000000000000..1237b4c5004f --- /dev/null +++ b/packages/create-cloudflare/e2e-tests/definitions.ts @@ -0,0 +1,20 @@ +export const frameworks = [ + "astro", + "docusaurus", + "analog", + "angular", + "gatsby", + "hono", + "qwik", + "remix", + "next", + "nuxt", + "react", + "solid", + "svelte", + "vue", +] as const; +type Framework = (typeof frameworks)[number]; +export const frameworkMap = Object.fromEntries( + frameworks.map((f) => [f, f]), +) as Record; diff --git a/packages/create-cloudflare/e2e-tests/frameworks.test.ts b/packages/create-cloudflare/e2e-tests/frameworks.test.ts index 46c1e854dde7..7b2c6cf8919c 100644 --- a/packages/create-cloudflare/e2e-tests/frameworks.test.ts +++ b/packages/create-cloudflare/e2e-tests/frameworks.test.ts @@ -17,6 +17,7 @@ import { } from "vitest"; import { deleteProject, deleteWorker } from "../scripts/common"; import { getFrameworkMap } from "../src/templates"; +import { frameworkMap } from "./definitions"; import { getFrameworkToTest } from "./frameworkToTest"; import { createTestLogStream, @@ -68,8 +69,8 @@ type FrameworkTestConfig = RunnerConfig & { const { name: pm, npx } = detectPackageManager(); // These are ordered based on speed and reliability for ease of debugging -const frameworkTests: Record = { - astro: { +export const frameworkTests: Record = { + [frameworkMap.astro]: { testCommitMessage: true, quarantine: true, unsupportedOSs: ["win32"], @@ -97,7 +98,7 @@ const frameworkTests: Record = { "strict", ], }, - docusaurus: { + [frameworkMap.docusaurus]: { unsupportedPms: ["bun"], testCommitMessage: true, unsupportedOSs: ["win32"], @@ -114,7 +115,7 @@ const frameworkTests: Record = { }, ], }, - analog: { + [frameworkMap.analog]: { testCommitMessage: true, timeout: LONG_TIMEOUT, unsupportedOSs: ["win32"], @@ -142,7 +143,7 @@ const frameworkTests: Record = { flags: ["--skipTailwind"], quarantine: true, }, - angular: { + [frameworkMap.angular]: { testCommitMessage: true, timeout: LONG_TIMEOUT, unsupportedOSs: ["win32"], @@ -152,7 +153,7 @@ const frameworkTests: Record = { }, flags: ["--style", "sass"], }, - gatsby: { + [frameworkMap.gatsby]: { unsupportedPms: ["bun", "pnpm"], promptHandlers: [ { @@ -167,7 +168,7 @@ const frameworkTests: Record = { expectedText: "Gatsby!", }, }, - hono: { + [frameworkMap.hono]: { testCommitMessage: false, unsupportedOSs: ["win32"], verifyDeploy: { @@ -181,7 +182,7 @@ const frameworkTests: Record = { }, ], }, - qwik: { + [frameworkMap.qwik]: { promptHandlers: [ { matcher: /Yes looks good, finish update/, @@ -210,7 +211,7 @@ const frameworkTests: Record = { expectedText: "C3_TEST", }, }, - remix: { + [frameworkMap.remix]: { testCommitMessage: true, timeout: LONG_TIMEOUT, unsupportedPms: ["yarn"], @@ -235,7 +236,7 @@ const frameworkTests: Record = { }, flags: ["--typescript", "--no-install", "--no-git-init"], }, - next: { + [frameworkMap.next]: { promptHandlers: [ { matcher: /Do you want to use the next-on-pages eslint-plugin\?/, @@ -263,7 +264,7 @@ const frameworkTests: Record = { "@/*", ], }, - nuxt: { + [frameworkMap.nuxt]: { testCommitMessage: true, timeout: LONG_TIMEOUT, unsupportedOSs: ["win32"], @@ -286,7 +287,7 @@ const frameworkTests: Record = { expectedText: "C3_TEST", }, }, - react: { + [frameworkMap.react]: { promptHandlers: [ { matcher: /Select a variant:/, @@ -302,7 +303,7 @@ const frameworkTests: Record = { expectedText: "Vite + React", }, }, - solid: { + [frameworkMap.solid]: { promptHandlers: [ { matcher: /Which template would you like to use/, @@ -322,7 +323,7 @@ const frameworkTests: Record = { expectedText: "Hello world", }, }, - svelte: { + [frameworkMap.svelte]: { promptHandlers: [ { matcher: /Which Svelte app template/, @@ -355,7 +356,7 @@ const frameworkTests: Record = { expectedText: "C3_TEST", }, }, - vue: { + [frameworkMap.vue]: { testCommitMessage: true, unsupportedOSs: ["win32"], verifyDeploy: { diff --git a/tools/e2e/runIndividualE2ETests.ts b/tools/e2e/runIndividualE2ETests.ts new file mode 100644 index 000000000000..8aaa831c9bf0 --- /dev/null +++ b/tools/e2e/runIndividualE2ETests.ts @@ -0,0 +1,38 @@ +/** + * Turbo only supports caching on the individual task level, but for C3's + * e2e tests we want to support caching on a more granular basis—at the file level & test level. + * + * As such, we run the `test:e2e` turbo task multiple times—once per e2e test file, and once per framework test + * with different arguments, ensuring that each file's tests can be cached individually. + * + * The intended flow here is that CI will run this file, which will trigger turbo to run + * an individual task for each C3 e2e test file & test, using `execSync`. + */ +import { execSync } from "child_process"; +import { readdirSync } from "fs"; +import { frameworks } from "../../packages/create-cloudflare/e2e-tests/definitions"; + +// Get a list of e2e test files, each of which should have an associated script +const e2eTests = readdirSync("packages/create-cloudflare/e2e-tests"); + +const tasks = new Set(); + +for (const file of e2eTests) { + if (file === "frameworks.test.ts") { + for (const framework of frameworks) { + tasks.add( + `pnpm test:e2e --log-order=stream --summarize --filter create-cloudflare --concurrency 1 -- run ./e2e-tests/${file} -t ${framework}` + ); + } + } else if (file.endsWith(".test.ts")) { + tasks.add( + `pnpm test:e2e --log-order=stream --summarize --filter create-cloudflare --concurrency 1 -- run ./e2e-tests/${file}` + ); + } +} + +for (const task of tasks.values()) { + execSync(task, { + stdio: "inherit", + }); +} From dd685f499556f8eac736c0cf39ffd93e09133ca3 Mon Sep 17 00:00:00 2001 From: Samuel Macleod Date: Mon, 16 Sep 2024 21:29:46 +0100 Subject: [PATCH 2/2] oops --- package.json | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index d092b96675cc..9d712d995bcf 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "author": "wrangler@cloudflare.com", "scripts": { "build": "dotenv -- turbo build", - "check": "pnpm check:fixtures && node lint-turbo.mjs && dotenv -- turbo check:lint check:type check:format type:tests", + "check": "pnpm check:fixtures && pnpm check:deployments && node lint-turbo.mjs && dotenv -- turbo check:lint check:type check:format type:tests", + "check:deployments": "node -r esbuild-register tools/deployments/deploy-non-npm-packages.ts check", "check:fixtures": "node -r esbuild-register tools/deployments/ensure-fixtures-are-not-deployable.ts", "check:format": "prettier . --check --ignore-unknown", "check:lint": "dotenv -- turbo check:lint", @@ -33,7 +34,7 @@ "@changesets/changelog-github": "^0.5.0", "@changesets/cli": "^2.27.1", "@changesets/parse": "^0.4.0", - "@cloudflare/workers-types": "^4.20240620.0", + "@cloudflare/workers-types": "^4.20240909.0", "@ianvs/prettier-plugin-sort-imports": "4.2.1", "@manypkg/cli": "^0.21.4", "@turbo/gen": "^1.10.13", @@ -47,18 +48,20 @@ "prettier": "^3.2.5", "prettier-plugin-packagejson": "^2.2.18", "rimraf": "^5.0.1", + "tree-kill": "^1.2.2", "turbo": "^1.10.14", "typescript": "^5.5.2", "vite": "^5.0.12", - "vitest": "^1.2.2" + "vitest": "catalog:default" }, - "packageManager": "pnpm@9.1.3", + "packageManager": "pnpm@9.10.0", "engines": { "node": ">=18.20.0", - "pnpm": "^9.1.3" + "pnpm": "^9.10.0" }, "volta": { - "node": "18.20.2" + "node": "18.20.2", + "pnpm": "9.10.0" }, "pnpm": { "peerDependencyRules": { @@ -74,13 +77,15 @@ "@types/react-tabs>@types/react": "^18", "@types/react-transition-group>@types/react": "^18", "@cloudflare/elements>@types/react": "^18", - "capnpc-ts>typescript": "5.5.2" + "capnpc-ts>typescript": "4.2.4", + "vitest>@types/node": "$@types/node" }, "patchedDependencies": { "ink@3.2.0": "patches/ink@3.2.0.patch", "@cloudflare/component-listbox@1.10.6": "patches/@cloudflare__component-listbox@1.10.6.patch", "capnp-ts@0.7.0": "patches/capnp-ts@0.7.0.patch", - "pg@8.11.3": "patches/pg@8.11.3.patch" + "pg@8.11.3": "patches/pg@8.11.3.patch", + "toucan-js@3.3.1": "patches/toucan-js@3.3.1.patch" } } }