Repository navigation
test(cli): run sentry wizard e2e tests in toolkit #2547
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
Merged
+2,030
−3
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
949060d
feat(cli): add sentry wizard with Next.js
sentry-junior[bot] 76e162b
feat(cli): add the wizard's shared AST and URL helpers
sentry-junior[bot] 0113841
feat(cli): reject the wizard's removed sign-up flags
sentry-junior[bot] 7e5f894
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] 39e20d5
fix(cli): address review findings in sentry wizard
sentry-junior[bot] c4786b3
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] 2c98751
refactor(cli): reuse existing CLI helpers in the wizard AST utils
sentry-junior[bot] ac6b75d
feat(cli): use positionals and existing CLI flags in sentry wizard
sentry-junior[bot] 4c93aa8
fix(cli): use the credential host for the project issues URL
sentry-junior[bot] d32b3db
test(cli): run sentry wizard e2e tests in toolkit
sentry-junior[bot] 1df9766
Merge remote-tracking branch 'origin/feat/cli-wizard-scaffold' into f…
sentry-junior[bot] b7f2f6b
test(cli): run the wizard e2e tests with the positional command line
sentry-junior[bot] 2f2f91a
fix(mcp): regenerate the chart app after the for…of conversion
sentry-junior[bot] f0a48de
Merge remote-tracking branch 'origin/feat/cli-wizard-scaffold' into f…
sentry-junior[bot] 3259a4b
Merge commit 'f0a48dee68470690517ba652f224f6f6f8587528' into feat/cli…
sentry-junior[bot] b1008cd
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-e2e
sentry-junior[bot] 8bcd010
test(cli): give wizard e2e hooks room for every step timeout
sentry-junior[bot] d3ccf65
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-e2e
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| name: Wizard E2E | ||
|
|
||
| # `sentry wizard` end-to-end tests: each job sets up Sentry in a real | ||
| # framework app, installs its packages, and builds and runs it. They take | ||
| # minutes per app, so they run only when the wizard or its tests change. | ||
| on: | ||
| pull_request: | ||
| paths: | ||
| - "packages/cli/src/commands/wizard.ts" | ||
| - "packages/cli/src/lib/wizard/**" | ||
| - "packages/cli/test/wizard-e2e/**" | ||
| - "packages/cli/test/mocks/**" | ||
| - ".github/workflows/wizard-e2e.yml" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| wizard-e2e: | ||
| name: Wizard E2E (${{ matrix.test }}) | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 20 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| # One job per file in packages/cli/test/wizard-e2e/. | ||
| test: | ||
| - help-message | ||
| - nextjs-14 | ||
| - nextjs-15 | ||
| - nextjs-16 | ||
| env: | ||
| SENTRY_CLIENT_ID: test-client-id | ||
| SENTRY_CLI_NO_TELEMETRY: "1" | ||
| steps: | ||
| - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 | ||
| - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 | ||
| with: | ||
| node-version: "22.23.4" | ||
| cache: pnpm | ||
| - run: pnpm install --frozen-lockfile | ||
| - name: Run ${{ matrix.test }} | ||
| env: | ||
| TEST_FILE: test/wizard-e2e/${{ matrix.test }}.test.ts | ||
| run: pnpm --filter sentry run test:wizard-e2e "$TEST_FILE" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # `sentry wizard` end-to-end tests | ||
|
|
||
| Each test copies an app from `test-applications/` to a temporary git | ||
| repository, runs the CLI's `sentry wizard` in it while answering its prompts, | ||
| and then checks the files the wizard wrote and that the app still builds and | ||
| runs. They were moved here from getsentry/sentry-wizard's `e2e-tests/`. | ||
|
|
||
| The wizard never talks to sentry.io. `global-setup.ts` starts a local mock | ||
| Sentry API (the routes in `../mocks/routes.ts`, plus org auth token creation). | ||
| Every run gets its URL in `SENTRY_URL` and its token in `SENTRY_AUTH_TOKEN`, | ||
| and `getWizardCommand()` runs `sentry wizard test-org/test-project <integration>`. | ||
| For a run without a project, pass `env: { SENTRY_SPOTLIGHT: "1" }` to | ||
| `withEnv()` and run `["wizard", <integration>]`. No secrets are needed. | ||
|
|
||
| ## Running | ||
|
|
||
| ```bash | ||
| # From packages/cli. Builds the npm bundle, then runs every test file. | ||
| pnpm run test:wizard-e2e | ||
|
|
||
| # One file | ||
| pnpm run test:wizard-e2e test/wizard-e2e/nextjs-15.test.ts | ||
| ``` | ||
|
|
||
| The tests run the npm bundle (`dist/bin.cjs`), or the CLI in | ||
| `SENTRY_CLI_BINARY` when set. They need network access for the apps' package | ||
| installs, and the package managers the tests pick (npm, pnpm and Yarn v1). | ||
|
|
||
| - `SENTRY_WIZARD_E2E_DEBUG=true` streams the wizard's output. | ||
| - `SENTRY_WIZARD_E2E_KEEP_TEMP=true` keeps the temporary app directories. | ||
|
|
||
| `test:unit` and `test:e2e` don't run these. In CI, `wizard-e2e.yml` runs one | ||
| job per test file on pull requests that change the wizard or these tests, and | ||
| on manual dispatch. Add a new test file to its matrix. | ||
|
|
||
| ## Writing tests | ||
|
|
||
| Isolate each wizard run in its own `describe` block with | ||
| `createIsolatedTestEnv()`, run the wizard in `beforeAll`, and clean up in | ||
| `afterAll`. `withEnv().defineInteraction()` scripts the answers, in the shape | ||
| of the `clifty` builder the sentry-wizard tests used: | ||
|
|
||
| ```ts | ||
| const { projectDir, cleanup } = createIsolatedTestEnv("nextjs-15-test-app"); | ||
|
|
||
| beforeAll(async () => { | ||
| wizardExitCode = await withEnv({ cwd: projectDir }) | ||
| .defineInteraction() | ||
| .whenAsked("Please select your package manager.") | ||
| .respondWith(KEYS.ENTER) | ||
| .expectOutput("Successfully installed the Sentry Next.js SDK!") | ||
| .run(getWizardCommand("nextjs")); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| cleanup(); | ||
| }); | ||
| ``` | ||
|
|
||
| Each step waits for its text after the previous step's match, so list prompts | ||
| in the order the wizard asks them. Test apps have no lockfiles, so the wizard | ||
| picks the package manager the test selects. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /** | ||
| * The org, project, and tokens of the mock Sentry API that the wizard e2e | ||
| * tests run against. No vitest imports, so `global-setup.ts` can load it. | ||
| */ | ||
|
|
||
| import { | ||
| TEST_DSN, | ||
| TEST_ORG, | ||
| TEST_PROJECT, | ||
| TEST_TOKEN, | ||
| } from "../mocks/routes.js"; | ||
|
|
||
| /** The org, project, and tokens the mock Sentry API serves. */ | ||
| export const TEST_ARGS = { | ||
| /** The CLI's login token, which the mock API accepts. */ | ||
| LOGIN_TOKEN: TEST_TOKEN, | ||
| /** The org auth token the mock API mints for source map uploads. */ | ||
| AUTH_TOKEN: "sntrys_wizard-e2e-org-auth-token", | ||
| PROJECT_DSN: TEST_DSN, | ||
| ORG_SLUG: TEST_ORG, | ||
| PROJECT_SLUG: TEST_PROJECT, | ||
| } as const; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * Starts one mock Sentry API for every wizard e2e test, so a wizard run can | ||
| * log in, read its preselected org and project, and mint an org auth token | ||
| * without a Sentry account. Tests read its URL with `inject("sentryUrl")`. | ||
| */ | ||
|
|
||
| import type { TestProject } from "vitest/node"; | ||
| import { apiRoutes } from "../mocks/routes.js"; | ||
| import { createMockServer } from "../mocks/server.js"; | ||
| import { TEST_ARGS } from "./constants.js"; | ||
|
|
||
| declare module "vitest" { | ||
| export interface ProvidedContext { | ||
| /** Origin of the mock Sentry API, for `SENTRY_URL`. */ | ||
| sentryUrl: string; | ||
| } | ||
| } | ||
|
|
||
| export default async function setup(project: TestProject): Promise<() => void> { | ||
| const server = createMockServer( | ||
| [ | ||
| ...apiRoutes, | ||
| { | ||
| method: "POST", | ||
| path: "/api/0/organizations/:orgSlug/org-auth-tokens/", | ||
| status: 201, | ||
| response: { | ||
| id: "1", | ||
| name: "Sentry Wizard", | ||
| scopes: ["org:ci"], | ||
| tokenLastCharacters: TEST_ARGS.AUTH_TOKEN.slice(-4), | ||
| dateCreated: "2024-01-01T00:00:00.000Z", | ||
| dateLastUsed: null, | ||
| token: TEST_ARGS.AUTH_TOKEN, | ||
| }, | ||
| }, | ||
| ], | ||
| { validTokens: [TEST_ARGS.LOGIN_TOKEN] }, | ||
| ); | ||
| await server.start(); | ||
| project.provide("sentryUrl", server.url); | ||
| return () => server.stop(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { runCli } from "./utils.js"; | ||
|
|
||
| describe("sentry wizard --help", () => { | ||
| it("prints the up to date help", () => { | ||
| const { exitCode, stdout } = runCli(["wizard", "--help"]); | ||
|
|
||
| expect(exitCode).toBe(0); | ||
| expect(stdout).toMatchInlineSnapshot(` | ||
| "USAGE | ||
| sentry wizard [<org>/<project>] [<integration>] | ||
| sentry wizard --help | ||
| Set up Sentry in the project in the current directory. The wizard asks you a few questions, installs the Sentry SDK for your framework, writes its configuration, and sets up source map or debug file uploads. | ||
| It logs in with your \`sentry auth login\` account (or starts a login) on the Sentry instance the rest of the CLI uses, and lets you pick or create the Sentry project to send data to. Pass \`<org>/<project>\` first to skip those questions, or \`<org>/\` to pick only the project. Pass an integration, such as \`nextjs\`, to skip the integration picker. Integrations: reactNative, flutter, ios, appleSnapshots, angular, android, nextjs, nuxt, remix, reactRouter, sveltekit, cloudflare, sourcemaps. | ||
| An integration id is never read as a project or org, and a single bare word is always read as an integration. To name a project or org, write it with a \`/\`: \`my-org/my-project\`, \`my-org/\`, or \`/my-project\` (for a project spelled like an integration, \`my-org/nextjs\`). | ||
| Set \`SENTRY_SPOTLIGHT=1\` to set up Spotlight for local development instead, without a Sentry account or login. Use the global \`--verbose\` flag for the wizard's debug output. | ||
| The wizard changes files in your project. To have a coding agent set up Sentry instead, run \`sentry init\`, which prints the agent's setup guide and changes nothing. | ||
| Examples: | ||
| sentry wizard # Pick an integration and a project, then set it up | ||
| sentry wizard nextjs # Set up Next.js, picking the project | ||
| sentry wizard my-org/my-project nextjs # Set up Next.js for a known org and project | ||
| SENTRY_SPOTLIGHT=1 sentry wizard nextjs # Set up Next.js for Spotlight, without a Sentry account | ||
| FLAGS | ||
| -f [--force] Change a project with uncommitted changes without asking, and install the SDK even when the package manager's checks fail [default = false] | ||
| -h --help Print help information and exit | ||
| -- All subsequent inputs should be interpreted as arguments | ||
| ARGUMENTS | ||
| org/project-or-integration... <org>/<project> to set up (skips the project picker), then the integration (skips the integration picker) | ||
| " | ||
| `); | ||
| }); | ||
|
|
||
| // Flags of `npx @sentry/wizard` that `sentry wizard` dropped. `--org` and | ||
| // `--project` still work: every CLI command takes them as hidden flags that | ||
| // set SENTRY_ORG and SENTRY_PROJECT. | ||
| it.each([ | ||
| ["--signup"], | ||
| ["-s"], | ||
| ["--promo-code", "CODE"], | ||
| ["--coming-from", "partner"], | ||
| ["-i", "nextjs"], | ||
| ["--url", "https://sentry.example.com"], | ||
| ["--saas"], | ||
| ["--spotlight"], | ||
| ["--force-install"], | ||
| ["--ignore-git-changes"], | ||
| ["--disable-telemetry"], | ||
| ["--debug"], | ||
| ])("rejects the removed flag %s", (...flag) => { | ||
| const { exitCode, stderr } = runCli(["wizard", ...flag]); | ||
|
|
||
| expect(exitCode).not.toBe(0); | ||
| expect(stderr).toMatch(/^No (flag|alias) registered for /); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.