You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h1 id="exportjest">🤖 ️Generate Jest tests with Pythagora and GPT-4</h1>
62
68
63
-
```bash
64
-
npx pythagora --export
65
-
```
66
-
If you don't have recorded login endpoint it will ask you to run:
69
+
You can export any Pythagora test to Jest with GPT-4. To see how it works, you can watch [the full demo video here](https://youtu.be/YxzvljVyaEA).
70
+
71
+
## What are Jest integration tests made of
72
+
73
+
- **Database setup** (before a test is run)
74
+
- during the export to Jest, Pythagora saves all database documents in the `pythagora_tests/exported_tests/data` folder as a JSON file
75
+
- in the `beforeEach` function, these documents are restored into the database so that the database is in the same state as it was when the test was recorded
76
+
- Pythagora has built-in functions to work with the database but incase you want to use your own and completely separate Jest tests from Pythagora, use the `global-setup.js` file in which you can set up your own ways to populate the database, get a collection and clear the database
77
+
- **User authentication** (when the endpoint requires authentication)
78
+
- the first time you run the export, Pythagora will create `auth.js` file
79
+
- it is used inside `beforeEach`functionto retrieve the authentication token so that API requests (that require authentication) can be executed
80
+
- **Test**
81
+
- tests check the response from the API and if the database is updated correctly
82
+
83
+
## How to export Pythagora tests to Jest
84
+
85
+
1. First, you need to tell Pythagora what is the login endpoint. You can do that by running:
86
+
87
+
```bash
88
+
npx pythagora --export-setup
89
+
```
90
+
91
+
2. After that, just run Pythagora capture command and log into the app so the login route gets captured.
92
+
93
+
```bash
94
+
npx pythagora --init-command "my start command" --mode capture
95
+
```
96
+
97
+
3. Exporting to Jest is done with GPT-4 so you either need to have OpenAI API key with GPT-4 access or a Pythagora API key which you can get [here](https://mailchi.mp/f4f4d7270a7a/api-waitlist). Once you have the API key, you're ready to export tests to Jest by running:
Exported tests will be available in the `pythagora_tests/exported_tests` folder.
114
+
115
+
NOTE: Pythagora uses GPT-4 8k model so some tests that do too many things during the processing might exceed the 8k token limit. To check which tests you can export to Jest, you can run:
67
116
68
117
```bash
69
-
npx pythagora --export-setup
118
+
npx pythagora --tests-eligible-for-export
70
119
```
71
-
after which you just have to run capture command again and go to endpoint login. Once that is done you are ready to export your tests to Jest.
120
+
72
121
<br>
73
122
<br>
74
123
<h1 id="demo">🎞 Demo</h1>
@@ -82,6 +131,8 @@ Here are some demo videos that can help you get started.
0 commit comments