Skip to content

Commit fa6f354

Browse files
committed
feat: enable folder-level env manipulation for CLI
1 parent 9ce5944 commit fa6f354

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
@@ -169,6 +169,12 @@ describe('inso dev bundle', () => {
169169

170170
expect(secondReqLogPosition).toBeGreaterThan(firstReqLogPosition);
171171
});
172+
173+
it('read and write folder environments', async () => {
174+
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"';
175+
const result = await runCliFromRoot(input);
176+
expect(result.stdout).toContain('updated value from folder: 666');
177+
});
172178
});
173179
});
174180

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
@@ -98,6 +98,7 @@ export const runScript = async ({
9898
globals: mutatedContextObject.globals,
9999
requestTestResults: mutatedContextObject.requestTestResults,
100100
execution: mutatedContextObject.execution,
101+
parentFolders: mutatedContextObject.parentFolders,
101102
};
102103
};
103104

0 commit comments

Comments
 (0)