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 basic smoke tests #2796

Merged
merged 16 commits into from
Mar 21, 2023
Merged

Add basic smoke tests #2796

merged 16 commits into from
Mar 21, 2023

Conversation

penalosa
Copy link
Contributor

@penalosa penalosa commented Feb 24, 2023

What this PR solves / how to test:

Adds (basic) e2e smoke tests as a pre-release check for Wrangler. Run with CLOUDFLARE_ACCOUNT_ID=$TEST_ACCOUNT_ID npm -w wrangler run test:e2e.

By default, this runs npx wrangler@beta, which can be customised using the WRANGLER environment variable

Associated docs issues/PR:

  • [insert associated docs issue(s)/PR(s)]

Author has included the following, where applicable:

  • Tests
  • Changeset

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

Fixes # [insert issue number].

@penalosa penalosa requested a review from a team as a code owner February 24, 2023 19:56
@changeset-bot
Copy link

changeset-bot bot commented Feb 24, 2023

⚠️ No Changeset found

Latest commit: effaf9e

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 Feb 24, 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/4472098604/npm-package-wrangler-2796

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

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

Or you can use npx with this latest build directly:

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

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

@@ -0,0 +1,9 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels a bit brittle. We now have one TS file in this folder that is built with this TS config, but then a load of others that use the top level.
If this script is fundamentally different, then perhaps we should have two folders?
Otherwise I think we should try to keep all these source files compiling with the same config.

@@ -65,7 +65,8 @@
"start": "npm run bundle && cross-env NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
"test": "npm run assert-git-version && jest --silent=false --verbose=true --forceExit",
"test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch",
"test:ci": "npm run test -- --verbose=true --coverage"
"test:ci": "npm run test -- --verbose=true --coverage",
"test:smoke": "esbuild --bundle scripts/smoke-test.ts --outfile=scripts/smoke-test.mjs --platform=node --format=esm && zx scripts/smoke-test.mjs && rm scripts/smoke-test.mjs"
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 we should not be polluting the scripts folder with generated files, even if they are gitignored. Can we put these in some dist-... folder that is gitignored?

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, I note that other scripts are just compiled on demand using:

node -r esbuild-register ...

Copy link
Contributor

@mrbbot mrbbot left a comment

Choose a reason for hiding this comment

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

Nice! The zx package looks pretty cool, but it's pretty big. Did you consider any alternatives?

packages/wrangler/scripts/smoke-test.ts Outdated Show resolved Hide resolved
packages/wrangler/scripts/smoke-test.ts Outdated Show resolved Hide resolved
packages/wrangler/scripts/smoke-test.ts Outdated Show resolved Hide resolved
@penalosa
Copy link
Contributor Author

penalosa commented Mar 1, 2023

@cloudflare/wrangler This has changed a fair amount—I've moved everything to vitest and shellac, and into an e2e folder

Comment on lines 2 to 16
return npmStripTimings(
removeWorkersDev(
removeUUID(
normalizeErrorMarkers(
replaceByte(
stripTrailingWhitespace(
normalizeSlashes(
normalizeTempDirs(stripTimings(removeVersionHeader(stdout)))
)
)
)
)
)
)
);
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a lot of nesting but I love the composability 😅 , maybe something like this would be nicer?

Suggested change
return npmStripTimings(
removeWorkersDev(
removeUUID(
normalizeErrorMarkers(
replaceByte(
stripTrailingWhitespace(
normalizeSlashes(
normalizeTempDirs(stripTimings(removeVersionHeader(stdout)))
)
)
)
)
)
)
);
const functions = [
removeWorkersDev,
removeUUID,
...
];
for (const f of functions) stdout = f(stdout);
return stdout;

Copy link
Contributor

Choose a reason for hiding this comment

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

I am in favor of some sort of refactor.

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 also replacing the other normalizeOutput function for the rest of the tests? If not we should refactor that one the same way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this is intentionally kept separate from the jest tests

`;
expect(stdout).toMatchInlineSnapshot(`
"Using npm as package manager.
✨ Created ${workerName}/wrangler.toml
Copy link
Contributor

@mrbbot mrbbot Mar 1, 2023

Choose a reason for hiding this comment

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

How does interpolation interact with toMatchInlineSnapshot()? Do you have to add the ${...}s back when updating the snapshot?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, it is generally not encouraged to have dynamic snapshots like this.

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've added an explicit replacers option to runIn which should make this simpler

packages/wrangler/e2e/publish.test.ts Outdated Show resolved Hide resolved
packages/wrangler/e2e/publish.test.ts Show resolved Hide resolved
packages/wrangler/e2e/r2.test.ts Outdated Show resolved Hide resolved
packages/wrangler/e2e/util.ts Outdated Show resolved Hide resolved
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.

Discussing file naming internally.

packages/wrangler/e2e/util.ts Outdated Show resolved Hide resolved
packages/wrangler/e2e/vite.config.ts Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 3, 2023

Codecov Report

Merging #2796 (effaf9e) into main (8b81abd) will decrease coverage by 0.41%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2796      +/-   ##
==========================================
- Coverage   73.94%   73.54%   -0.41%     
==========================================
  Files         167      166       -1     
  Lines       10295    10397     +102     
  Branches     2748     2779      +31     
==========================================
+ Hits         7613     7646      +33     
- Misses       2682     2751      +69     

see 21 files with indirect coverage changes

packages/wrangler/e2e/helpers/setup.ts Show resolved Hide resolved
packages/wrangler/e2e/helpers/normalise.ts Outdated Show resolved Hide resolved
packages/wrangler/e2e/publish.test.ts Outdated Show resolved Hide resolved
packages/wrangler/e2e/r2.test.ts Show resolved Hide resolved
packages/wrangler/e2e/tsconfig.json Outdated Show resolved Hide resolved
packages/wrangler/e2e/tsconfig.json Outdated Show resolved Hide resolved
packages/wrangler/e2e/helpers/normalise.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@mrbbot mrbbot left a comment

Choose a reason for hiding this comment

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

Apologies for the delayed review, looks really good! :) Once comment about Windows compatibility, but other than that... ✅

const CF_ID = `CLOUDFLARE_ACCOUNT_ID=${process.env.CLOUDFLARE_ACCOUNT_ID}`;
const WRANGLER = process.env.WRANGLER ?? `npx wrangler@beta`;

const RUN = `${CF_ID} ${WRANGLER}`;
Copy link
Contributor

@mrbbot mrbbot Mar 21, 2023

Choose a reason for hiding this comment

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

This won't work on Windows. Is there any way we can specify environment variables with shellac? Does it inherit process.env if we modified that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is definitely a concern. I'll merge this for now, but we should loop back on Windows support soon.

@penalosa penalosa merged commit e062180 into main Mar 21, 2023
@penalosa penalosa deleted the penalosa/smoke-tests branch March 21, 2023 12:18
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