@@ -32,12 +32,8 @@ modifiers that can be used in (`*.test.ts`).
3232
3333#### Helpers
3434
35- - ` startWizardInstance ` - Starts a new instance of ` WizardTestEnv ` .
36-
37- - ` initGit ` - Initializes a temporary git repository in the test project.
38- - ` cleanupGit ` - Cleans up the temporary git repository in the test project.
39- - ` revertLocalChanges ` - Reverts local changes (git tracked or untracked) in the
40- test project.
35+ - ` createIsolatedTestEnv ` - creates a new isolated test env by copying the test app to a temporary directory.
36+ Also initializes git in the tmp dir
4137
4238- ` createFile ` - Creates a file (optionally with content) in the test project.
4339- ` modifyFile ` - Modifies a file in the test project.
@@ -61,12 +57,6 @@ modifiers that can be used in (`*.test.ts`).
6157- ` checkSentryProperties ` - Checks if the Flutter ` sentry.properties ` file
6258 contains the auth token
6359
64- #### ` WizardTestEnv `
65-
66- ` WizardTestEnv ` is a class that can be used to run the Sentry Wizard in a test
67- environment. It provides methods to run the wizard with specific arguments and
68- stdio.
69-
7060## Running Tests Locally
7161
7262First, you need to create a ` .env ` file set the environment variables from the
@@ -82,6 +72,65 @@ To run a specific test application
8272
8373## Writing Tests
8474
85- Each test file should contain a single test suite that tests the Sentry Wizard
86- for a specific framework. The test suite should contain a ` beforeAll ` and
87- ` afterAll ` function that starts and stops the test application respectively.
75+ Each test file should test the Sentry Wizard for a specific framework and project.
76+
77+ The test suite may contain multiple wizard runs but for consistency, each scenario must be
78+ isolated via ` createIsolatedTestEnv ` . You can most easily do this by using a ` describe ` block
79+ per wizard run.
80+
81+ For every ` describe ` block, isolate the test, run the wizard in ` beforeAll ` , ` test ` what you
82+ want to test and clean up the tmp dir in ` afterAll ` :
83+
84+ ``` ts
85+ describe (' no sentry files present' , () => {
86+ const {projectDir, cleanup} = createIsolatedTestEnv ();
87+
88+ beforeAll (() => {
89+ await runWizard (projectDir );
90+ });
91+
92+ afterAll (() => {
93+ cleanup ()
94+ })
95+ })
96+
97+ describe (' with sentry files present' , () => {
98+ const {projectDir, cleanup} = createIsolatedTestEnv ();
99+
100+ beforeAll (() => {
101+ addSentryFiles (projectDir );
102+ await runWizard (projectDir );
103+ });
104+
105+ afterAll (() => {
106+ cleanup ()
107+ })
108+ })
109+ ```
110+
111+ ### Running the wizard
112+
113+ To define how a wizard run should look like (i.e. which responses the "user" makes) on
114+ wizard prompots, use ` clifty ` . Clifty's ` run ` method starts a new process to run the wizard
115+ with the predefined interaction and returns the processe's exit code.
116+ You can use this to check for a successful wizard run.
117+
118+ ``` ts
119+ import { KEYS , withEnv } from ' clifty' ;
120+
121+ const wizardExitCode = await withEnv ({
122+ cwd: projectDir ,
123+ })
124+ .defineInteraction ()
125+ .whenAsked (' Do you want to enable Tracing' )
126+ .respondWith (KEYS .ENTER )
127+ .expectOutput (' Added Sentry code to sentry.client.ts' )
128+ .run (getWizardCommand (Integrations .nextjs ));
129+
130+ // ...
131+
132+ test (' wizard ran successfully' , () => {
133+ expect (wizardExitCode ).toBe (0 );
134+ })
135+ ```
136+
0 commit comments