Skip to content

Commit 096a0ec

Browse files
committed
update Readme.md with documentation for exporting tests to Jest
1 parent eb67dd4 commit 096a0ec

File tree

1 file changed

+52
-7
lines changed

1 file changed

+52
-7
lines changed

README.md

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ Pythagora records all requests to endpoints of your app with the response and ev
4242
<b>NOTES: </b>
4343
- to stop the capture, you can exit the process like you usually do (Eg. `Ctrl + C`)
4444
- on Windows make sure to run all commands using `Git Bash` and not `Power Shell` or anything similiar
45-
<br>
45+
46+
<br>
47+
<br>
4648
<h1 id="executingtests">▶️ Running tests</h1>
4749
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.
4850

@@ -55,6 +57,20 @@ So, after you captured all requests you want, you just need to change the mode p
5557
```
5658

5759
<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:
62+
63+
```bash
64+
npx pythagora --export
65+
```
66+
If you don't have recorded login endpoint it will ask you to run:
67+
68+
```bash
69+
npx pythagora --export-setup
70+
```
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.
72+
<br>
73+
<br>
5874
<h1 id="demo">🎞 Demo</h1>
5975
6076
Here are some demo videos that can help you get started.
@@ -191,10 +207,42 @@ That's it! You are ready to go and all your API requests with authentication sho
191207
192208
<br><br>
193209
<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.
210+
Each captured test is saved in <strong><i>"pythagora_tests"</i></strong> directory at the root of your repository.
211+
<br><br>
212+
<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>
213+
214+
<ul>
215+
<li>pythagora_tests
216+
<ul>
217+
<li>exported_tests <span style="color: green;">// folder containing all exported Jest tests</span>
218+
<ul>
219+
<li>data <span style="color: green;">// folder containing Jest test data</span>
220+
<ul>
221+
<li>JestTest1.json <span style="color: green;">// this is data that is populated in DB for JestTest1.test.js</span></li>
222+
<li>JestTest2.json <span style="color: green;">// this is data that is populated in DB for JestTest2.test.js</span></li>
223+
<li>...</li>
224+
</ul>
225+
</li>
226+
<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>
228+
<li>JestTest1.test.js <span style="color: green;">// this is an exported Jest test</span></li>
229+
<li>JestTest2.test.js</li>
230+
<li>...</li>
231+
</ul>
232+
</li>
233+
<li>pythagoraTest1.json <span style="color: green;">// this is a Pythagora test</span></li>
234+
<li>pythagoraTest2.json</li>
235+
<li>...</li>
236+
</ul>
237+
</li>
238+
</ul>
239+
</details>
240+
<br><br>
195241
Each JSON file in this repository represents one endpoint that was captured and each endpoint can have many captured tests.
196242
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
197243
is stored in this object. Here is an example of a test object.
244+
<br><br>
245+
<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>
198246
199247
```json
200248
{
@@ -258,11 +306,8 @@ is stored in this object. Here is an example of a test object.
258306
"createdAt": "2023-02-22T14:57:52.362Z" // date when the test was captured
259307
}
260308
```
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:
263-
```
264-
npx pythagora --rename-tests
265-
```
309+
310+
</details>
266311
267312
<br><br>
268313
<h1 id="support">🤔️ FAQ</h1>

0 commit comments

Comments
 (0)