Skip to content

Commit

Permalink
Add --experimental-local support to unstable_dev (#1940)
Browse files Browse the repository at this point in the history
* Add `--experimental-local` support to `unstable_dev`

* Enable `--experimental-vm-modules` in `local-mode-tests`

`--experimental-local` uses `npx-import` to import `@miniflare/tre`,
because we want to install `workerd` lazily. `npx-import` makes use
of dynamic `import()`. Jest only supports this if
`--experimental-vm-modules` is set. If it isn't, the tests just hang.

* Report correct `port` from `Miniflare` in `onReady`

...and use correct `next` dist tag for `npx-import`

* Temporarily remove `unstable_dev` `experimentalLocal` test
  • Loading branch information
mrbbot committed Sep 28, 2022
1 parent 58a430f commit b88ccf4
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 109 deletions.
4 changes: 2 additions & 2 deletions fixtures/local-mode-tests/package.json
Expand Up @@ -9,8 +9,8 @@
"main": "index.js",
"scripts": {
"check:type": "tsc",
"test": "cross-env NODE_ENV=local-testing npx jest --forceExit",
"test:ci": "cross-env NODE_ENV=local-testing npx jest --forceExit"
"test": "cross-env NODE_ENV=local-testing NODE_OPTIONS=--experimental-vm-modules npx jest --forceExit",
"test:ci": "cross-env NODE_ENV=local-testing NODE_OPTIONS=--experimental-vm-modules npx jest --forceExit"
},
"jest": {
"restoreMocks": true,
Expand Down
5 changes: 4 additions & 1 deletion fixtures/local-mode-tests/tests/unstableDev.test.ts
@@ -1,5 +1,8 @@
import { unstable_dev } from "wrangler";

// TODO: add test for `experimentalLocal: true` once issue with dynamic
// `import()` and `npx-import` resolved:
// https://github.com/cloudflare/wrangler2/pull/1940#issuecomment-1261166695
describe("worker", () => {
let worker: {
fetch: (
Expand All @@ -22,7 +25,7 @@ describe("worker", () => {
});

afterAll(async () => {
await worker.stop();
await worker?.stop();
});

it("should invoke the worker and exit", async () => {
Expand Down
84 changes: 42 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/wrangler/package.json
Expand Up @@ -112,7 +112,7 @@
"@databases/sql": "^3.2.0",
"@iarna/toml": "^3.0.0",
"@microsoft/api-extractor": "^7.28.3",
"@miniflare/tre": "3.0.0-next.1",
"@miniflare/tre": "3.0.0-next.2",
"@types/better-sqlite3": "^7.6.0",
"@types/busboy": "^1.5.0",
"@types/command-exists": "^1.2.0",
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/api/dev.ts
Expand Up @@ -54,6 +54,7 @@ interface DevOptions {
_?: (string | number)[]; //yargs wants this
$0?: string; //yargs wants this
testScheduled?: boolean;
experimentalLocal?: boolean;
}

interface DevApiOptions {
Expand Down
9 changes: 6 additions & 3 deletions packages/wrangler/src/dev.tsx
Expand Up @@ -561,10 +561,13 @@ export async function startApiDev(args: StartDevOptions) {
isWorkersSite: Boolean(args.site || configParam.site),
compatibilityDate: getDevCompatibilityDate(
config,
args["compatibility-date"]
// Only `compatibilityDate` will be set when using `unstable_dev`
args["compatibility-date"] ?? args.compatibilityDate
),
compatibilityFlags:
args["compatibility-flags"] || configParam.compatibility_flags,
args["compatibility-flags"] ??
args.compatibilityFlags ??
configParam.compatibility_flags,
usageModel: configParam.usage_model,
bindings: bindings,
crons: configParam.triggers.crons,
Expand All @@ -578,7 +581,7 @@ export async function startApiDev(args: StartDevOptions) {
firstPartyWorker: configParam.first_party_worker,
sendMetrics: configParam.send_metrics,
testScheduled: args.testScheduled,
experimentalLocal: undefined,
experimentalLocal: args.experimentalLocal,
});
}

Expand Down

0 comments on commit b88ccf4

Please sign in to comment.