Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insomnia Format v5 #8209

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b2d0d13
schema
gatzjames Nov 25, 2024
c99ac13
working imports
gatzjames Nov 27, 2024
b7e3129
exports
gatzjames Nov 27, 2024
264f08d
cleanup
gatzjames Dec 9, 2024
d025366
Move sortKey and description to meta and define request settings schema
gatzjames Dec 9, 2024
22ce7ff
request docs
gatzjames Dec 9, 2024
b4717b8
export: cleanup empty fields
gatzjames Dec 10, 2024
bff4f1c
improve request settings
gatzjames Dec 12, 2024
388f3ed
update types and cleanup
gatzjames Jan 6, 2025
259ea90
fix falsy value error
gatzjames Jan 6, 2025
c17caa3
cleanup todo file
gatzjames Jan 7, 2025
2ffe53f
cleanup zod-to-json-schema
gatzjames Jan 7, 2025
c4e2a73
fix export ordering to imrpove readability
gatzjames Jan 7, 2025
7fa8196
cleanup schema
gatzjames Jan 7, 2025
de7ffec
update fixtures to v5
gatzjames Jan 7, 2025
e3f5e40
fix tests
gatzjames Jan 11, 2025
4868dcb
clean up types and fix e2e tests
gatzjames Jan 14, 2025
2e1bb6f
importer in inso-cli
gatzjames Jan 15, 2025
c89664e
update inso-cli e2e tests
gatzjames Jan 15, 2025
8892001
update optional collection and spec meta
gatzjames Jan 16, 2025
75ca1de
throw if no import found in inso
gatzjames Jan 16, 2025
8eccbb1
update inso error
gatzjames Jan 16, 2025
aca00cf
add docs for debugging inso
gatzjames Jan 16, 2025
d7d22c7
clarify name and comment
jackkav Jan 20, 2025
3ecf3f2
comment
jackkav Jan 20, 2025
f26b0b9
fix lint
jackkav Feb 18, 2025
91fb97a
bring fixture collection back to prev version
gatzjames Feb 18, 2025
65f65d5
update pre-request-collection fixture to v5
gatzjames Feb 18, 2025
01492af
fix after-response-collection
gatzjames Feb 18, 2025
5472247
after-response v5
gatzjames Feb 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion packages/insomnia-inso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ npm run serve -w insomnia-smoke-test
# watch inso
npm run start -w insomnia-inso

# run api test with dev bundle
# run api test with dev bundle. To debug run this in a Javascript Debug Terminal in VSCode
$PWD/packages/insomnia-inso/bin/inso run test "Echo Test Suite" -w $PWD/packages/insomnia-smoke-test/fixtures/inso-nedb --env Dev --verbose
```

Expand Down
18 changes: 9 additions & 9 deletions packages/insomnia-inso/src/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ const shouldReturnSuccessCode = [

// run collection
// export file
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-smoke-test/fixtures/simple.yaml -e env_2eecf85b7f wrk_0702a5',
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-smoke-test/fixtures/simple.yaml -e production wrk_dc393c',
// with regex filter
'$PWD/packages/insomnia-inso/bin/inso run collection wrk_0702a57d75d44255a8cecd2c5fa87809 -w packages/insomnia-smoke-test/fixtures/simple.yaml -e env_2eecf85b7f --requestNamePattern "example http" wrk_0702a5',
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-smoke-test/fixtures/simple.yaml -e production --requestNamePattern "example http" wrk_dc393c',
// after-response script and test
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/after-response.yml wrk_616795 --verbose',
// select request by id
'$PWD/packages/insomnia-inso/bin/inso run collection wrk_c992d40 -w packages/insomnia-inso/src/examples/three-requests.yml -i req_3fd28aabbb18447abab1f45e6ee4bdc1 -i req_6063adcdab5b409e9b4f00f47322df4a',
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/three-requests.yml -i req_3fd28aabbb18447abab1f45e6ee4bdc1 -i req_6063adcdab5b409e9b4f00f47322df4a wrk_c992d40',
// setNextRequest runs the next request then ends
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/set-next-request.yml wrk_cbc89e',
// multiple --env-var overrides
'$PWD/packages/insomnia-inso/bin/inso run collection wrk_c992d40ce76f4a3cb44c5fdb8435cbeb -w packages/insomnia-inso/src/examples/with-missing-env-vars.yml -i req_3fd28aabbb18447abab1f45e6ee4bdc1 --env-var firstkey=first --env-var secondkey=second',
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/with-missing-env-vars.yml -i req_3fd28aabbb18447abab1f45e6ee4bdc1 --env-var firstkey=first --env-var secondkey=second wrk_c992d40',
// globals file path env overrides
'$PWD/packages/insomnia-inso/bin/inso run collection wrk_c992d40ce76f4a3cb44c5fdb8435cbeb -w packages/insomnia-inso/src/examples/with-missing-env-vars.yml -i req_3fd28aabbb18447abab1f45e6ee4bdc1 --globals packages/insomnia-inso/src/examples/global-environment.yml',
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/with-missing-env-vars.yml -i req_3fd28aabbb18447abab1f45e6ee4bdc1 --globals packages/insomnia-inso/src/examples/global-environment.yml wrk_c992d40',
];

const shouldReturnErrorCode = [
Expand Down Expand Up @@ -120,7 +120,7 @@ describe('inso dev bundle', () => {
});

it('iterationData and iterationCount args work', async () => {
const input = '$PWD/packages/insomnia-inso/bin/inso run collection wrk_c992d40 -d packages/insomnia-smoke-test/fixtures/files/runner-data.json -w packages/insomnia-inso/src/examples/three-requests.yml -n 2 -i req_3fd28aabbb18447abab1f45e6ee4bdc1 -e env_86e135 --verbose';
const input = '$PWD/packages/insomnia-inso/bin/inso run collection -d packages/insomnia-smoke-test/fixtures/files/runner-data.json -w packages/insomnia-inso/src/examples/three-requests.yml -n 2 -i req_3fd28aabbb18447abab1f45e6ee4bdc1 -e env_86e135 wrk_c992d40 --verbose';
const result = await runCliFromRoot(input);
if (result.code !== 0) {
console.log(result);
Expand All @@ -130,7 +130,7 @@ describe('inso dev bundle', () => {
});

it('send request with client cert and key', async () => {
const input = '$PWD/packages/insomnia-inso/bin/inso run collection wrk_0b96eff84c1c4eaa9c6e67ad74bbc85b -w packages/insomnia-inso/src/db/fixtures/nedb --requestNamePattern "withCertAndCA" --verbose "Insomnia Designer"';
const input = '$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/db/fixtures/nedb --requestNamePattern "withCertAndCA" --verbose "Insomnia Designer" wrk_0b96eff';
const result = await runCliFromRoot(input);
if (result.code !== 0) {
console.log(result);
Expand All @@ -140,13 +140,13 @@ describe('inso dev bundle', () => {
});

it('send request with settings enabled (by testing followRedirects)', async () => {
const input = '$PWD/packages/insomnia-inso/bin/inso run collection wrk_0b96eff84c1c4eaa9c6e67ad74bbc85b -w packages/insomnia-inso/src/db/fixtures/nedb --requestNamePattern "withSettings" --verbose "Insomnia Designer"';
const input = '$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/db/fixtures/nedb --requestNamePattern "withSettings" --verbose "Insomnia Designer" wrk_0b96eff';
const result = await runCliFromRoot(input);
expect(result.stdout).not.toContain("Issue another request to this URL: 'https://insomnia.rest/'");
});

it('run collection: run requests in specified order', async () => {
const input = '$PWD/packages/insomnia-inso/bin/inso run collection wrk_c992d40 -w packages/insomnia-inso/src/examples/three-requests.yml -i req_6063adcdab5b409e9b4f00f47322df4a -i req_3fd28aabbb18447abab1f45e6ee4bdc1 -e env_86e135 --verbose';
const input = '$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/three-requests.yml -i req_6063adcdab5b409e9b4f00f47322df4a -i req_3fd28aabbb18447abab1f45e6ee4bdc1 -e env_86e135 wrk_c992d40 --verbose';
const result = await runCliFromRoot(input);

expect(result.code).toBe(0);
Expand Down
18 changes: 16 additions & 2 deletions packages/insomnia-inso/src/db/adapters/insomnia-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs';
import { importInsomniaV5Data } from 'insomnia/src/common/insomnia-v5';
import path from 'path';
import YAML from 'yaml';

Expand Down Expand Up @@ -82,18 +83,31 @@ const insomniaAdapter: DbAdapter = async (filePath, filterTypes) => {
__export_format: number;
resources: RawTypeModel[];
} | undefined;

try {
parsed = YAML.parse(content);

if (!parsed?.__export_format) {
const insomnia5Import = importInsomniaV5Data(content);

if (insomnia5Import.length > 0) {
parsed = {
__export_format: 5,
// @ts-expect-error -- TSCONVERSION
resources: insomnia5Import,
};
}
}
} catch (error) {
throw new InsoError(`Failed to parse ${fileName}.`, error);
}

// We are supporting only v4 files
// We are supporting only v4 and v5 files
if (!parsed) {
throw new InsoError(`Failed to parse ${fileName}.`);
} else if (!parsed.__export_format) {
throw new InsoError(`Expected an Insomnia v4 export file; unexpected data found in ${fileName}.`);
} else if (parsed.__export_format !== 4) {
} else if (parsed.__export_format !== 4 && parsed.__export_format !== 5) {
throw new InsoError(`Expected an Insomnia v4 export file; found an Insomnia v${parsed.__export_format} export file in ${fileName}.`);
}

Expand Down
239 changes: 110 additions & 129 deletions packages/insomnia-smoke-test/fixtures/after-response-collection.yaml
Original file line number Diff line number Diff line change
@@ -1,143 +1,124 @@
_type: export
__export_format: 4
__export_date: 2024-02-13T07:27:17.322Z
__export_source: insomnia.desktop.app:v8.6.1
resources:
- _id: wrk_6b9b8455fd784462ae19cd51d7156f86
parentId: null
modified: 1707808692801
created: 1707808692801
name: After-response Scripts
description: ""
scope: collection
_type: workspace
- _id: req_244fe815da6c4342a17f0cfd98cf648c
parentId: wrk_6b9b8455fd784462ae19cd51d7156f86
modified: 1707809218855
created: 1707808697304
url: '{{_.base_url}}/echo'
type: collection.insomnia.rest/5.0
name: After-response Scripts
meta:
id: wrk_5033693e76a244d9a19124895c871ed5
created: 1739888439647
modified: 1739888439647
collection:
- url: "{{_.base_url}}/echo"
name: tests with expect and test
description: ""
meta:
id: req_6d55848a007849e885c0d1d35fd3c8f7
created: 1707808697304
modified: 1707809218855
isPrivate: false
sortKey: -1707809028499
method: POST
afterResponseScript: |-
insomnia.test('happy tests', () => {
insomnia.expect(200).to.eql(200);
insomnia.expect('uname').to.be.a('string');
insomnia.expect('a').to.have.lengthOf(1);
insomnia.expect('xxx_customer_id_yyy').to.include("customer_id");
insomnia.expect(201).to.be.oneOf([201,202]);
insomnia.expect(199).to.be.below(200);
// test objects
insomnia.expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
insomnia.expect({a: 1, b: 2}).to.have.any.keys('a', 'b');
insomnia.expect({a: 1, b: 2}).to.not.have.any.keys('c', 'd');
insomnia.expect({a: 1}).to.have.property('a');
insomnia.expect({a: 1, b: 2}).to.be.a('object')
.that.has.all.keys('a', 'b');
});
insomnia.test('unhappy tests', () => {
insomnia.expect(199).to.eql(200);
insomnia.expect(199).to.be.oneOf([201,202]);
});
body:
mimeType: "application/json"
text: |-
{}
parameters: []
mimeType: application/json
text: "{}"
headers:
- name: 'Content-Type'
value: 'application/json'
authentication: {}
metaSortKey: -1707809028499
isPrivate: false
pathParameters: []
settingStoreCookies: true
settingSendCookies: true
settingDisableRenderRequestBody: false
settingEncodeUrl: true
settingRebuildPath: true
settingFollowRedirects: global
_type: request
- _id: req_244fe815da6c4342a17f0cfd98cf6401
parentId: wrk_6b9b8455fd784462ae19cd51d7156f86
modified: 1707809218855
created: 1707808697304
url: http://127.0.0.1:4010/echo
- name: Content-Type
value: application/json
scripts:
afterResponse: |-
insomnia.test('happy tests', () => {
insomnia.expect(200).to.eql(200);
insomnia.expect('uname').to.be.a('string');
insomnia.expect('a').to.have.lengthOf(1);
insomnia.expect('xxx_customer_id_yyy').to.include("customer_id");
insomnia.expect(201).to.be.oneOf([201,202]);
insomnia.expect(199).to.be.below(200);
// test objects
insomnia.expect({a: 1, b: 2}).to.have.all.keys('a', 'b');
insomnia.expect({a: 1, b: 2}).to.have.any.keys('a', 'b');
insomnia.expect({a: 1, b: 2}).to.not.have.any.keys('c', 'd');
insomnia.expect({a: 1}).to.have.property('a');
insomnia.expect({a: 1, b: 2}).to.be.a('object')
.that.has.all.keys('a', 'b');
});
insomnia.test('unhappy tests', () => {
insomnia.expect(199).to.eql(200);
insomnia.expect(199).to.be.oneOf([201,202]);
});
settings:
renderRequestBody: true
encodeUrl: true
followRedirects: global
cookies:
send: true
store: true
rebuildPath: true
- url: http://127.0.0.1:4010/echo
name: persist environments
description: ""
meta:
id: req_76b32fc876f44f6984684bbc2a35c9e8
created: 1707808697304
modified: 1707809218855
isPrivate: false
sortKey: -1707809028499
method: POST
afterResponseScript: |-
insomnia.environment.set('__fromAfterScript', 'environment');
insomnia.baseEnvironment.set('__fromAfterScript1', 'baseEnvironment');
insomnia.collectionVariables.set('__fromAfterScript2', 'collection');
insomnia.environment.replaceIn('{{ $timestamp }}');
body:
mimeType: "application/json"
text: |-
{}
parameters: []
mimeType: application/json
text: "{}"
headers:
- name: 'Content-Type'
value: 'application/json'
authentication: {}
metaSortKey: -1707809028499
isPrivate: false
pathParameters: []
settingStoreCookies: true
settingSendCookies: true
settingDisableRenderRequestBody: false
settingEncodeUrl: true
settingRebuildPath: true
settingFollowRedirects: global
_type: request
- _id: req_244fe815da6c4342a17f0cfd98cf6402
parentId: wrk_6b9b8455fd784462ae19cd51d7156f86
modified: 1707809218855
created: 1707808697304
url: http://127.0.0.1:4010/echo
- name: Content-Type
value: application/json
scripts:
afterResponse: |-
insomnia.environment.set('__fromAfterScript', 'environment');
insomnia.baseEnvironment.set('__fromAfterScript1', 'baseEnvironment');
insomnia.collectionVariables.set('__fromAfterScript2', 'collection');
insomnia.environment.replaceIn('{{ $timestamp }}');
settings:
renderRequestBody: true
encodeUrl: true
followRedirects: global
cookies:
send: true
store: true
rebuildPath: true
- url: http://127.0.0.1:4010/echo
name: transient var
description: ""
meta:
id: req_f101063d3746440b8eae243db5b3e78f
created: 1707808697304
modified: 1707809218855
isPrivate: false
sortKey: -1707809028499
method: POST
preRequestScript: |-
insomnia.variables.set('var', 666);
afterResponseScript: |-
insomnia.test('check var', () => {
insomnia.expect(insomnia.variables.get('var')).to.eql(666);
});
body:
mimeType: "application/json"
text: |-
{}
parameters: []
mimeType: application/json
text: "{}"
headers:
- name: 'Content-Type'
value: 'application/json'
authentication: {}
metaSortKey: -1707809028499
isPrivate: false
pathParameters: []
settingStoreCookies: true
settingSendCookies: true
settingDisableRenderRequestBody: false
settingEncodeUrl: true
settingRebuildPath: true
settingFollowRedirects: global
_type: request
- _id: env_f9ef1d097c5e00986051fcb4f7a921eea1a86916
parentId: wrk_6b9b8455fd784462ae19cd51d7156f86
modified: 1707808692805
- name: Content-Type
value: application/json
scripts:
preRequest: insomnia.variables.set('var', 666);
afterResponse: |-
insomnia.test('check var', () => {
insomnia.expect(insomnia.variables.get('var')).to.eql(666);
});
settings:
renderRequestBody: true
encodeUrl: true
followRedirects: global
cookies:
send: true
store: true
rebuildPath: true
cookieJar:
name: Default Jar
meta:
id: jar_eb95028c43f847e985763a20ca93825d
created: 1707808692807
modified: 1707808692807
environments:
name: Base Environment
meta:
id: env_5c64074c252f4016b26e30daed930bd6
created: 1707808692805
name: Base Environment
data: {"base_url": "http://localhost:4010"}
dataPropertyOrder: null
color: null
modified: 1707808692805
isPrivate: false
metaSortKey: 1707808692805
_type: environment
- _id: jar_f9ef1d097c5e00986051fcb4f7a921eea1a86916
parentId: wrk_6b9b8455fd784462ae19cd51d7156f86
modified: 1707808692807
created: 1707808692807
name: Default Jar
cookies: []
_type: cookie_jar
data:
base_url: http://localhost:4010
Loading
Loading