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

feat: implement fetch, and write our first integration test #1386

Merged
merged 2 commits into from
Jul 5, 2022

Conversation

rozenmd
Copy link
Contributor

@rozenmd rozenmd commented Jul 1, 2022

Disable whitespaces for this change

Closes #1383
Closes #1384
Closes #1385

@changeset-bot
Copy link

changeset-bot bot commented Jul 1, 2022

🦋 Changeset detected

Latest commit: 1ef5c5b

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 1, 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/2615466229/npm-package-wrangler-1386

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

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

Or you can use npx with this latest build directly:

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

@@ -0,0 +1 @@
declare module "wrangler";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove once we're outputting types

@rozenmd rozenmd force-pushed the test-unstable-dev branch 2 times, most recently from ed20f16 to fc9d99a Compare July 4, 2022 14:52
@rozenmd rozenmd changed the title WIP - Testing API/unstable_dev feat: implement fetch, and write our first integration test Jul 4, 2022
@rozenmd rozenmd marked this pull request as ready for review July 4, 2022 14:54
packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
.changeset/quiet-olives-fry.md Outdated Show resolved Hide resolved
@@ -255,7 +255,7 @@ function useLocalWorker({
});
//TODO: instead of being lucky with spawn's timing, have miniflare-cli notify wrangler that it's ready in packages/wrangler/src/miniflare-cli/index.ts, after the mf.startScheduler promise resolves
if (onReady) {
await new Promise((resolve) => setTimeout(resolve, 200));
await new Promise((resolve) => setTimeout(resolve, 5000));
Copy link
Contributor

Choose a reason for hiding this comment

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

is this where the 200 ms delay came from? also now it's 5 seconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - since we haven't implemented message passing between the wrangler and miniflare processes, this is a hack which waits 5000ms for miniflare to be ready for requests. Will try lower values and see if they pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can be as low as 250ms, but it's flaky. 500ms seems to be a good spot for now.

process.exit(0);
},
fetch: async () => {
const port = args.port || config.dev.port || (await getLocalPort());
Copy link
Contributor

Choose a reason for hiding this comment

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

getLocalPort might not return the same value as was used by the server
I think you'll have to somehow get the value out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ugh

Copy link
Contributor

Choose a reason for hiding this comment

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

add a todo comment here, this will be critical to fix

packages/wrangler/src/dev.tsx Outdated Show resolved Hide resolved
return new Promise<{ stop: () => void }>((resolve) => {
return new Promise<{
stop: () => void;
fetch: (init?: RequestInit) => Promise<Response | undefined>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

feels weird to be using fetch(init?) instead of the actual standard of fetch(resource, init?), but we're not letting folks pick the resource after the worker has started (yet)...

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.

stamping to land and iterate

process.exit(0);
},
fetch: async () => {
const port = args.port || config.dev.port || (await getLocalPort());
Copy link
Contributor

Choose a reason for hiding this comment

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

add a todo comment here, this will be critical to fix

@@ -255,7 +255,7 @@ function useLocalWorker({
});
//TODO: instead of being lucky with spawn's timing, have miniflare-cli notify wrangler that it's ready in packages/wrangler/src/miniflare-cli/index.ts, after the mf.startScheduler promise resolves
if (onReady) {
await new Promise((resolve) => setTimeout(resolve, 200));
await new Promise((resolve) => setTimeout(resolve, 500));
Copy link
Contributor

Choose a reason for hiding this comment

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

this is going to need some ipc magic to fix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah looking into this now on a separate branch

@rozenmd rozenmd merged commit 4112001 into main Jul 5, 2022
@rozenmd rozenmd deleted the test-unstable-dev branch July 5, 2022 10:22
@github-actions github-actions bot mentioned this pull request Jul 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
2 participants