Skip to content

Commit 02f5bf4

Browse files
authored
inso cli scripting first pass (#7790)
* poc * add header test * fix lint * fix types * make require work * low cost abstraction * test insomnia.sendRequest * remove execa * split tests and improve docs * dynamic import to fix build
1 parent 838d820 commit 02f5bf4

23 files changed

Lines changed: 600 additions & 418 deletions

File tree

.github/workflows/test-cli.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ jobs:
3939
- name : Build Inso
4040
run: npm run build -w insomnia-inso
4141

42+
- name: Run Inso unit tests
43+
run: npm run test:unit -w insomnia-inso
44+
4245
- name: Start test server
4346
run: npm run serve -w insomnia-smoke-test & npx -y wait-on http://localhost:4010
4447

45-
- name: Run Inso bundle tests
48+
- name: Run Inso bundle e2e tests
4649
run: npm run test:bundle -w insomnia-inso
4750

4851
- name: Set Inso CLI variables
@@ -59,7 +62,7 @@ jobs:
5962
env:
6063
VERSION: ${{ steps.inso-variables.outputs.inso-version }}
6164

62-
- name: Run Inso binary tests
65+
- name: Run Inso binary e2e tests
6366
run: npm run test:binary -w insomnia-inso
6467

6568
- name: Create Inso zip/tar/gz artifacts

package-lock.json

Lines changed: 0 additions & 82 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/insomnia-inso/README.md

Lines changed: 109 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,109 @@
1-
<!-- markdownlint-disable heading-style first-line-h1 -->
2-
<!-- markdownlint-disable no-inline-html -->
3-
<div align="center">
4-
<br />
5-
<br />
6-
<img src="https://raw.githubusercontent.com/Kong/insomnia/develop/packages/insomnia-inso/assets/logo.svg" alt=""/>
7-
<h1>
8-
Inso CLI
9-
<br />
10-
<br />
11-
</h1>
12-
<h3>A CLI for <a href="https://insomnia.rest">Insomnia</a></h3>
13-
<pre>npm install --global <a href="https://www.npmjs.com/package/insomnia-inso">insomnia-inso</a></pre>
14-
<img src="https://raw.githubusercontent.com/Kong/insomnia/develop/packages/insomnia-inso/assets/demo.gif" alt=""/>
15-
<br />
16-
</div>
17-
<br />
18-
<!-- markdownlint-enable no-inline-html -->
19-
20-
## Documentation
21-
22-
See the [open-source Inso CLI documentation](https://docs.insomnia.rest/inso-cli/introduction).
1+
# Documentation
2+
3+
How to use [Inso CLI](https://docs.insomnia.rest/inso-cli/introduction).
4+
5+
## Testing
6+
7+
```shell
8+
# unit tests
9+
npm run test:unit
10+
11+
# start smoke test api (required for e2e tests)
12+
npm run serve -w insomnia-smoke-test
13+
14+
# e2e tests for dev bundle
15+
npm run test:bundle
16+
17+
# e2e tests for binary
18+
npm run test:binary
19+
```
20+
21+
## Development
22+
23+
### Getting started
24+
25+
```shell
26+
npm run inso-start
27+
npm run test -w insomnia-inso
28+
# will default to insomnia app database
29+
$PWD/packages/insomnia-inso/bin/inso run test
30+
# will use config, useful for testing with fewer args
31+
$PWD/packages/insomnia-inso/bin/inso -w packages/insomnia-inso/src/db/fixtures/git-repo script runTest
32+
```
33+
34+
### node-libcurl
35+
36+
`Error: The module '.../insomnia/node_modules/@getinsomnia/node-libcurl/lib/binding/node_libcurl.node'
37+
was compiled against a different Node.js version using`
38+
39+
node-libcurl builds for 3 operating systems and two versions of nodejs. insomnia-inso uses the nodejs build and insomnia app uses the electron build. you can switch between them using the following two commands
40+
41+
```shell
42+
# install node version
43+
node_modules/.bin/node-pre-gyp install --update-binary --directory node_modules/@getinsomnia/node-libcurl
44+
# install electron version
45+
node_modules/.bin/node-pre-gyp install --update-binary --directory node_modules/@getinsomnia/node-libcurl --runtime=electron --target=30.0.0
46+
```
47+
48+
## Run CLI Smoke Tests
49+
50+
```shell
51+
# Run CLI tests
52+
npm run test:bundle -w insomnia-inso
53+
# Package the Inso CLI binaries
54+
npm run inso-package
55+
npm run test:binary -w insomnia-inso
56+
```
57+
58+
## Debugging CLI tests using watcher
59+
60+
This is helpful for debugging failing api tests
61+
62+
From project root, in separate terminals:
63+
64+
```sh
65+
# start smoke test api
66+
npm run serve -w insomnia-smoke-test
67+
68+
# watch inso
69+
npm run start -w insomnia-inso
70+
71+
# run api test with dev bundle
72+
$PWD/packages/insomnia-inso/bin/inso run test "Echo Test Suite" --src $PWD/packages/insomnia-smoke-test/fixtures/inso-nedb --env Dev --verbose
73+
```
74+
75+
## How to debug pkg
76+
77+
```sh
78+
# run modify package command and then a unit test
79+
npm run package -w insomnia-inso && \
80+
$PWD/packages/insomnia-inso/binaries/inso run test "Echo Test Suite" --src $PWD/packages/insomnia-smoke-test/fixtures/inso-nedb --env Dev --verbose
81+
82+
```
83+
84+
## How to update the `inso-nedb` fixtures
85+
86+
Run Insomnia with `INSOMNIA_DATA_PATH` environment variable set to `fixtures/inso-nedb`, e.g.:
87+
88+
```bash
89+
INSOMNIA_DATA_PATH=packages/insomnia-smoke-test/fixtures/inso-nedb /Applications/Insomnia.app/Contents/MacOS/Insomnia
90+
```
91+
92+
Relaunch the app one more time, so that Insomnia compacts the database.
93+
94+
The `.gitignore` file will explicitly ignore certain database files, to keep the directory size down and avoid prevent sensitive data leaks.
95+
96+
## How to run inso with the `inso-nedb` fixture locally?
97+
98+
Set the `--src` argument pointed to `packages/insomnia-smoke-test/fixtures/inso-nedb`:
99+
100+
```bash
101+
# if installed globally
102+
inso --src <INSO_NEDB_PATH>
103+
104+
# using the package bin
105+
./packages/insomnia-inso/bin/inso --src <INSO_NEDB_PATH>
106+
107+
# using a binary
108+
./packages/insomnia-inso/binaries/insomnia-inso --src <INSO_NEDB_PATH>
109+
```

packages/insomnia-inso/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
},
2222
"scripts": {
2323
"lint": "eslint . --ext .js,.ts,.tsx --cache",
24-
"test": "esr esbuild.ts && vitest run --exclude '**/cli.test.ts'",
25-
"test:watch": "npm run test -- --watch",
24+
"test:unit": "vitest run --exclude '**/cli.test.ts'",
2625
"test:bundle": "vitest cli.test.ts -t \"inso dev bundle\"",
2726
"test:binary": "vitest cli.test.ts -t \"inso packaged binary\"",
2827
"type-check": "tsc --noEmit --project tsconfig.json",
@@ -39,7 +38,6 @@
3938
"cross-env": "^7.0.3",
4039
"esbuild": "^0.20.2",
4140
"esbuild-runner": "^2.2.2",
42-
"execa": "^5.0.0",
4341
"vitest": "^2.0.4"
4442
},
4543
"dependencies": {

0 commit comments

Comments
 (0)