Skip to content

Commit

Permalink
inso cli scripting first pass (#7790)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jackkav authored Aug 27, 2024
1 parent 838d820 commit 02f5bf4
Show file tree
Hide file tree
Showing 23 changed files with 600 additions and 418 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ jobs:
- name : Build Inso
run: npm run build -w insomnia-inso

- name: Run Inso unit tests
run: npm run test:unit -w insomnia-inso

- name: Start test server
run: npm run serve -w insomnia-smoke-test & npx -y wait-on http://localhost:4010

- name: Run Inso bundle tests
- name: Run Inso bundle e2e tests
run: npm run test:bundle -w insomnia-inso

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

- name: Run Inso binary tests
- name: Run Inso binary e2e tests
run: npm run test:binary -w insomnia-inso

- name: Create Inso zip/tar/gz artifacts
Expand Down
82 changes: 0 additions & 82 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 109 additions & 22 deletions packages/insomnia-inso/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,109 @@
<!-- markdownlint-disable heading-style first-line-h1 -->
<!-- markdownlint-disable no-inline-html -->
<div align="center">
<br />
<br />
<img src="https://raw.githubusercontent.com/Kong/insomnia/develop/packages/insomnia-inso/assets/logo.svg" alt=""/>
<h1>
Inso CLI
<br />
<br />
</h1>
<h3>A CLI for <a href="https://insomnia.rest">Insomnia</a></h3>
<pre>npm install --global <a href="https://www.npmjs.com/package/insomnia-inso">insomnia-inso</a></pre>
<img src="https://raw.githubusercontent.com/Kong/insomnia/develop/packages/insomnia-inso/assets/demo.gif" alt=""/>
<br />
</div>
<br />
<!-- markdownlint-enable no-inline-html -->

## Documentation

See the [open-source Inso CLI documentation](https://docs.insomnia.rest/inso-cli/introduction).
# Documentation

How to use [Inso CLI](https://docs.insomnia.rest/inso-cli/introduction).

## Testing

```shell
# unit tests
npm run test:unit

# start smoke test api (required for e2e tests)
npm run serve -w insomnia-smoke-test

# e2e tests for dev bundle
npm run test:bundle

# e2e tests for binary
npm run test:binary
```

## Development

### Getting started

```shell
npm run inso-start
npm run test -w insomnia-inso
# will default to insomnia app database
$PWD/packages/insomnia-inso/bin/inso run test
# will use config, useful for testing with fewer args
$PWD/packages/insomnia-inso/bin/inso -w packages/insomnia-inso/src/db/fixtures/git-repo script runTest
```

### node-libcurl

`Error: The module '.../insomnia/node_modules/@getinsomnia/node-libcurl/lib/binding/node_libcurl.node'
was compiled against a different Node.js version using`

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

```shell
# install node version
node_modules/.bin/node-pre-gyp install --update-binary --directory node_modules/@getinsomnia/node-libcurl
# install electron version
node_modules/.bin/node-pre-gyp install --update-binary --directory node_modules/@getinsomnia/node-libcurl --runtime=electron --target=30.0.0
```

## Run CLI Smoke Tests

```shell
# Run CLI tests
npm run test:bundle -w insomnia-inso
# Package the Inso CLI binaries
npm run inso-package
npm run test:binary -w insomnia-inso
```

## Debugging CLI tests using watcher

This is helpful for debugging failing api tests

From project root, in separate terminals:

```sh
# start smoke test api
npm run serve -w insomnia-smoke-test

# watch inso
npm run start -w insomnia-inso

# run api test with dev bundle
$PWD/packages/insomnia-inso/bin/inso run test "Echo Test Suite" --src $PWD/packages/insomnia-smoke-test/fixtures/inso-nedb --env Dev --verbose
```

## How to debug pkg

```sh
# run modify package command and then a unit test
npm run package -w insomnia-inso && \
$PWD/packages/insomnia-inso/binaries/inso run test "Echo Test Suite" --src $PWD/packages/insomnia-smoke-test/fixtures/inso-nedb --env Dev --verbose

```

## How to update the `inso-nedb` fixtures

Run Insomnia with `INSOMNIA_DATA_PATH` environment variable set to `fixtures/inso-nedb`, e.g.:

```bash
INSOMNIA_DATA_PATH=packages/insomnia-smoke-test/fixtures/inso-nedb /Applications/Insomnia.app/Contents/MacOS/Insomnia
```

Relaunch the app one more time, so that Insomnia compacts the database.

The `.gitignore` file will explicitly ignore certain database files, to keep the directory size down and avoid prevent sensitive data leaks.

## How to run inso with the `inso-nedb` fixture locally?

Set the `--src` argument pointed to `packages/insomnia-smoke-test/fixtures/inso-nedb`:

```bash
# if installed globally
inso --src <INSO_NEDB_PATH>

# using the package bin
./packages/insomnia-inso/bin/inso --src <INSO_NEDB_PATH>

# using a binary
./packages/insomnia-inso/binaries/insomnia-inso --src <INSO_NEDB_PATH>
```
4 changes: 1 addition & 3 deletions packages/insomnia-inso/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
},
"scripts": {
"lint": "eslint . --ext .js,.ts,.tsx --cache",
"test": "esr esbuild.ts && vitest run --exclude '**/cli.test.ts'",
"test:watch": "npm run test -- --watch",
"test:unit": "vitest run --exclude '**/cli.test.ts'",
"test:bundle": "vitest cli.test.ts -t \"inso dev bundle\"",
"test:binary": "vitest cli.test.ts -t \"inso packaged binary\"",
"type-check": "tsc --noEmit --project tsconfig.json",
Expand All @@ -39,7 +38,6 @@
"cross-env": "^7.0.3",
"esbuild": "^0.20.2",
"esbuild-runner": "^2.2.2",
"execa": "^5.0.0",
"vitest": "^2.0.4"
},
"dependencies": {
Expand Down
Loading

0 comments on commit 02f5bf4

Please sign in to comment.