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 wrangler dev --(experimental-)local E2E tests #2365

Closed
wants to merge 4 commits into from

Conversation

mrbbot
Copy link
Contributor

@mrbbot mrbbot commented Dec 8, 2022

What this PR solves / how to test:

Wrangler has lots of tests, but none that simulate the full user flow for common operations (npm install, wrangler dev, wrangler publish). This PR adds end-to-end testing for wrangler dev --(experimental-)local.

Importantly, these E2E tests:

  • Install wrangler using npm as a user would, meaning we don't have access to wrangler's devDependencies in tests
  • Run wrangler with a pseudo-TTY, meaning we can run wrangler with stdin in "raw" mode, and test interactive elements like hotkeys
  • Determine when wrangler is listening based on stdout as a user would

The E2E tests in this PR (would) have caught the following issues:

We'll add E2E tests for remote wrangler dev and wrangler publish in the new year.

To try out the E2E tests, run npm build in the repository root, then change into the e2e directory, and run npm test.

Associated docs issues/PR:

N/A

Author has included the following, where applicable:

  • Tests 😄
  • Changeset (no user facing changes)

Reviewer has performed the following, where applicable:

  • Checked for inclusion of relevant tests
  • Checked for inclusion of a relevant changeset
  • Checked for creation of associated docs updates
  • Manually pulled down the changes and spot-tested

Ref #2351

@changeset-bot
Copy link

changeset-bot bot commented Dec 8, 2022

⚠️ No Changeset found

Latest commit: f6c55ce

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 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.devprod.cloudflare.dev/runs/3937933656/npm-package-wrangler-2365

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

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/prs/2365/npm-package-wrangler-2365

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/runs/3937933656/npm-package-wrangler-2365 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.devprod.cloudflare.dev/runs/3937933656/npm-package-cloudflare-pages-shared-2365

@codecov
Copy link

codecov bot commented Dec 19, 2022

Codecov Report

Merging #2365 (f6c55ce) into main (4db768f) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2365      +/-   ##
==========================================
- Coverage   72.99%   72.97%   -0.02%     
==========================================
  Files         156      156              
  Lines        9745     9747       +2     
  Branches     2568     2568              
==========================================
  Hits         7113     7113              
- Misses       2632     2634       +2     
Impacted Files Coverage Δ
packages/wrangler/src/dev/local.tsx 21.97% <0.00%> (-0.17%) ⬇️

@mrbbot mrbbot changed the title Implement E2E tests Implement wrangler dev --(experimental-)local E2E tests Dec 19, 2022
@mrbbot mrbbot marked this pull request as ready for review December 19, 2022 13:56
@mrbbot mrbbot requested a review from a team as a code owner December 19, 2022 13:56
Copy link
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

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

Very excited for this! Couple small comments (mostly clarification questions)

e2e/jest.config.mjs Show resolved Hide resolved
e2e/package.json Show resolved Hide resolved
e2e/package.json Show resolved Hide resolved
e2e/setup.ts Show resolved Hide resolved
e2e/setup.ts Show resolved Hide resolved
e2e/setup.ts Show resolved Hide resolved
exitPromise: Promise<number>;
// Exit code of `process` or `undefined` if it hasn't terminated yet
exitCode?: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are both of these necessary?

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 need some way of knowing if the process has already exited in cleanupSpawnedProcesses, and you can't inspect Promise state without awaiting it. We could just have a boolean exited flag, but this seemed like it could be useful in tests.

e2e/setup.ts Show resolved Hide resolved
e2e/setup.ts Show resolved Hide resolved
Comment on lines +78 to +79
const newValue = files["src/value.ts"].replace("= 1", "= 2");
await fs.writeFile(path.resolve(cwd, "src/value.ts"), newValue);
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like there should be a seed-like helper function for updating files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm, seed could return something like an instance of a RootedFileSystem<FileName extends string> class, with read/write/delete/replace methods. But I don't think we'll be replacing files too often for this to be needed? 🤷

Copy link
Contributor

@JacobMGEvans JacobMGEvans left a comment

Choose a reason for hiding this comment

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

I have no major callouts on this PR. No nits either. Thededent() is clever

My approval is tentative to @penalosa comments being resolved & checks fixed

[warn] e2e/package.json
[warn] Code style issues found in the above file. Forgot to run Prettier?

Edit: We should look into this framework to use it or if there is anything we can use from it https://github.com/node-modules/clet

@penalosa
Copy link
Contributor

LGTM!

@Cherry
Copy link
Contributor

Cherry commented Feb 26, 2023

Would be awesome to see this merged 👀

@Cherry
Copy link
Contributor

Cherry commented May 18, 2023

Hoping this lands in v3 soon 👀

@mrbbot
Copy link
Contributor Author

mrbbot commented Jun 28, 2023

Closing in favour of #3344

@mrbbot mrbbot closed this Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants