Commit graph

29 commits

Author SHA1 Message Date
Ben
da39573016
chore(local-explorer-ui): Added basic behaviour tests (#12878)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Somhairle MacLeòid <smacleod@cloudflare.com>
Co-authored-by: Joevin <104806938+joevingracien@users.noreply.github.com>
Co-authored-by: Pete Bacon Darwin <pbacondarwin@cloudflare.com>
Co-authored-by: Chaitanya <chaitanyamishra.ai@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Wrangler automated PR updater <wrangler@cloudflare.com>
Co-authored-by: Thomas Gauvin <35609369+thomasgauvin@users.noreply.github.com>
Co-authored-by: Nikita Cano <ncano@cloudflare.com>
Co-authored-by: Nikita Cano <48366124+nikitacano@users.noreply.github.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Edmund Hung <me@edmund.dev>
Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>
Co-authored-by: James Opstad <13586373+jamesopstad@users.noreply.github.com>
Co-authored-by: ANT Bot <116369605+workers-devprod@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com>
Co-authored-by: Gabi <gvillalongasimon@cloudflare.com>
2026-04-01 16:05:55 +01:00
Pete Bacon Darwin
1beea21776
Replace public EBI Postgres database with local mock server in tests (#12784) 2026-03-06 14:29:55 +00:00
Pete Bacon Darwin
603fe181be
fix: add maxRetries to recursive directory removal for Windows EBUSY (#12629) 2026-02-24 14:10:45 +00:00
Dario Piotrowicz
b4d13733b5
fix wrangler dev logs being logged on the incorrect level in some cases (#10004)
* [miniflare] add `structuredWorkerdLogs` option

* fix `wrangler dev` logs being logged on the incorrect level in some cases
2025-07-31 16:50:07 +01:00
Pete Bacon Darwin
1f76f30bb3
Ensure consistent fixture package naming (#9378)
* tighten up turbo dependencies to avoid having to manually build

* test: ensure that fixture packages always start with `fixture-`

* refactor: consolidate fixture package names with consistent `fixture-` prefix

Updates all 63 fixture package names to use a consistent naming scheme with logical categorization:
- Core workers: fixture-worker-basic, fixture-worker-ai, fixture-worker-typescript, etc.
- Pages functions: fixture-pages-functions, fixture-pages-workerjs, etc.
- Database/storage: fixture-d1-basic, fixture-secrets-store, etc.
- Module handling: fixture-import-wasm, fixture-no-bundle-import, etc.
- Development tools: fixture-interactive-dev, fixture-local-mode, etc.

Also updates test files that reference specific fixture package names to maintain compatibility.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* add CI_OS env var to the check run to ensure correct turbo remote caching

* fixup! refactor: consolidate fixture package names with consistent `fixture-` prefix

* fixup! test: ensure that fixture packages always start with `fixture-`

* revert unnecessary change

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-05-28 12:08:48 +00:00
Dario Piotrowicz
75b454c37e
[wrangler] add validation to redirected configs in regards to environments (#8596)
* [wrangler] add validation to redirected configs in regards to environments

* error instead of warning on specified environments

* Update packages/wrangler/src/config/validation.ts

Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com>

* Update packages/wrangler/src/config/validation.ts

Co-authored-by: James Opstad <13586373+jamesopstad@users.noreply.github.com>

* update lock file

* update fixture tests

---------

Co-authored-by: emily-shen <69125074+emily-shen@users.noreply.github.com>
Co-authored-by: James Opstad <13586373+jamesopstad@users.noreply.github.com>
2025-04-07 09:53:18 +01:00
Somhairle MacLeòid
aaa9cca4de
Support Vitest 3 (#7923)
* Support Vitest 3

* no hangin timeout

* more changes

* faster tests?

* turbo

* update lockfile

* fix lockfile

* fix

* lint & windows

* fix lockfile

* lockfile

* fix lint

* Support v2 as well

* changeset

* lockfile
2025-02-14 17:52:20 +00:00
Victor Berchet
7d0be5fa79
refactor(wrangler): runWranglerDev always log error (#7907) 2025-01-27 12:57:44 +00:00
Somhairle MacLeòid
c63f1b0790
Remove express-based dev registry (#7706)
* Remove Server Registry

* some more

* Create ten-eyes-tease.md

* fix

* remove metafile

* fix rebase

* fix lockfile
2025-01-10 02:57:30 +00:00
Pete Bacon Darwin
e4716cc878
feat: add support for redirecting Wrangler to a generated config when running deploy commands (#7442)
* Do not console log wrangler output during normal fixture tests

This creates a lot of unwanted logging in the console.

The logging is still dumped to the console if the test times out, or if `WRANGLER_LOG=debug` is set as env var.

* no need to get relative config path for calls to verifyWorkerMatchesCITag()

* feat: add support for redirecting Wrangler to a generated config when running deploy commands

This new feature is designed for build tools and frameworks to provide a deploy-specific configuration,
which Wrangler can use instead of user configuration when running deploy commands.
It is not expected that developers of Workers will need to use this feature directly.

The commands that use this feature are:

- `wrangler deploy`
- `wrangler dev`
- `wrangler versions upload`
- `wrangler versions deploy`

When running these commands, Wrangler will look up the directory tree from the current working directory for a file at the path `.wrangler/deploy/config.json`. This file must contain only a single JSON object of the form:

```json
{ "configPath": "../../path/to/wrangler.json" }
```

When this file exists Wrangler will use the `configPath` (relative to the `deploy.json` file) to find an alternative Wrangler configuration file to load and use as part of this command.

When this happens Wrangler will display a warning to the user to indicate that the configuration has been redirected to a different file than the user's configuration file.

A common approach that a build tool might choose to implement.

- The user writes code that uses Cloudflare Workers resources, configured via a user `wrangler.toml` file.

  ```toml
  name = "my-worker"
  main = "src/index.ts"
  [[kv_namespaces]]
  binding = "<BINDING_NAME1>"
  id = "<NAMESPACE_ID1>"
  ```

  Note that this configuration points `main` at user code entry-point.

- The user runs a custom build, which might read the `wrangler.toml` to find the entry-point:

  ```bash
  > my-tool build
  ```

- This tool generates a `dist` directory that contains both compiled code and a new deployment configuration file, but also a `.wrangler/deploy/config.json` file that redirects Wrangler to this new deployment configuration file:

  ```plain
  - dist
    - index.js
  	- wrangler.json
  - .wrangler
    - deploy
  	  - config.json
  ```

  The `dist/wrangler.json` will contain:

  ```json
  {
  	"name": "my-worker",
  	"main": "./index.js",
  	"kv_namespaces": [{ "binding": "<BINDING_NAME1>", "id": "<NAMESPACE_ID1>" }]
  }
  ```

  And the `.wrangler/deploy/config.json` will contain:

  ```json
  {
  	"configPath": "../../dist/wrangler.json"
  }
  ```

* add config redirect fixture with tests

* Add config redirect support for Pages commands

* refactor: compute both the actual config path and the original user's configuration

* add `userConfigPath` to the `Config` type so it can be used where needed

* add fixture and test for redirected config in a pages project

* Do not check formatting of generated fixture files

* clean node_modules for npm-import fixture before testing

* fix unstable_dev tests

* run more Wrangler e2e tests on safe ports

* Requires that you create a `.env` file in the `packages/wrangler` directory containing:

```
CLOUDFLARE_ACCOUNT_ID=<dev-prod-account-id>
CLOUDFLARE_API_TOKEN=<dev-prod-account-api-key>
WRANGLER="node <path to workers-sdk/packages/wrangler/bin/wrangler.js>"
WRANGLER_IMPORT="<path to /workers-sdk/packages/wrangler/wrangler-dist/cli.js>"
````

* correctly configure python workers when no command line script is provided

* test: ensure that `pages functions build-env` command outputs correct relative pages_build_output_dir path

* Improve error message when deploy/config.json is not valid

* Complete jsdoc description

* Update jsdocs to note that the result of `resolveWranglerConfigPath()` contains absolute paths.

* PR feedback

* rename `useRedirect` to `useRedirectIfAvailable`

* Rename command definition behaviour from "useConfigRedirect" to "useConfigRedirectIfAvailable"

* Add clarifying comment

* Do not store package-lock.json for import-npm fixture

This fixture does not need a package lockfile to work.

* Remove unnecessary option in test
2025-01-08 09:32:40 +00:00
Somhairle MacLeòid
b499b743e2
No more React in wrangler dev (--x-dev-env only) (#7069)
* No more React in dev

* fix e2e

* remove more dead code

* fix

* fix fixtures

* fix prettier

* fix lockfile

* more dead code elimination

* lockfile

* fix regression

* Create late-guests-end.md

* fix lockfile

* fix merge

* fix snapshots

* remove stray log

* windows?

* add e2e retries

* fail at the right bit of e2e c3 test

* skip on windows

* remove retries

* Update messaging
2024-11-11 10:10:50 -05:00
Rahul Sethi
07fe80be51
file based registry fixtures (#6893) 2024-10-14 15:19:42 +01:00
Rahul Sethi
585cec014e
use --x-dev-env in pages fixtures (#6364) 2024-07-29 17:30:51 +01:00
Rahul Sethi
cfbdede63c
Add --x-dev-env to fixtures tests (#6330)
* add --x-dev-env to fixtures usage of `wrangler dev`

* set experimental.devEnv flag on fixtures usage of `unstable_dev()`

* fixups

* fixups

* cleanup runWranglerLongLived with tree-kill

* disable --x-registry/fileBasedRegistry in external-durable-objects-app fixtures

* unstable_dev should wait for ProxyWorker and UserWorker to be ready

* fixup

* fixup

* use runWranglerDevPages instead of fork

* add changeset
2024-07-29 11:52:47 +01:00
Pete Bacon Darwin
b7b1d65003
chore: use root volta config in all fixtures/packages (#5973)
Co-authored-by: bcoll <bcoll@cloudflare.com>
2024-06-05 11:32:08 +01:00
Pete Bacon Darwin
d0fd494bc1
Node 18 (#5820)
* chore: update wrangler tests to support running on node 18

* test: hide unwanted console logs from test output

* chore: tighten up wrangler turbo inputs further

The tests change files within the src directory, which was causing cache misses every time on builds

* test: use explicit IPv4 localhost address (127.0.0.1) to avoid known issue

When `wrangler dev` is run with `--port=0` workerd can get messed up on Node 18+
because it starts listening to both 127.0.0.1 and ::1 addresses with different dynamically
assigned ports. The workaround is to always specify the IP address when setting port to 0.

* chore: update the mono-repo to run on Node 18+

* chore: do not try to format temporary turbo files

* docs: remove incorrect requirement from pages-example-forum-app template

* ci: run Github Actions in Node.js 18.20.2

* test: ignore EBUSY errors when trying to clean up temp directories on Windows
2024-05-15 13:04:33 +01:00
Somhairle MacLeòid
649e763823
cache + speedup windows e2e (#5654)
* cache + speedup windows e2e

* fix README

* Merge prerelease jobs

* Run tests on PRs

* Fix turborepo

* Cache changesets

* Use turbo for create-cloudflare publishing
2024-04-25 15:21:35 +01:00
Greg Brimble
cd03d1d3fa
Add support for named entrypoints (#5215)
* feature: support named entrypoints in `wrangler (pages) deploy`

* chore: exclude `miniflare` from monorepo's Prettier config

* fix: allow `script`s without `scriptPath`s to import built-ins

* feature: service binding named entrypoints for single-instance JSRPC

* feature: direct socket named entrypoints for multi-instance JSRPC

* refactor: switch middleware to `external` services for dev registry

* feature: support binding to named entrypoints in `wrangler dev`

* feature: add middleware support to `WorkerEntrypoint`s

* feature: add API for starting isolated dev registry

* fix: ensure `url` and `cf` blob preserved across service bindings

* test: add tests for named entrypoints and RPC

* fixup! test: add tests for named entrypoints and RPC

Update error messages

* fix: improve error message for cross-session Durable Object RPC

* chore: move service binding assignment before Durable Objects

* fix: improve error message for RPC on not found service

* test: update deploy snapshot

* Add test for binding to own named entrypoint

* fix: allow named entrypoints to current worker

* Simplify cross-Worker Durable Object RPC error message

* Bump @cloudflare/workers-types@4.20240402.0

---------

Co-authored-by: bcoll <bcoll@cloudflare.com>
2024-04-03 17:42:35 -04:00
Pete Bacon Darwin
d70f44a171
ci: remove fixture from changeset releases (#5173)
* ci: remove fixture from changeset releases

* ci: ensure that fixtures are not deployable

* ci: actually run the deploy script not the deploy command for deploying Workers and Pages

* fixup! ci: ensure that fixtures are not deployable
2024-03-06 10:36:36 +00:00
Pete Bacon Darwin
3679bc18b2
fix: ensure that the Pages dev proxy server does not change the Host header (#4888)
* fix: ensure that the Pages dev proxy server does not change the Host header

Previously, when configuring `wrangler pages dev` to use a proxy to a 3rd party dev server,
the proxy would replace the Host header, resulting in problems at the dev server if it was
checking for cross-site scripting attacks.

Now the proxy server passes through the Host header unaltered making it invisible to the
3rd party dev server.

Fixes #4799

* fixup! fix: ensure that the Pages dev proxy server does not change the Host header

* fixup! fix: ensure that the Pages dev proxy server does not change the Host header

* fixup! fix: ensure that the Pages dev proxy server does not change the Host header
2024-02-02 16:48:58 +00:00
Magnus Dahlstrand
3e7cd6e408
[wrangler] fix: stop rebuild attempts when sources are missing (#3886) (#4877)
* [wrangler] fix: stop rebuild attempts when sources are missing (#3886)

* fixup! [wrangler] fix: stop rebuild attempts when sources are missing (#3886)

* fixup! [wrangler] fix: stop rebuild attempts when sources are missing (#3886)

* fixup! [wrangler] fix: stop rebuild attempts when sources are missing (#3886)

* Update .changeset/hip-files-count.md

Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>

* !fixup: [wrangler] fix: stop rebuild attempts when sources are missing (#3886)

* !fixup: [wrangler] fix: stop rebuild attempts when sources are missing (#3886)

---------

Co-authored-by: Peter Bacon Darwin <pbacondarwin@cloudflare.com>
Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com>
2024-02-02 12:58:02 +00:00
Rahul Sethi
61ec986a19
Improve fixture test stability (#4509)
* set --inspector-port=0
for all fixture tests which already set --port=0

* increase run-long-lived-wrangler timeout
2023-11-24 15:33:33 +00:00
Somhairle MacLeòid
9bc52cfb38
Improve Testing (#4325) 2023-11-09 16:16:57 +00:00
MrBBot
46cd2df574
fix: ensure console.log()s during startup are displayed (#4235)
As of #4072, whenever Wrangler connected to the V8 inspector, it would
clear V8's internal buffer of log messages. This ensured only messages
logged while the inspector was connected would be displayed.
Unfortunately, we only connect to the inspector once the Worker has
reported it's ready to receive connections. This meant any
`console.log()`s during Worker startup wouldn't be displayed. This
change switches to clearing V8's buffer whenever we _disconnect_
from the inspector instead, ensuring startup logs are shown.
2023-10-24 11:12:14 +01:00
Pete Bacon Darwin
7d20bdbd4e
Add find_additional_modules option to support partial bundling with externals (#3726)
* typo

* move stuff

* remove unnecessary typing

* remove unnecessary `active` property from middleware loader config

* more refactorings

* rename traverseModuleGraph as this is not what it does

* refactor to simplify findAdditionalModules()

* Rename the functions build helpers to make it more clear what their role is.

* invert module collector config - no longer need to return it as it is passed in

* implement module finding in normal bundling if the find_additional_modules flag is on

* allow `__STATIC_CONTENT_MANIFEST` to be imported from any module

* test: improve no-bundle-import tests

The no-bundle-import tests would actually pass if Wrangler actually bundled the code,
since it would identify and inline all the dynamic
imports that were being tested.

This change adds a test that would not pass if we are not capturing the additional modules.

It also moves the declaration of no-bundle to the wrangler.toml to ensure that normal use of `wrangler dev` will get this behavior.

* refactor: convert additional file finding to a generator function

This has a few of benefits:
- we don't risk creating too many file reads in a single go (using up all the available file handles); previously file reads were all done in parallel
- we don't read the files over and over for each rule
- the code is a bit easier to follow as we don't have to create `Promise.all()` objects

* fix: ensure that additional modules appear in the out-dir

When using `find_additional_modules` (or `no_bundle`) we find files that
will be uploaded to be deployed alongside the Worker.

Previously, if an `outDir` was specified, only the Worker code was output
to this directory. Now all additional modules are also output there too.

* pnpm fixups

* test: ignore failure to remove tmp dir on Windows

* test: do not show output in d1 time-travel tests

* refactor: consolidate writing additional modules

* test: add CommonJS lazy import to additional-modules fixture

* test: rename spec to test

* Add debug logging when writing additional modules

* Test additional module failure case and fix message typo

* Display build warnings before updating the bundle

---------

Co-authored-by: bcoll <bcoll@cloudflare.com>
2023-10-05 14:25:36 +01:00
MrBBot
a2f71e696c
fix: improve fixture test reliability/debugability (#3863) 2023-08-29 19:07:15 +01:00
Greg Brimble
33762441db
Mark fixtures-shared and routing-app as private (#3501) 2023-06-20 21:26:26 +01:00
Jacob M-G Evans
05099f4c9f
Turborepo Implementation & Monorepo standardization (#3261)
* Turborepo 
- Turbo Workspaces: isolated tasks and localized pipelines more complex packages to exist in the monorepo.
- Persistent mode for dev keyword let's Turborepo know it's something that will be watched or run long term.
- Update all packages with namespaced ones for configs
- Namespacing TSConfig & ESlint with `@Cloudflare/` per security suggestion by Greg Brimble

* ESLint and TSConfig Monorepo Configuration
   - ESLint & TSConfig are local packages, the monorepo now isolates its configs to packages utilizing them, 
      configurations are now monorepo packages
   -  Type Checking TypeScript can now directly
       use the TSConfig which infers from valid TS config formats, since we are using Monorepo conventions each 
       package only needs to care about its own config specifics and the extended global config as a package.
   - Wrangler Emit TSConfig: Figure out if this can be part of the TurboRepo pipeline then move this into the workers- 
      tsconfig package as "wrangler-emit"
   - TurboRepo setup to work with TypeScript subdirectories as TS projects & added configs to more fixtures
   - Instructions for VSCode TypeScript Project Version
   - ESLint & Turbo require the `.` declared where to run monorepo tasks from each package

* Dependencies 
  - Adding Wrangler as direct Dependency for Fixtures that need it
  - Standardize Monorepo packaging in Fixtures 
  - All Wrangler dependencies are now devDependency

* Vitest
   - Update Vitest & remove global Vitest config
   - Added Vitest script for explicit test:watch
   - Refactor pages-simple-assets test
   - Fix tests in fixtures (thanks @petebacondarwin)
2023-06-12 12:57:01 -05:00
Pete Bacon Darwin
3f824347c6
feat: support bundling the raw Pages _worker.js before deploying (#2404)
* refactor: tidy up fixture tests of long-lived wrangler processes

We now use helper functions to setup and teardown a long-lived wrangler process.
This means that we can remove the `--forceExit` option from the jest setup.

* feat: support bundling the raw Pages `_worker.js` before deploying

Previously, if you provided a `_worker.js` file, then Pages would simply check the
file for disallowed imports and then deploy the file as-is.

Not bundling the `_worker.js` file means that it cannot containing imports to other
JS files, but also prevents Wrangler from adding shims such as the one for the D1 alpha
release.

This change adds the ability to tell Wrangler to pass the `_worker.js` through the
normal Wrangler bundling process before deploying by setting the `--bundle`
command line argument to `wrangler pages dev` and `wrangler pages publish`.

This is in keeping with the same flag for `wrangler publish`.

Currently bundling is opt-in, flag defaults to `false` if not provided.

* test: increase timeout on local-mode test
2023-01-12 10:53:29 +00:00