forked from cloudflare/workers-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'cloudflare:main' into main
- Loading branch information
Showing
144 changed files
with
9,684 additions
and
10,147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -653,6 +653,7 @@ async function runTests( | |
filePath: workerPath, | ||
name: "run", | ||
data, | ||
cwd: process.cwd(), | ||
}), | ||
}, | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
); | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare module "vitest" { | ||
interface ProvidedContext { | ||
tmpPoolInstallationPath: string; | ||
} | ||
} | ||
|
||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
}; | ||
} |
Oops, something went wrong.