-
Notifications
You must be signed in to change notification settings - Fork 758
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
Add e2e tests to CI #3344
Conversation
|
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 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 Report
@@ 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 |
packages/wrangler/e2e/dev.test.ts
Outdated
await retry(() => | ||
expect( | ||
fetch(`http://127.0.0.1:${port}`).then((r) => r.text()) | ||
).resolves.toMatchInlineSnapshot('"Hello World!"') |
There was a problem hiding this comment.
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... 😅
).resolves.toMatchInlineSnapshot('"Hello World!"') | |
).resolves.toMatchInlineSnapshot('"Updated Worker!"') |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
if (n === 0) { | ||
await promise(); | ||
} else { | ||
try { | ||
await promise(); | ||
} catch { | ||
await setTimeout(2_000); | ||
return retry(promise, n - 1); | ||
} | ||
} |
There was a problem hiding this comment.
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");
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not interested? 😿
There was a problem hiding this comment.
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
packages/wrangler/e2e/dev.test.ts
Outdated
await retry(() => | ||
expect( | ||
fetch(`http://127.0.0.1:${port}`).then((r) => r.text()) | ||
).resolves.toMatchInlineSnapshot('"Hello World!"') |
There was a problem hiding this comment.
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.
d861067
to
966dc4a
Compare
697381c
to
9c4386c
Compare
9c4386c
to
e49a53f
Compare
.github/workflows/e2e.yml
Outdated
NODE_ENV: "production" | ||
|
||
- name: Run tests | ||
run: cd packages/wrangler && npm run test:e2e |
There was a problem hiding this comment.
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?
run: cd packages/wrangler && npm run test:e2e | |
run: npm run -w wrangler test:e2e |
packages/wrangler/package.json
Outdated
@@ -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", |
There was a problem hiding this comment.
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?
if (n === 0) { | ||
await promise(); | ||
} else { | ||
try { | ||
await promise(); | ||
} catch { | ||
await setTimeout(2_000); | ||
return retry(promise, n - 1); | ||
} | ||
} |
There was a problem hiding this comment.
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`; |
There was a problem hiding this comment.
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:
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Interestingly I ran this locally and got:
Note it says that two snapshots failed, but does not tell me which... |
I think these are snapshot failures that are caught by |
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 ofworkerd
—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:
[ ] Changeset (Changeset guidelines)Reviewer is to perform the following, as applicable: