Skip to content

Commit f08f2ec

Browse files
committed
feat: enable folder-level env manipulation for CLI
1 parent c52080c commit f08f2ec

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

packages/insomnia-inso/src/cli.test.ts

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ describe('inso dev bundle', () => {
160160

161161
expect(secondReqLogPosition).toBeGreaterThan(firstReqLogPosition);
162162
});
163+
164+
it('read and write folder environments', async () => {
165+
const input = '$PWD/packages/insomnia-inso/bin/inso run collection wrk_cfacae2b022e49c8851c2376674cc890 -w packages/insomnia-inso/src/examples/script-folder-environments.yml --requestNamePattern "updateFolderValue" --verbose "FolderEnv"';
166+
const result = await runCliFromRoot(input);
167+
expect(result.stdout).toContain('updated value from folder: 666');
168+
});
163169
});
164170
});
165171

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
_type: export
2+
__export_format: 4
3+
__export_date: 2024-08-05T10:12:24.557Z
4+
__export_source: insomnia.desktop.app:v9.3.3
5+
resources:
6+
- _id: fld_01de564274824ecaad272330339ea6b3
7+
parentId: wrk_cfacae2b022e49c8851c2376674cc890
8+
modified: 1668533312225
9+
created: 1668533312225
10+
name: folder1
11+
description: ""
12+
environment:
13+
val: "1"
14+
environmentPropertyOrder: null
15+
metaSortKey: -1668533312225
16+
_type: request_group
17+
afterResponseScript: ""
18+
preRequestScript: ""
19+
- _id: req_51dfc16d0f324a799e46aad52ffd0cd2
20+
parentId: fld_01de564274824ecaad272330339ea6b3
21+
modified: 1722852690008
22+
created: 1722852503814
23+
url: localhost:4010/echo
24+
name: updateFolderValue
25+
description: ""
26+
method: GET
27+
body: {}
28+
parameters: []
29+
headers:
30+
- name: User-Agent
31+
value: insomnia/9.3.3
32+
authentication: {}
33+
preRequestScript: |-
34+
const folder1 = insomnia.parentFolders.get('folder1');
35+
folder1.environment.set('val', '666');
36+
const folder1ValFromFolder1 = folder1.environment.get('val');
37+
console.log("updated value from folder: " + folder1ValFromFolder1)
38+
metaSortKey: -1722852503814
39+
isPrivate: false
40+
pathParameters: []
41+
settingStoreCookies: true
42+
settingSendCookies: true
43+
settingDisableRenderRequestBody: false
44+
settingEncodeUrl: true
45+
settingRebuildPath: true
46+
settingFollowRedirects: global
47+
_type: request
48+
- _id: wrk_cfacae2b022e49c8851c2376674cc890
49+
parentId: null
50+
modified: 1722852498102
51+
created: 1722852498102
52+
name: FolderEnv
53+
description: ""
54+
scope: collection
55+
_type: workspace
56+
- _id: env_fa53fdd70393dd67a77da3c45c26f2b75ecbc1f2
57+
parentId: wrk_cfacae2b022e49c8851c2376674cc890
58+
modified: 1722852666754
59+
created: 1722852498103
60+
name: Base Environment
61+
data: {}
62+
dataPropertyOrder: {}
63+
color: null
64+
isPrivate: false
65+
metaSortKey: 1722852498103
66+
_type: environment
67+
- _id: jar_fa53fdd70393dd67a77da3c45c26f2b75ecbc1f2
68+
parentId: wrk_cfacae2b022e49c8851c2376674cc890
69+
modified: 1722852666753
70+
created: 1722852498104
71+
name: Default Jar
72+
cookies: []
73+
_type: cookie_jar

packages/insomnia/src/scriptExecutor.ts

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export const runScript = async (
8787
globals: mutatedContextObject.globals,
8888
requestTestResults: mutatedContextObject.requestTestResults,
8989
execution: mutatedContextObject.execution,
90+
parentFolders: mutatedContextObject.parentFolders,
9091
};
9192
};
9293

0 commit comments

Comments
 (0)