Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement a testMode for running wrangler's dev function via API #1538

Merged
merged 8 commits into from
Sep 5, 2022

Conversation

rozenmd
Copy link
Contributor

@rozenmd rozenmd commented Jul 25, 2022

Prior to this change, wrangler.unstable_dev() would only support running one instance of wrangler at a time, as Ink only lets you render one instance of React. This resulted in test failures in CI.

This change creates pure JS/TS versions of these React hooks:

  • useEsbuild
  • useLocalWorker
  • useCustomBuild
  • useTmpDir

As a side-effect of removing React, tests should run faster in CI.

What we're not supporting (in this PR, anyway):

  • multi-worker support (you should be able to test multiple workers at the same time, but they won't know about each other)
  • watching/rebuilds - this API is designed to be used only by tests

Follow-up task:

Closes #1432
Closes #1419

@rozenmd rozenmd self-assigned this Jul 25, 2022
@changeset-bot
Copy link

changeset-bot bot commented Jul 25, 2022

🦋 Changeset detected

Latest commit: 1cf7983

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Jul 25, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2980556025/npm-package-wrangler-1538

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/1538/npm-package-wrangler-1538

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/2980556025/npm-package-wrangler-1538 dev path/to/script.js

@codecov
Copy link

codecov bot commented Jul 25, 2022

Codecov Report

Merging #1538 (1cf7983) into main (23f8921) will decrease coverage by 6.05%.
The diff coverage is 67.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1538      +/-   ##
==========================================
- Coverage   80.18%   74.13%   -6.06%     
==========================================
  Files          92       97       +5     
  Lines        6224     7070     +846     
  Branches     1603     1850     +247     
==========================================
+ Hits         4991     5241     +250     
- Misses       1233     1829     +596     
Impacted Files Coverage Δ
packages/wrangler/src/bundle.ts 71.42% <ø> (+1.78%) ⬆️
packages/wrangler/src/metrics/send-event.ts 100.00% <ø> (ø)
packages/wrangler/src/pages/dev.tsx 22.90% <ø> (ø)
packages/wrangler/src/dev/local.tsx 29.51% <50.00%> (ø)
packages/wrangler/src/api/dev.ts 57.69% <52.38%> (+42.30%) ⬆️
packages/wrangler/src/dev/start-server.ts 69.49% <69.49%> (ø)
packages/wrangler/src/dev.tsx 84.65% <97.82%> (+3.36%) ⬆️
packages/wrangler/src/pages/constants.ts 100.00% <0.00%> (ø)
...ngler/src/pages/functions/routes-transformation.ts 80.39% <0.00%> (ø)
packages/wrangler/src/dev-registry.tsx 14.28% <0.00%> (ø)
... and 6 more

@rozenmd rozenmd force-pushed the react-free-dev-api branch 2 times, most recently from 6c0b6d5 to 63b3781 Compare July 28, 2022 12:56
@rozenmd rozenmd changed the title work in progress - first steps to running dev without react First steps to running dev without react Jul 29, 2022
@rozenmd rozenmd changed the title First steps to running dev without react First steps to running wrangler's dev function via API without react Jul 29, 2022
@rozenmd rozenmd marked this pull request as ready for review July 29, 2022 09:20
@rozenmd rozenmd force-pushed the react-free-dev-api branch from 16df463 to d604c48 Compare July 29, 2022 09:56
@rozenmd rozenmd force-pushed the react-free-dev-api branch from 92a9f9e to 28e2c4b Compare August 25, 2022 08:40
@rozenmd rozenmd changed the title First steps to running wrangler's dev function via API without react Implement a testMode for running wrangler's dev function via API Aug 29, 2022
@rozenmd rozenmd force-pushed the react-free-dev-api branch from 43267e1 to d5eb1bb Compare August 29, 2022 16:54
This was referenced Aug 30, 2022
@rozenmd rozenmd force-pushed the react-free-dev-api branch from d5eb1bb to cca6063 Compare August 31, 2022 11:53
@rozenmd rozenmd assigned threepointone and unassigned rozenmd Aug 31, 2022
Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tentatively approving. thanks for pair reviewing this with me!

packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
packages/wrangler/src/dev/no-react.ts Outdated Show resolved Hide resolved
packages/wrangler/src/dev/no-react.ts Outdated Show resolved Hide resolved
packages/wrangler/src/dev/no-react.ts Outdated Show resolved Hide resolved
packages/wrangler/src/dev/no-react.ts Outdated Show resolved Hide resolved
logPrefix,
enablePagesAssetsServiceBinding,
}: LocalProps) {
let local: ChildProcess | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this implementation should be shared with the react version as well, it's just so much code

packages/wrangler/src/pages/dev.tsx Outdated Show resolved Hide resolved
@@ -0,0 +1,18 @@
import { unstable_dev } from "../api";

jest.unmock("undici");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
jest.unmock("undici");
jest["unmock"]("undici");

.


update imports


fix-up this fixture


make TS happy


an idea


make tests pass?


fix Pages


extract common logic


make pages work?


fix?


remove ability to rebuild in tests


remove watching from no-react


extract common warnings


split up logic common to both startDev and startApiDev


remove watchMode from API's esbuild
@@ -1,15 +1,19 @@
import { spawnWranglerDev } from "./helpers";
console.log(spawnWranglerDev);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to land this file in this TODO state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah i've removed this test and added a follow-up to reimplement it with unstable_dev: #1756

Comment on lines +4 to +7
let worker: {
fetch: (init?: RequestInit) => Promise<Response | undefined>;
stop: () => Promise<void>;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should export a named type for this rather than requiring users to write out the type by hand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do export:

/**
 *  unstable_dev starts a wrangler dev server, and returns a promise that resolves with utility functions to interact with it.
 *  @param {string} script
 *  @param {DevOptions} options
 */
export declare function unstable_dev(script: string, options?: DevOptions, apiOptions?: DevApiOptions): Promise<{
    stop: () => Promise<void>;
    fetch: (init?: RequestInit | undefined) => Promise<Response | undefined>;
    waitUntilExit: () => Promise<void>;
}>;

I just couldn't figure out how to make the types work within the mono repo 😕

@rozenmd rozenmd merged commit 2c9caf7 into main Sep 5, 2022
@rozenmd rozenmd deleted the react-free-dev-api branch September 5, 2022 07:29
@github-actions github-actions bot mentioned this pull request Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants