* chore: add CI validation for external package dependencies
Add a validation check that ensures packages explicitly declare their
external (non-bundled) dependencies to prevent dependency chain poisoning.
- Add tools/deployments/validate-package-dependencies.ts validation script
- Add check:package-deps npm script and integrate into pnpm check
- Create scripts/deps.ts allowlists for packages with external dependencies:
- miniflare (12 deps)
- @cloudflare/vite-plugin (8 deps)
- @cloudflare/vitest-pool-workers (7 deps)
- @cloudflare/kv-asset-handler (1 dep)
- @cloudflare/workers-editor-shared (1 dep)
- Update CONTRIBUTING.md with documentation on managing dependencies
- Add unit tests for the validation logic (22 tests)
* fix(kv-asset-handler): bundle mime dependency instead of keeping it external
Move mime from dependencies to devDependencies so it gets bundled into
the distributable. This follows the project's practice of bundling
dependencies to prevent dependency chain poisoning.
* fix(miniflare): bundle acorn and acorn-walk dependencies
Move acorn and acorn-walk from dependencies to devDependencies so they
get bundled into the distributable. These are pure JavaScript parsing
libraries with no special runtime requirements, so they can be safely
bundled.
* chore: bundle more dependencies to reduce supply chain risk
Move 13 dependencies from dependencies to devDependencies so they get
bundled into the distributed packages rather than being installed as
transitive dependencies by users.
Packages updated:
- miniflare: bundle exit-hook, glob-to-regexp, stoppable, youch
- @cloudflare/vitest-pool-workers: bundle birpc, devalue, get-port, semver
- @cloudflare/vite-plugin: bundle @remix-run/node-fetch-server, defu,
get-port, picocolors, tinyglobby
Also updates the EXTERNAL_DEPENDENCIES comments to explain WHY each
remaining dependency cannot be bundled (native binaries, optional native
bindings, runtime resolution needs) rather than just describing how
they are used.
* fix(vitest-pool-workers): bundle dependencies that were moved to devDependencies
* chore: add changeset for dependency bundling
* fixup: remove unnecessary stuff from CONTRIBUTING
* test: fix Node 24/25 miniflare tests
Vite strips `//# sourceMappingURL=` comments from string literals during transformation,
which was causing the inline source map test to fail. This fix moves the worker script
with the inline source map to an external fixture file that is loaded at runtime,
bypassing Vite's transformation and allowing the test to work correctly on all Node.js versions.
* test: fix Node 25 wrangler tests by mocking undici globals
Extend the undici mock in vitest.setup.ts to also replace FormData,
Headers, Request, and Response with their global equivalents. This
allows MSW to properly intercept and parse requests in Node 25 where
native fetch/FormData classes differ from undici's implementations.
Also update FormData snapshot assertions in pages/deploy.test.ts to use
a new formDataToObject() helper that produces consistent output across
Node versions, since the internal representation of FormData varies.
* fix: patch buffer-equal-constant-time for Node 25 compatibility
Node 25 removed SlowBuffer from the buffer module (it was deprecated
in Node 24). The buffer-equal-constant-time package (last updated in
2013) accesses SlowBuffer.prototype without checking if it exists,
causing a crash.
This patch adds guards to check if SlowBuffer is defined before
accessing its prototype. The fix is backwards compatible with older
Node versions.
This is a transitive dependency through:
verdaccio -> @verdaccio/signature -> jsonwebtoken -> jws -> jwa -> buffer-equal-constant-time
* test: disable native webstorage for wrangler tests on Node 25+
Node 25 has native localStorage enabled by default, which conflicts with MSW.
Use a helper script to conditionally add --no-experimental-webstorage flag
to NODE_OPTIONS only on Node 25+, since this flag doesn't exist in Node 20-24.
* refactor(miniflare): migrate tests from Ava to Vitest
- Replace Ava test framework with Vitest
- Update test-shared utilities for Vitest APIs
- Convert all test files to use Vitest syntax
- Add vitest.config.mts configuration
- Update package.json dependencies and scripts
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: address PR feedback - use toBeInstanceOf and toBeDefined, fix flaky() and browser tests
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: remove incorrect vitest imports from fixture files
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: rename setup.ts to setup.mjs to avoid TypeScript checking dist/src/index.js
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: update vitest config to reference setup.mjs instead of setup.ts
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: fix FIXTURES_PATH resolution and D1 test imports
- Fix FIXTURES_PATH in test/plugins/core/errors/index.spec.ts (5 levels -> 4 levels)
- Fix FIXTURES_PATH in test/plugins/kv/sites.spec.ts (4 levels -> 3 levels)
- Fix FIXTURES_PATH in test/plugins/d1/test.ts (4 levels -> 3 levels)
- Convert D1 tests require('./suite') to ESM import
- Add zod-format snapshot file for Vitest
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: fix ROOT path in modules.spec.ts and add miniflare:shared alias to vitest config
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: address PR feedback - remove noinspection comments, use vi.spy, wrap browser tests in describe.sequential, fix errors test
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: address PR feedback - remove changeset, use test.skipIf, add timeout to browser tests
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: restore isWindows constant for conditional logic inside tests
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: skip data URL sourceMapURL assertion on Node < 24 (inspector limitation)
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: attach rejection handler before dispose() to prevent unhandled rejection
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: simplify FIXTURES_PATH and add hookTimeout for Windows CI
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: simplify all FIXTURES_PATH patterns across test files
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: remove unnecessary expect(error).toBeDefined() assertions in modules.spec.ts
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: add disposeWithRetry helper for Windows EPERM errors in browser tests
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: address PR feedback - move onTestFinished before expect, wrap retry tests in describe.sequential
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: replace flaky() and waitUntil() helpers with Vitest built-ins
- Replace flaky() with Vitest's built-in { retry: 3 } option in browser and fetch tests
- Replace waitUntil() with vi.waitFor() in dev-registry and inspector-proxy tests
- Use disposeWithRetry() in miniflare.ts afterAll hook for Windows compatibility
- Remove flaky(), waitFor(), and waitUntil() from asserts.ts (now using Vitest built-ins)
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: update email test to use vi.waitFor instead of removed waitFor helper
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: use useDispose() helper consistently and remove jscodeshift dependencies
- Replace all onTestFinished(() => mf.dispose()) with useDispose(mf)
- Update imports in all affected test files
- Remove jscodeshift dev dependencies from root package.json (used for migration)
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: use getter pattern in useDispose() for tests that reassign mf
Tests that reassign mf (e.g., persistence tests that dispose and recreate
Miniflare instances) need to use useDispose(() => mf) instead of useDispose(mf).
This ensures the current instance at teardown time is disposed, matching the
original onTestFinished(() => mf.dispose()) semantics.
The useDispose() helper now accepts either a Miniflare instance or a getter
function that returns the instance.
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: restore error message validation and use useDispose() consistently
- Fix r2/index.spec.ts: restore error message checking in rejects.toThrow() calls
that was lost during Ava-to-Vitest migration
- Replace all onTestFinished(() => xxx.dispose()) with useDispose(xxx) in:
- dev-registry.spec.ts (local, remote, unrelated)
- index.spec.ts (mfOther, mf1, mf2, client, server)
- kv/index.spec.ts (mf1, mf2)
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: correct error expectation for completeMultipartUpload with multiple parts of same part number
The original Ava test expected internalErrorExpectations (10001) for the
'completing with multiple parts of same part number' test case, but during
migration I mistakenly used notFoundExpectations (10025). This fixes the
test to match the original expected behavior.
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: replace isWithin() helper with direct Vitest assertions
Remove the isWithin() helper function and replace its usage with direct
Vitest assertions using toBeGreaterThanOrEqual() and toBeLessThanOrEqual()
for timestamp comparisons. This addresses PR feedback to use Vitest's
built-in matchers instead of custom helpers.
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: wrap DevRegistry tests in describe.sequential block
Address PR feedback to wrap all tests in dev-registry.spec.ts inside a
describe.sequential block to ensure tests run sequentially and don't
interfere with each other through the shared dev registry path.
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* chore: update pnpm-lock.yaml after merge with main
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: use error message in toThrow() matcher for poisoned stub test
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* refactor: remove test file bundling from build (Vitest runs tests directly from source)
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* use inline snapshots for zod tests
* fixup the tests that check thrown errors
* remove unnecessary factory function form of useDispose
* fix: add second useDispose(mf) call after mf reassignment in persistence tests
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fixups
* fix: make disposeWithRetry idempotent and restore sequential test for MINIFLARE_WORKERD_PATH
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* remove unnecessary comment
* move zod tests into a describe block
* move proxy tests into a describe block
* remove redundant config
* fixup comment
* move comment
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
* update to latest ava
* Display error `cause` in Miniflare tests
* hide unwanted logging from Miniflare browser plugin tests
* quieten Miniflare secrets-store plugin tests
* quieten Miniflare Durable Object plugin tests
* quieten other Miniflare tests
* Retry removing the Browser Session temp directory
* Give the Miniflare browser plugin tests a bit longer to complete
These tests will need to download the Chrome browser in the background, which can take quite a few seconds sometimes.
* silence Miniflare pipeline plugin tests
* Silence Miniflare unsafe plugin tests
* don't run miniflare tests files concurrently to flakes
In particular the dev-registry tests appear to be particularly sensitive
to concurrency issues, likely due to shared ports/sockets.
* run the Miniflare dev-registry tests in series (rather than parallel)
* fix typo
* quieten unwanted logging from Miniflare dev-registry tests
* no keep-alive
* add changeset
* no keep-alive
* fix changeset
* fix lockfile
* fix changeset (again)
* mark Miniflare browser tests as flaky
* add `@cloudflare/` scope to all private packages and rename root package
* move `::group::` inside then
* update blob and fixtures ignoring
* revert incorrect `::group::` change
* use `@cloudflare/vite-plugin-e2e-` as suggested in PR
* update import-example fixture package name
* fix(c3): preserve comments in wrangler.json files during project generation
- Replace jsoncParse/JSON.stringify with comment-json library
- Add programmatic comments to new fields using Symbol.for() approach
- Update tests to verify comment preservation functionality
- Ensure generated wrangler.json files maintain user-friendly comments
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: restore comprehensive comment structure and fix formatting
- Revert test snapshot to original comprehensive comment structure
- Fix config.ts to add comprehensive multi-line block comments using comment-json API
- Add proper spacing between comment sections
- Fix final newline formatting to match test expectations
Addresses GitHub PR feedback to restore full comment documentation.
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* test: remove conflicting test that expected simple line comments
The test was expecting simple line comments but the implementation now
generates comprehensive block comments as requested in the PR feedback.
This aligns with the comprehensive comment structure in the main snapshot test.
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: address GitHub comments by ensuring comprehensive comment structure
- Test snapshot already contains comprehensive comment structure as requested
- Config.ts implementation generates the expected comprehensive comments
- All local tests pass (5/5) including 'placeholder replacement (json)' test
- Implementation correctly uses comment-json API to add comprehensive block comments
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: revert to original comment generation approach to address GitHub feedback
- Simplified the config.ts implementation to use the original string concatenation approach
- This generates the comprehensive comment structure that matches the test expectations
- Addresses @petebacondarwin's feedback about fixing the implementation rather than the tests
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* modify wrangler.json using comment-json API
* fixup type issues
* moved helpers into their own file so they can be reused in c3 templates etc
* remove unnecessary `parse()` call from deploy.ts
* fixup package lock file
* fix typings
* more typings fixes
* docs: complete JSDoc documentation for addJSONComment function
- Complete the incomplete sentence 'loaded with comment-json'
- Add proper @param descriptions for all parameters
- Addresses GitHub comments from vicb
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: improve regex pattern for compatibility date validation
- Add $ anchor to ensure full string match in validCompatDateRe
- Addresses GitHub comment suggestion from vicb
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* docs: add explanatory comments to comment-json patch
- Explain why the patch is needed for proper whitespace formatting
- Document the two specific formatting issues it addresses
- Addresses GitHub comment from vicb about patch documentation
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
* fix: update pnpm lockfile after comment-json patch changes
- Update comment-json patch hash to match current patch content
- Resolves ERR_PNPM_LOCKFILE_CONFIG_MISMATCH in CI builds
Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
---------
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
Co-authored-by: Peter Bacon Darwin <pbacondarwin@cloudflare.com>
* feat(wrangler): improve script source display on pretty error screen
* avoid relying on fs in the patch with style refined
* drop native module script source support
* fix: ensure that the `sourcemap-codec` library has been transformed correctly to be imported in workerd during Vitest runs
Prior to this the inline snapshot tests were failing because they use the `magic-string` library, which in turn relies upon the `sourcemap-codec` library.
This resulted in errors that look like:
```
Error running worker: SyntaxError: The requested module '@jridgewell/sourcemap-codec' does not provide an export named 'encode'
```
* refactor: run C3 e2e tests more easily locally and individually
* fixup! refactor: run C3 e2e tests more easily locally and individually
* move to-exist helper back to setup file
* rename the filtering env vars
* fixup! refactor: run C3 e2e tests more easily locally and individually
* fix c3 e2e ci groups
* remove unnecessary step
* skip gatsby on yarn
* Run windows tests in a normal directory
* skip Workers tests on Windows
* match the previous test descriptions