2020-08-24 22:13:29 +00:00
# Insomnia Smoke Tests
2021-03-16 23:30:21 +00:00
This project contains the smoke testing suite for Insomnia and Inso.
2020-12-17 11:54:30 +00:00
2021-12-17 12:05:14 +00:00
Tests for the Electron app are written using [Playwright ](https://github.com/microsoft/playwright ) while tests for the CLI use [execa ](https://github.com/sindresorhus/execa ).
2020-12-17 11:54:30 +00:00
## Structure
2022-02-18 12:47:41 +00:00
| Folder | Purpose |
| ------------ | --------------------------------- |
| `/cli` | tests for inso |
| `/tests` | tests for Insomnia |
| `/playwright` | test helpers |
| `/server` | Express server used by the tests |
| `/fixtures` | data used by tests and the server |
2020-12-17 11:54:30 +00:00
2022-02-18 12:47:41 +00:00
## Run Insomnia app smoke tests
2020-12-17 11:54:30 +00:00
2022-02-18 12:47:41 +00:00
### Development method
2020-12-17 11:54:30 +00:00
2022-02-18 12:47:41 +00:00
In one terminal run the watcher
2020-12-17 11:54:30 +00:00
2021-08-27 03:44:01 +00:00
```shell
2022-02-18 12:47:41 +00:00
npm run watch:app # Run watcher
```
In a second terminal run/debug/step through smoke tests
```shell
# Run tests
npm run test:smoke:dev
# Debug tests with playwright logs
DEBUG=pw:api npm run test:smoke:dev
# Debug tests with insomnia console logs
DEBUG=pw:browser npm run test:smoke:dev
2022-03-07 13:10:35 +00:00
# Debug tests with webserver console logs
DEBUG=pw:WebServer npm run test:smoke:dev
2022-02-18 12:47:41 +00:00
# Step through tests with playwright inspector
PWDEBUG=1 npm run test:smoke:dev
2020-12-17 11:54:30 +00:00
```
2022-02-18 12:47:41 +00:00
### Build and package methods
It's possible to run the smoke tests for:
- A `build` , the JS bundle that is loaded into an electron client
- A `package` , the executable binary (e.g. `.dmg` or `.exe` )
For `build` :
2020-12-17 11:54:30 +00:00
2021-08-27 03:44:01 +00:00
```shell
2022-03-16 09:36:41 +00:00
npm run app-build # Transpile js bundle
2022-02-18 12:47:41 +00:00
npm run test:smoke:build # Run tests
2020-12-17 11:54:30 +00:00
```
2022-02-18 12:47:41 +00:00
For `package` :
2020-12-17 11:54:30 +00:00
2021-08-27 03:44:01 +00:00
```shell
2022-03-16 09:36:41 +00:00
npm run app-package # Build executable in /packages/insomnia-app/dist
2022-02-18 12:47:41 +00:00
npm run test:smoke:package # Run tests
2020-12-17 11:54:30 +00:00
```
Each of the above commands will automatically run the Express server, so you do not need to take any extra steps.
2022-02-18 12:47:41 +00:00
### Show trace viewer
Each time you run a playwright test a trace.zip will be generated, this is useful for debugging CI. [docs ](https://playwright.dev/docs/trace-viewer )
```shell
# Open a trace viewer for a given test output
npx playwright show-trace packages/insomnia-smoke-test/screenshots/app-can-send-requests/trace.zip
# Alternatively you can upload this trace to https://trace.playwright.dev/
```
2022-02-28 15:28:02 +00:00
### Using the Playwright VS Code extension
You can also use the [playwright extension ](https://marketplace.visualstudio.com/items?itemName=ms-playwright.playwright ) to run and debug tests directly from VS Code.
With the extension installed, in a terminal, run the watcher
```shell
npm run watch:app
```
You can now run and debug playwright tests, either from the `Testing` tab, or by going into one of the test files and clicking the run button.
If no tests appear, you may need to run "Refresh playwright tests". This can be done from the command palette, or by using the button at the top of the `Testing` tab.
2022-02-18 12:47:41 +00:00
## Run Inso CLI smoke tests
```shell
npm run inso-package # Package the Inso CLI binaries
npm run test:smoke:cli # Run CLI tests
```
2020-12-17 11:54:30 +00:00
2022-02-18 12:47:41 +00:00
### Write Inso CLI smoke tests
2020-12-17 11:54:30 +00:00
2021-12-17 12:05:14 +00:00
In order to run CLI tests for development, open two terminal tabs in `packages/insomnia-smoke-test` :
2021-08-27 03:44:01 +00:00
```shell
2020-12-17 11:54:30 +00:00
# In the first tab, serve the Express API
npm run serve
# In the second tab, run your tests
npm run cli # Run CLI tests
```
This will allow you to write and monitor the server separately from each test, speeding up the development cycle.
2022-03-16 12:05:12 +00:00
### Debug Inso CLI api test in watch mode
This is helpful for debugging failing api tests and changing the send-request abstraction
From project root, in seperate terminals:
```sh
# start smoke test api
npx lerna --scope insomnia-smoke-test exec 'npm run serve'
# watch send-request
npx lerna --scope insomnia-app exec 'npm run build:sr -- --watch'
# watch inso
npx lerna --scope insomnia-inso exec 'npm run start'
# run api test
$PWD/packages/insomnia-inso/bin/inso run test "Echo Test Suite" --src $PWD/packages/insomnia-smoke-test/fixtures/inso-nedb --env Dev --verbose
```
2020-12-17 11:54:30 +00:00
## General guidelines
### Data
2021-08-27 03:44:01 +00:00
2020-12-17 11:54:30 +00:00
Individual tests will automatically run against a clean Insomnia data directory to keep data isolated.
### Dependencies
2021-08-27 03:44:01 +00:00
2020-12-17 11:54:30 +00:00
A test should not depend on any external services unless absolutely necessary. If a particular endpoint is required (eg. for authentication or a specific content type), implement a new endpoint in `/server` .
2021-10-06 22:01:43 +00:00
## Working with fixtures
### How to update the inso-nedb fixture
In order to update the inso-nedb fixutre you need to launch Insomnia using the inso-nedb directory. To do this, set the INSOMNIA_DATA_PATH environment variable and launch from the command line.
#### MacOS
```bash
INSOMNIA_DATA_PATH=packages/insomnia-smoke-test/fixtures/inso-nedb /Applications/Insomnia.app/Contents/MacOS/Insomnia
```
#### Linux
TODO
#### Windows
TODO
After making your changes, be sure to relaunch the app one more time from the command line, so that Insomnia compacts the database. The .gitignore file will explicity ignore certain database files, to keep the directory size down and avoid prevent data leakage in case you are signed in to the app when launching with this database.
### How to run inso with the inso-nedb fixture locally?
Set the `--src packages/insomnia-smoke-test/fixtures/inso-nedb` flag
```bash
# if installed globally
inso --src ...
# using the package bin
./packages/insomnia-inso/bin/inso --src ...
# using a binary
./packages/insomnia-inso/binaries/insomnia-inso --src ...
```