Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/wizard-e2e.yml
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"
1 change: 1 addition & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"packages/mcp-server-mocks/src/fixtures/**",
"packages/mcp-core/src/ui/chart-app.generated.ts",
"packages/codemod-cli3to4/tests/**",
"packages/cli/test/wizard-e2e/test-applications/**",
"**/worker-configuration.d.ts",
"**/tsconfig*.json"
]
Expand Down
3 changes: 2 additions & 1 deletion .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"**/tsconfig*.json",
"packages/mcp-server-mocks/src/fixtures/**",
"packages/mcp-core/src/ui/chart-app.generated.ts",
"packages/codemod-cli3to4/tests/**"
"packages/codemod-cli3to4/tests/**",
"packages/cli/test/wizard-e2e/test-applications/**"
],
"rules": {
"no-unused-vars": [
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"test:unit": "node --experimental-strip-types --import ./script/require-shim.mjs script/generate.ts docs sdk && vitest run test/lib test/commands test/types test/script --coverage",
"test:changed": "node --experimental-strip-types --import ./script/require-shim.mjs script/generate.ts docs sdk && vitest run --changed",
"test:e2e": "pnpm ts script/prepare-e2e-bundle.ts && vitest run test/e2e",
"test:wizard-e2e": "pnpm ts script/prepare-e2e-bundle.ts && vitest run -c test/wizard-e2e/vitest.config.ts",
"generate": "node --experimental-strip-types --import ./script/require-shim.mjs script/generate.ts docs sdk",
"generate:sdk": "node --experimental-strip-types --import ./script/require-shim.mjs script/generate.ts sdk",
"generate:skill": "node --experimental-strip-types --import ./script/require-shim.mjs script/generate.ts skill",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"compilerOptions": {
"lib": ["ESNext", "DOM"]
},
"include": ["**/*.ts", "**/*.tsx"]
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["wizard-e2e/test-applications"]
}
62 changes: 62 additions & 0 deletions packages/cli/test/wizard-e2e/README.md
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.
22 changes: 22 additions & 0 deletions packages/cli/test/wizard-e2e/constants.ts
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;
43 changes: 43 additions & 0 deletions packages/cli/test/wizard-e2e/global-setup.ts
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();
}
63 changes: 63 additions & 0 deletions packages/cli/test/wizard-e2e/help-message.test.ts
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 /);
});
});
Loading
Loading