Skip to content

Commit

Permalink
Granular e2e caching (#6201)
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa committed Jul 5, 2024
1 parent 88313e5 commit c6c083f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
NODE_ENV: "production"

- name: Run tests
run: pnpm run test:e2e --filter=wrangler
run: pnpm run test:e2e:wrangler
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.TEST_CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }}
Expand All @@ -75,3 +75,10 @@ jobs:
with:
name: e2e-test-report-${{ matrix.os }}-${{ matrix.node }}
path: ${{ runner.temp }}/test-report/

- name: Upload turbo logs
if: always()
uses: actions/upload-artifact@v3
with:
name: turbo-runs-${{ matrix.os }}-${{ matrix.node }}
path: .turbo/runs
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"prettify": "prettier . --write --ignore-unknown",
"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 --log-order=stream",
"test:e2e": "dotenv -- turbo test:e2e",
"test:e2e:wrangler": "node -r esbuild-register tools/e2e/runIndividualE2EFiles.ts",
"test:watch": "turbo test:watch",
"type:tests": "dotenv -- turbo type:tests"
},
Expand Down
32 changes: 32 additions & 0 deletions tools/e2e/runIndividualE2EFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Turbo only supports caching on the individual task level, but for Wrangler's
* e2e tests we want to support caching on a more granular basis—at the file level.
*
* As such, we run the `test:e2e` turbo task multiple times—once per e2e test file
* 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 Wrangler e2e test file, using `execSync`.
*/
import { execSync } from "child_process";
import { readdirSync } from "fs";

// Get a list of e2e test files, each of which should have an associated script
const e2eTests = readdirSync("packages/wrangler/e2e");

const tasks = new Set<string>();

for (const file of e2eTests) {
// Ignore other files in the e2e directory (the README, for instance)
if (file.endsWith(".test.ts")) {
tasks.add(
`pnpm test:e2e --log-order=stream --summarize --filter wrangler --concurrency 1 -- run ./e2e/${file}`
);
}
}

for (const task of tasks.values()) {
execSync(task, {
stdio: "inherit",
});
}
8 changes: 6 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"persistent": true,
"cache": false
},
"build": { "dependsOn": ["^build"] },
"build": {
"dependsOn": ["^build"]
},
"test": {
"dependsOn": ["build"]
},
Expand All @@ -33,6 +35,8 @@
"dependsOn": ["build"]
},
"test:e2e": {},
"//#check:format": { "cache": true }
"//#check:format": {
"cache": true
}
}
}

0 comments on commit c6c083f

Please sign in to comment.