Skip to content

Commit 6c743ec

Browse files
author
Zvonimir Sabljic
committed
Added docs for exporting tests to Jest
1 parent d0270bb commit 6c743ec

File tree

1 file changed

+61
-10
lines changed

1 file changed

+61
-10
lines changed

README.md

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<p align=center>
22
<picture>
33
<source media="(prefers-color-scheme: dark)" srcset="https://user-images.githubusercontent.com/10895136/228003796-7e3319ad-f0b1-4da9-a2d0-6cf67ccc7a32.png">
4-
<img height="200px" alt="Text changing depending on mode. Light: 'So light!' Dark: 'So dark!'" src="https://user-images.githubusercontent.com/10895136/228003796-7e3319ad-f0b1-4da9-a2d0-6cf67ccc7a32.png">
4+
<img height="200px" alt="Pythagora Logo" src="https://user-images.githubusercontent.com/10895136/228003796-7e3319ad-f0b1-4da9-a2d0-6cf67ccc7a32.png">
55
</picture>
66
</p>
77
<p align=center>
88
Developers spend 20-30% of their time writing tests!
99
</p>
1010
<h3 align="center">✊ Pythagora creates automated tests for you by analysing server activity ✊</h3>
11+
<h3 align="center"><a href="#exportjest"> 🤖 Generate Jest integration tests with GPT-4 and Pythagora 🤖</a></h3>
1112
<br>
1213
<p align="center">🌟 As an open source tool, it would mean the world to us if you starred Pythagora repo 🌟<br>🙏 Thank you 🙏</p>
1314
<br>
@@ -57,18 +58,66 @@ So, after you captured all requests you want, you just need to change the mode p
5758
```
5859

5960
<br><br>
60-
<h1 id="exportjest">🗄️ Export tests to Jest</h1>
61-
If you want to export recorded Pythagora tests to Jest tests so you can more easily read and edit them you can do so by running this command:
61+
<p align=center>
62+
<picture>
63+
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/Pythagora-io/pythagora/assets/10895136/41f349ec-c6fe-4357-8c92-db09b88d2b8e">
64+
<img height="100px" alt="OpenAI logo" src="https://github.com/Pythagora-io/pythagora/assets/10895136/41f349ec-c6fe-4357-8c92-db09b88d2b8e">
65+
</picture>
66+
</p>
67+
<h1 id="exportjest">🤖 ️Generate Jest tests with Pythagora and GPT-4</h1>
6268

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 in case 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` function to 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:
98+
99+
```bash
100+
npx pythagora --export --test-id <TEST_ID> --openai-api-key <YOUR_OPENAI_API_KEY>
101+
```
102+
or
103+
```bash
104+
npx pythagora --export --test-id <TEST_ID> --pythagora-api-key <YOUR_PYTHAGORA_API_KEY>
105+
```
106+
107+
4. To run the exported tests, run:
108+
109+
```bash
110+
npx pythagora --mode jest
111+
```
112+
113+
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:
67116
68117
```bash
69-
npx pythagora --export-setup
118+
npx pythagora --tests-eligible-for-export
70119
```
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+
72121
<br>
73122
<br>
74123
<h1 id="demo">🎞 Demo</h1>
@@ -82,6 +131,8 @@ Here are some demo videos that can help you get started.
82131
<p align=center>
83132
<a target="_blank" href="https://youtu.be/YxzvljVyaEA">Pythagora Demo (4 min)</a>
84133
<br>
134+
<a target="_blank" href="https://youtu.be/YxzvljVyaEA">Generate Jest tests with Pythagora and GPT-4 (4 min)</a>
135+
<br>
85136
<a target="_blank" href="https://youtu.be/ferEJsqBHqw">Pythagora Tech Deep Dive (16 min)</a>
86137
<br>
87138
<a target="_blank" href="https://youtu.be/opQP8NMCiPw">Dev Workflow With Pythagora (4 min)</a>
@@ -224,7 +275,7 @@ Each captured test is saved in <strong><i>"pythagora_tests"</i></strong> directo
224275
</ul>
225276
</li>
226277
<li>auth.js <span style="color: green;">// here is authentication function that is used in all Jest tests</span></li>
227-
<li>global-setup.js</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>
228279
<li>JestTest1.test.js <span style="color: green;">// this is an exported Jest test</span></li>
229280
<li>JestTest2.test.js</li>
230281
<li>...</li>

0 commit comments

Comments
 (0)