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

Add e2e tests to CI #3344

Merged
merged 3 commits into from
Jun 14, 2023
Merged

Add e2e tests to CI #3344

merged 3 commits into from
Jun 14, 2023

Conversation

penalosa
Copy link
Contributor

@penalosa penalosa commented May 25, 2023

Fixes #2351.

What this PR solves / how to test:

e2e testing in CI! This adds a run of the e2e tests to the pull request and main branch workflows, as well as adding basic tests for wrangler dev. It will be removed from the pull request workflow before this PR gets merged, but it's there for now to demonstrate how the tests work. Currently, about half the tests fail because of OS limitations of workerd—I'm in two minds about whether we should keep those failing tests in to remind us, or skip them for now.

Author has included the following, where applicable:

Reviewer is to perform the following, as 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

@changeset-bot
Copy link

changeset-bot bot commented May 25, 2023

⚠️ No Changeset found

Latest commit: e5af057

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

@penalosa penalosa requested a review from a team May 25, 2023 17:54
@github-actions
Copy link
Contributor

github-actions bot commented May 25, 2023

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/workers-sdk/runs/5266760836/npm-package-wrangler-3344

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

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

Or you can use npx with this latest build directly:

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

Note that these links will no longer work once the GitHub Actions artifact expires.

@codecov
Copy link

codecov bot commented May 25, 2023

Codecov Report

Merging #3344 (e5af057) into main (05099f4) will decrease coverage by 0.12%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3344      +/-   ##
==========================================
- Coverage   75.32%   75.20%   -0.12%     
==========================================
  Files         183      183              
  Lines       11022    11052      +30     
  Branches     2893     2904      +11     
==========================================
+ Hits         8302     8312      +10     
- Misses       2720     2740      +20     

see 5 files with indirect coverage changes

packages/wrangler/e2e/dev.test.ts Outdated Show resolved Hide resolved
packages/wrangler/e2e/dev.test.ts Outdated Show resolved Hide resolved
await retry(() =>
expect(
fetch(`http://127.0.0.1:${port}`).then((r) => r.text())
).resolves.toMatchInlineSnapshot('"Hello World!"')
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess snapshots don't really work with retries... 😅

Suggested change
).resolves.toMatchInlineSnapshot('"Hello World!"')
).resolves.toMatchInlineSnapshot('"Updated Worker!"')

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 actually a bit worrying, from a maintenance perspective.
The problem with retry is that it will pass if you put in the "old" data and wrangler has not yet updated the worker.

packages/wrangler/e2e/dev.test.ts Outdated Show resolved Hide resolved
packages/wrangler/e2e/helpers/retry.ts Outdated Show resolved Hide resolved
packages/wrangler/e2e/dev.test.ts Show resolved Hide resolved
Copy link
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

LGTM once the "modify" tests are fixed.

.github/workflows/main.yml Outdated Show resolved Hide resolved
.github/workflows/main.yml Outdated Show resolved Hide resolved
packages/wrangler/e2e/dev.test.ts Outdated Show resolved Hide resolved
packages/wrangler/e2e/dev.test.ts Show resolved Hide resolved
packages/wrangler/e2e/dev.test.ts Outdated Show resolved Hide resolved
Comment on lines +7 to +16
if (n === 0) {
await promise();
} else {
try {
await promise();
} catch {
await setTimeout(2_000);
return retry(promise, n - 1);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for fun this could also be written without recursion:

async function retry(promise: ..., n = 20) {
  for (let i = 0; i < n; i++) {
    try {
      return promise();
    } catch {
      await setTimeout(2000);
    }
  }
  throw new Error("Timed out waiting for promise to resolve");
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Not interested? 😿

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kinda prefer the recursive way, since it should throw the proper error from the promise on the last run

await retry(() =>
expect(
fetch(`http://127.0.0.1:${port}`).then((r) => r.text())
).resolves.toMatchInlineSnapshot('"Hello World!"')
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 actually a bit worrying, from a maintenance perspective.
The problem with retry is that it will pass if you put in the "old" data and wrangler has not yet updated the worker.

@penalosa penalosa force-pushed the penalosa/e2e-ci branch 5 times, most recently from d861067 to 966dc4a Compare June 13, 2023 11:20
@penalosa penalosa added the e2e Run e2e tests on a PR label Jun 13, 2023
@penalosa penalosa force-pushed the penalosa/e2e-ci branch 6 times, most recently from 697381c to 9c4386c Compare June 13, 2023 12:21
NODE_ENV: "production"

- name: Run tests
run: cd packages/wrangler && npm run test:e2e
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you not use the npm workspace rather than cd-ing?

Suggested change
run: cd packages/wrangler && npm run test:e2e
run: npm run -w wrangler test:e2e

@@ -63,7 +63,7 @@
"test": "npm run assert-git-version && jest",
"test:ci": "npm run test -- --coverage",
"test:debug": "npm run test -- --silent=false --verbose=true",
"test:e2e": "vitest --single-thread ./e2e",
"test:e2e": "vitest --single-thread --test-timeout 120000 --dir ./e2e run",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the --test-timeout here and in the vite.config.ts file too?

Comment on lines +7 to +16
if (n === 0) {
await promise();
} else {
try {
await promise();
} catch {
await setTimeout(2_000);
return retry(promise, n - 1);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not interested? 😿

const WRANGLER = process.env.WRANGLER ?? `npx wrangler@beta`;

const RUN = `${CF_ID} ${WRANGLER}`;
const RUN = process.env.WRANGLER ?? `npx --prefer-offline wrangler@beta`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than hitting the beta deployed version, I think we could do:

Suggested change
const RUN = process.env.WRANGLER ?? `npx --prefer-offline wrangler@beta`;
const pathToWrangler = path.resolve(__dirname, "../../..");
const RUN = process.env.WRANGLER ?? `node "${pathToWrangler}"`;

And that might even avoid having to set the WRANGLER package in the CI job - and even avoid all that packaging and copying/moving in the job too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or were you trying to be even more "pure" in terms of e2e?

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, the idea was that it should mimic running a package installed from npm

@petebacondarwin
Copy link
Contributor

Interestingly I ran this locally and got:

> wrangler@3.1.0 test:e2e
> vitest --single-thread --test-timeout 120000 --dir ./e2e run


 RUN  v0.31.4 /Users/pbacondarwin/dev/wrangler2/packages/wrangler

 ❯ e2e/dev.test.ts (2)
   ❯ basic dev tests (2)
     ⠇ can modify worker during dev session (local)
     · can modify worker during dev session (remote)
 ❯ e2e/dev.test.ts (2)
   ❯ basic dev tests (2)
 ❯ e2e/dev.test.ts (2)
   ❯ basic dev tests (2)
 ❯ e2e/dev.test.ts (2)
   ❯ basic dev tests (2)
 ❯ e2e/dev.test.ts (2)
 ❯ e2e/dev.test.ts (2)
 ❯ e2e/dev.test.ts (2)
 ❯ e2e/dev.test.ts (2)
   ❯ basic dev tests (2)
 ❯ e2e/dev.test.ts (2)
   ❯ basic dev tests (2)
     ✓ can modify worker during dev session (local) 4054ms
 ❯ e2e/dev.test.ts (2)
   ❯ basic dev tests (2)
 ❯ e2e/dev.test.ts (2)
   ❯ basic dev tests (2)
 ❯ e2e/dev.test.ts (2)
 ❯ e2e/dev.test.ts (2)
   ❯ basic dev tests (2)
     ✓ can modify worker during dev session (local) 4054ms
⎔ Detected changes, restarted server.

 ❯ e2e/dev.test.ts (2)
 ✓ e2e/dev.test.ts (2) 10899ms
 ✓ e2e/r2.test.ts (7) 17519ms
 ✓ e2e/deployments.test.ts (8) 91675ms
 ✓ e2e/deploy.test.ts (4) 71216ms

  Snapshots  2 failed
 Test Files  4 passed (4)
      Tests  21 passed (21)
   Start at  20:26:54
   Duration  193.96s (transform 98ms, setup 0ms, collect 2.47s, tests 191.31s, environment 0ms, prepare 43ms)

Note it says that two snapshots failed, but does not tell me which...

@penalosa
Copy link
Contributor Author

penalosa commented Jun 13, 2023

Note it says that two snapshots failed, but does not tell me which...

I think these are snapshot failures that are caught by retry()

@penalosa penalosa merged commit 5cfb94c into main Jun 14, 2023
@penalosa penalosa deleted the penalosa/e2e-ci branch June 14, 2023 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🔬 Add E2E tests
4 participants