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
Developers spend 20-30% of their time writing tests!
9
9
</p>
10
10
<h3align="center">✊ Pythagora creates automated tests for you by analysing server activity ✊</h3>
11
+
<h3align="center"><ahref="#exportjest"> 🤖 Generate Jest integration tests with GPT-4 and Pythagora 🤖</a></h3>
11
12
<br>
12
13
<palign="center">🌟 As an open source tool, it would mean the world to us if you starred Pythagora repo 🌟<br>🙏 Thank you 🙏</p>
13
14
<br>
@@ -42,7 +43,9 @@ Pythagora records all requests to endpoints of your app with the response and ev
42
43
<b>NOTES: </b>
43
44
- to stop the capture, you can exit the process like you usually do (Eg. `Ctrl + C`)
44
45
- on Windows make sure to run all commands using `Git Bash` and not `Power Shell` or anything similiar
45
-
<br>
46
+
47
+
<br>
48
+
<br>
46
49
<h1 id="executingtests">▶️ Running tests</h1>
47
50
When running tests, it doesn’t matter what database is your Node.js connected to or what is the state of that database. Actually, that database is never touched or used —> instead, Pythagora creates a special, ephemeral pythagoraDb database, which it uses to restore the data before each test is executed, which was present at the time when the test was recorded. Because of this, tests can be run on any machine or environment.
48
51
@@ -55,6 +58,68 @@ So, after you captured all requests you want, you just need to change the mode p
<h1 id="exportjest">🤖 ️Generate Jest tests with Pythagora and GPT-4</h1>
68
+
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://www.youtube.com/watch?v=kHbwX4QVoGY).
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:
116
+
117
+
```bash
118
+
npx pythagora --tests-eligible-for-export
119
+
```
120
+
121
+
<br>
122
+
<br>
58
123
<h1 id="demo">🎞 Demo</h1>
59
124
60
125
Here are some demo videos that can help you get started.
@@ -66,6 +131,8 @@ Here are some demo videos that can help you get started.
<a target="_blank" href="https://www.youtube.com/watch?v=kHbwX4QVoGY">Generate Jest tests with Pythagora and GPT-4 (4 min)</a>
135
+
<br>
69
136
<a target="_blank" href="https://youtu.be/ferEJsqBHqw">Pythagora Tech Deep Dive (16 min)</a>
70
137
<br>
71
138
<a target="_blank" href="https://youtu.be/opQP8NMCiPw">Dev Workflow With Pythagora (4 min)</a>
@@ -191,10 +258,42 @@ That's it! You are ready to go and all your API requests with authentication sho
191
258
192
259
<br><br>
193
260
<h1 id="testdata">🗺️️ Where can I see the tests?</h1>
194
-
Each captured test is saved in<strong><i>pythagora_tests</i></strong> directory at the root of your repository.
261
+
Each captured test is saved in <strong><i>"pythagora_tests"</i></strong> directory at the root of your repository.
262
+
<br><br>
263
+
<details><summary style="background-color: grey; padding: 10px; border: none; border-radius: 4px; cursor: pointer;">Click here to see "pythagora_tests" folder structure explanation:</summary>
264
+
265
+
<ul>
266
+
<li>pythagora_tests
267
+
<ul>
268
+
<li>exported_tests <span style="color: green;">// folder containing all exported Jest tests</span>
269
+
<ul>
270
+
<li>data <span style="color: green;">// folder containing Jest test data</span>
271
+
<ul>
272
+
<li>JestTest1.json <span style="color: green;">// this is data that is populated in DB for JestTest1.test.js</span></li>
273
+
<li>JestTest2.json <span style="color: green;">// this is data that is populated in DB for JestTest2.test.js</span></li>
274
+
<li>...</li>
275
+
</ul>
276
+
</li>
277
+
<li>auth.js <span style="color: green;">// here is authentication function that is used in all Jest tests</span></li>
278
+
<li>global-setup.js<span style="color: green;"> // Jest global setup if you want to use your own functions for running Jest tests</span></li>
279
+
<li>JestTest1.test.js <span style="color: green;">// this is an exported Jest test</span></li>
280
+
<li>JestTest2.test.js</li>
281
+
<li>...</li>
282
+
</ul>
283
+
</li>
284
+
<li>pythagoraTest1.json <span style="color: green;">// this is a Pythagora test</span></li>
285
+
<li>pythagoraTest2.json</li>
286
+
<li>...</li>
287
+
</ul>
288
+
</li>
289
+
</ul>
290
+
</details>
291
+
<br><br>
195
292
Each JSON file in this repository represents one endpoint that was captured and each endpoint can have many captured tests.
196
293
If you open these files, you will see an array in which each object represents a single test. All data that's needed to run a test
197
294
is stored in this object. Here is an example of a test object.
295
+
<br><br>
296
+
<details><summary style="background-color: grey; padding: 10px; border: none; border-radius: 4px; cursor: pointer;">Click here to see example of one recorded Pythagora test:</summary>
198
297
199
298
```json
200
299
{
@@ -258,11 +357,8 @@ is stored in this object. Here is an example of a test object.
258
357
"createdAt": "2023-02-22T14:57:52.362Z" // date when the test was captured
259
358
}
260
359
```
261
-
<b>NOTE:</b> If you used Pythagora version < 0.0.39 tests were stored in files with delimiter "|" and since we added Windows support that is changed to "-_-".
262
-
To update all your tests to work with new version of Pythagora run:
0 commit comments