Skip to content

Commit

Permalink
Merge branch 'cloudflare:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
JoftheV authored May 24, 2024
2 parents 700d7d8 + 53f22a0 commit e199352
Show file tree
Hide file tree
Showing 144 changed files with 9,684 additions and 10,147 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-spies-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: Remove WARP certificate injection. Instead, you should ensure that any custom certificates that are needed are included in `NODE_EXTRA_CA_CERTS`.
5 changes: 0 additions & 5 deletions .changeset/unlucky-radios-fold.md

This file was deleted.

12 changes: 10 additions & 2 deletions .github/workflows/test-and-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,22 @@ jobs:
TMP_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
NODE_OPTIONS: "--max_old_space_size=8192"
WRANGLER_LOG_PATH: ${{ runner.temp }}/wrangler-debug-logs/
TEST_REPORT_PATH: ${{ runner.temp }}/test-report/index.html
CI_OS: ${{ runner.os }}

- name: Run changeset version tests
run: node .github/changeset-version.test.js

- name: Upload debug logs
if: always()
uses: actions/upload-artifact@v3
with:
name: e2e-test-debug-logs-${{ matrix.os }}-${{ matrix.node }}
path: ${{ runner.temp }}/wrangler-debug-logs/

- name: Run changeset version tests
run: node .github/changeset-version.test.js
- name: Upload test report
if: always()
uses: actions/upload-artifact@v3
with:
name: e2e-test-report-${{ matrix.os }}-${{ matrix.node }}
path: ${{ runner.temp }}/test-report/
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ The code is checked for formatting errors by [Prettier](https://prettier.io/).

### Testing

Tests in a workspace are executed, by [Jest](https://jestjs.io/), which is configured to automatically compile and bundle the TypeScript before running the tests.
Tests in a workspace are executed, by [Vitest](https://vitest.dev/), which is configured to automatically compile and bundle the TypeScript before running the tests.

- Run the tests for all the workspaces
```sh
Expand Down Expand Up @@ -209,7 +209,7 @@ As a reviewer, it's important to be thoughtful about the proposed changes and co
## PR Tests
Every PR should include tests for the functionality that's being added. Most changes will be to [Wrangler](packages/wrangler/src/__tests__) (using Jest), [Miniflare](packages/miniflare/test) (using Ava), or [C3](packages/create-cloudflare/src/__tests__) (using Vitest), and should include unit tests within the testing harness of those packages.
Every PR should include tests for the functionality that's being added. Most changes will be to [Wrangler](packages/wrangler/src/__tests__) (using Vitest), [Miniflare](packages/miniflare/test) (using Ava), or [C3](packages/create-cloudflare/src/__tests__) (using Vitest), and should include unit tests within the testing harness of those packages.

If your PR includes functionality that's difficult to unit test, you can add a fixture test by creating a new package in the `fixtures/` folder. This allows for adding a test that requires a specific filesystem or worker setup (for instance, `fixtures/no-bundle-import` tests the interaction of Wrangler with a specific set of JS, WASM, text, and binary modules on the filesystem). When adding a fixture test, include a `vitest.config.ts` file within the new package, which will ensure it's run as part of the `workers-sdk` CI. You should merge your own configuration with the default config from the root of the repo.

Expand Down
6 changes: 6 additions & 0 deletions packages/pages-shared/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @cloudflare/pages-shared

## 0.11.38

### Patch Changes

- [#5875](https://github.com/cloudflare/workers-sdk/pull/5875) [`ddfeeef`](https://github.com/cloudflare/workers-sdk/commit/ddfeeef920f0b565ed7f39da40b5b75cb234db00) Thanks [@WalshyDev](https://github.com/WalshyDev)! - fix: no longer allow zone caching for responses that returned 404. This is to prevent some files in a new deployment from returning and subsequently caching 404s while the deployment propagates across the network.

## 0.11.37

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/pages-shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflare/pages-shared",
"version": "0.11.37",
"version": "0.11.38",
"repository": {
"type": "git",
"url": "https://github.com/cloudflare/workers-sdk.git",
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest-pool-workers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"dev": "node scripts/bundle.mjs watch",
"check:lint": "eslint .",
"check:type": "tsc && tsc -p src/worker/tsconfig.json && tsc -p types/tsconfig.json",
"test": "vitest run",
"test:ci": "vitest run",
"capnp:rtti": "capnpc -o ts scripts/rtti/rtti.capnp"
},
"devDependencies": {
Expand All @@ -57,6 +59,7 @@
"@types/semver": "^7.5.1",
"capnp-ts": "^0.7.0",
"capnpc-ts": "^0.7.0",
"ts-dedent": "^2.2.0",
"undici": "5.28.4"
},
"dependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/vitest-pool-workers/src/pool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ async function runTests(
filePath: workerPath,
name: "run",
data,
cwd: process.cwd(),
}),
},
});
Expand Down
7 changes: 7 additions & 0 deletions packages/vitest-pool-workers/src/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ globalThis.Buffer = Buffer; // Required by `vite-node/source-map`

globalThis.process = process; // Required by `vite-node`
process.argv = []; // Required by `@vitest/utils`
let cwd: string | undefined;
process.cwd = () => {
assert(cwd !== undefined, "Expected cwd to be set");
return cwd;
};
Object.setPrototypeOf(process, events.EventEmitter.prototype); // Required by `vitest`

globalThis.__console = console;
Expand Down Expand Up @@ -198,6 +203,8 @@ export class RunnerObject implements DurableObject {
assert("filePath" in wd && typeof wd.filePath === "string");
assert("name" in wd && typeof wd.name === "string");
assert("data" in wd && typeof wd.data === "object" && wd.data !== null);
assert("cwd" in wd && typeof wd.cwd === "string");
cwd = wd.cwd;

const port = new WebSocketMessagePort(poolSocket);
try {
Expand Down
10 changes: 10 additions & 0 deletions packages/vitest-pool-workers/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# `@cloudflare/vitest-pool-workers` E2E Tests

This directory implements E2E tests for the `@cloudflare/vitest-pool-workers` package.

`miniflare`, `wrangler` and `@cloudflare/vitest-pool-workers` are packed into tarballs, then installed in a temporary directory to test against.

If possible, tests should be written in the [`fixtures/vitest-pool-workers-examples`](../../../fixtures/vitest-pool-workers-examples) directory.
These tests run inside `@cloudflare/vitest-pool-workers` itself, and execute much faster.
They're also a source of documentation for end users.
Use the [`misc`](../../../fixtures/vitest-pool-workers-examples/misc) directory if your test doesn't really belong with an example.
46 changes: 46 additions & 0 deletions packages/vitest-pool-workers/test/chunking.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import dedent from "ts-dedent";
import { test } from "./helpers";

test("chunks large WebSocket messages bi-directionally", async ({
expect,
seed,
vitestRun,
}) => {
// Check loads module greater than 1 MiB `workerd` limit...
const bigText = "xyz".repeat(400_000);
await seed({
"big.txt": bigText,
"vitest.config.ts": dedent`
import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";
export default defineWorkersConfig({
test: {
poolOptions: {
workers: {
singleWorker: true,
miniflare: {
compatibilityDate: "2024-01-01",
compatibilityFlags: ["nodejs_compat"],
modulesRules: [
{ type: "Text", include: ["**/*.txt"] }
]
},
},
},
}
});
`,
"index.test.ts": dedent`
import text from "./big.txt";
import { it } from "vitest";
it("logs big text", () => {
console.log(text);
});
`,
});
// Increase buffer size to allow the `exec` command to receive this large output.
const result = await vitestRun({ maxBuffer: bigText.length + 1000 });
await result.exitCode;
// ...and logs it back
expect(result.stdout).toMatch(bigText);
expect(await result.exitCode).toBe(0);
});
54 changes: 54 additions & 0 deletions packages/vitest-pool-workers/test/console.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import dedent from "ts-dedent";
import { minimalVitestConfig, test, waitFor } from "./helpers";

test.skipIf(process.platform === "win32")(
"console.log()s include correct source-mapped locations",
async ({ expect, seed, vitestDev }) => {
await seed({
"vitest.config.ts": minimalVitestConfig,
"index.test.ts": dedent`
import { describe, it } from "vitest";
console.log("global");
describe("thing", () => {
console.log("describe");
it("does something", () => {
console.log("test");
});
});
`,
});
const result = vitestDev();
await waitFor(() => {
expect(result.stdout).toMatch("stdout | index.test.ts:2:9\nglobal");
expect(result.stdout).toMatch("stdout | index.test.ts:4:10\ndescribe");
expect(result.stdout).toMatch(
"stdout | index.test.ts > thing > does something\ntest"
);
});

// Check still have correct locations on reload
// TODO(soon): when issue with source map cache not being flushed between reloads,
// add a test here to ensure that changing line numbers changes output
await seed({
"index.test.ts": dedent`
import { describe, it } from "vitest";
console.log("new global");
describe("new thing", () => {
console.log("new describe");
it("does something else", () => {
console.log("new test");
});
});
`,
});
await waitFor(() => {
expect(result.stdout).toMatch("stdout | index.test.ts:2:9\nnew global");
expect(result.stdout).toMatch(
"stdout | index.test.ts:4:10\nnew describe"
);
expect(result.stdout).toMatch(
"stdout | index.test.ts > new thing > does something else\nnew test"
);
});
}
);
7 changes: 7 additions & 0 deletions packages/vitest-pool-workers/test/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare module "vitest" {
interface ProvidedContext {
tmpPoolInstallationPath: string;
}
}

export {};
88 changes: 88 additions & 0 deletions packages/vitest-pool-workers/test/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import assert from "node:assert";
import childProcess from "node:child_process";
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import type { GlobalSetupContext } from "vitest/node";

function packPackage(packDestinationPath: string, packagePath: string) {
const output = childProcess.execSync(
`pnpm pack --pack-destination ${packDestinationPath}`,
{ cwd: packagePath, encoding: "utf8" }
);
const tarballPath = output.split("\n").find((line) => line.endsWith(".tgz"));
assert(
tarballPath !== undefined && path.isAbsolute(tarballPath),
`Expected absolute tarball path in ${JSON.stringify(output)}`
);
return tarballPath;
}

// Using a global setup means we can modify tests without having to re-install
// packages into our temporary directory
export default async function ({ provide }: GlobalSetupContext) {
console.log("Installing packages to temporary directory...");

// Create temporary directory
const tmpPath = await fs.realpath(
await fs.mkdtemp(path.join(os.tmpdir(), "vitest-pool-workers"))
);

// Pack `miniflare`, `wrangler` and `vitest-pool-workers` into tarballs
const packDestinationPath = path.join(tmpPath, "packed");
const packagesRoot = path.resolve(__dirname, "../..");
const miniflareTarballPath = packPackage(
packDestinationPath,
path.join(packagesRoot, "miniflare")
);
const wranglerTarballPath = packPackage(
packDestinationPath,
path.join(packagesRoot, "wrangler")
);
const poolTarballPath = packPackage(
packDestinationPath,
path.join(packagesRoot, "vitest-pool-workers")
);

// Get required `vitest` version
const poolPackageJsonPath = path.join(
packagesRoot,
"vitest-pool-workers/package.json"
);
const poolPackageJson = JSON.parse(
await fs.readFile(poolPackageJsonPath, "utf8")
);
const poolVitestVersion = poolPackageJson.peerDependencies?.vitest;
assert(
poolVitestVersion,
"Expected to find `vitest` peer dependency version"
);

// Install packages into temporary directory
const packageJsonPath = path.join(tmpPath, "package.json");
const packageJson = {
name: "vitest-pool-workers-e2e-tests",
private: true,
type: "module",
devDependencies: {
"@cloudflare/vitest-pool-workers": poolTarballPath,
vitest: poolVitestVersion,
},
pnpm: {
overrides: {
miniflare: miniflareTarballPath,
wrangler: wranglerTarballPath,
},
},
};
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson));
childProcess.execSync("pnpm install", { cwd: tmpPath, stdio: "inherit" });

provide("tmpPoolInstallationPath", tmpPath);

// Cleanup temporary directory on teardown
return async () => {
console.log("Cleaning up temporary directory...");
await fs.rm(tmpPath, { recursive: true, maxRetries: 10 });
};
}
Loading

0 comments on commit e199352

Please sign in to comment.