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

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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" --src $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
234 changes: 105 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,119 @@
_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
type: collection.insomnia.rest/5.0
name: After-response Scripts
meta:
id: wrk_afb145f300dd4ca298aa1f07e8dab279
created: 1736264402522
modified: 1736264402522
collection:
- meta:
id: req_114186b826f14763b1077e76f8faf508
created: 1707808697304
modified: 1707809218855
isPrivate: false
name: transient var
url: http://127.0.0.1:4010/echo
name: tests with expect and test
description: ""
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:
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
- meta:
id: req_6d7687e32e80490bbf78306e3d6162b2
created: 1707808697304
modified: 1707809218855
isPrivate: false
name: persist environments
description: ""
url: http://127.0.0.1:4010/echo
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
- 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
- meta:
id: req_ed884243b76f4f56b31cd35ba27372a7
created: 1707808697304
modified: 1707809218855
isPrivate: false
name: tests with expect and test
url: http://127.0.0.1:4010/echo
name: transient var
description: ""
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:
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
cookieJar:
meta:
id: jar_a64c8e903b8f483b94897325f4f9e9d2
created: 1707808692807
modified: 1707808692807
name: Default Jar
environments:
meta:
id: env_317fbd93c6b547c592ef7b114514a8f9
created: 1707808692805
name: Base Environment
data: {}
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
name: Base Environment
Loading
Loading