Skip to content

Commit a2ad777

Browse files
authored
fix(inso): include transient variables during interpolation (#9396)
1 parent 3bce64d commit a2ad777

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ const shouldReturnSuccessCode = [
4747
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-smoke-test/fixtures/simple.yaml -e production --requestNamePattern "example http" wrk_dc393c',
4848
// after-response script and test
4949
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/after-response.yml wrk_616795 --verbose',
50+
// transient variables
51+
'$PWD/packages/insomnia-inso/bin/inso run collection -w packages/insomnia-inso/src/examples/transient-variables.yml wrk_3d6697b --verbose',
5052
// select request by id
5153
'$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',
5254
// setNextRequest runs the next request then ends
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
type: collection.insomnia.rest/5.0
2+
schema_version: "5.1"
3+
name: Simple Crud
4+
meta:
5+
id: wrk_3d6697ba0f6a43cdb9e7378d54d1a1cb
6+
created: 1763445405875
7+
modified: 1763445405875
8+
description: ""
9+
collection:
10+
- url: http://localhost:4010/simple-crud
11+
name: Create Thing
12+
meta:
13+
id: req_a93f56d7079740ce89d9365a58d2d202
14+
created: 1763445410113
15+
modified: 1763445948725
16+
isPrivate: false
17+
description: ""
18+
sortKey: -1763445410113
19+
method: POST
20+
body:
21+
mimeType: application/json
22+
text: |-
23+
{
24+
"some": "thing"
25+
}
26+
headers:
27+
- name: Content-Type
28+
value: application/json
29+
- name: User-Agent
30+
value: insomnia/12.1.0-beta.0
31+
description: ""
32+
disabled: false
33+
scripts:
34+
afterResponse: |-
35+
const jsonBody = insomnia.response.json();
36+
insomnia.variables.set('thingId', jsonBody.id);
37+
38+
insomnia.test('got a 201', () => {
39+
insomnia.expect(insomnia.response.code).to.eql(201);
40+
});
41+
42+
insomnia.test('variable set', () => {
43+
insomnia.expect(insomnia.variables.get('thingId')).to.eql(jsonBody.id);
44+
});
45+
settings:
46+
renderRequestBody: true
47+
encodeUrl: true
48+
followRedirects: global
49+
cookies:
50+
send: true
51+
store: true
52+
rebuildPath: true
53+
- url: http://localhost:4010/simple-crud/{{thingId}}
54+
name: Retrieve Thing
55+
meta:
56+
id: req_8aa3c21007f746e7b400d2e17a0a1aba
57+
created: 1763445773731
58+
modified: 1763445889533
59+
isPrivate: false
60+
description: ""
61+
sortKey: -1763445410013
62+
method: GET
63+
headers:
64+
- name: User-Agent
65+
value: insomnia/12.1.0-beta.0
66+
description: ""
67+
disabled: false
68+
scripts:
69+
afterResponse: |-
70+
const jsonBody = insomnia.response.json();
71+
insomnia.test('got the thing', () => {
72+
insomnia.expect(jsonBody.id).to.eql(insomnia.variables.get('thingId'))
73+
insomnia.expect(jsonBody.some).to.eql("thing");
74+
});
75+
settings:
76+
renderRequestBody: true
77+
encodeUrl: true
78+
followRedirects: global
79+
cookies:
80+
send: true
81+
store: true
82+
rebuildPath: true
83+
cookieJar:
84+
name: Default Jar
85+
meta:
86+
id: jar_217626d704282108ee9f812e810d658e53370cb1
87+
created: 1763445405878
88+
modified: 1763445982968
89+
environments:
90+
name: Base Environment
91+
meta:
92+
id: env_217626d704282108ee9f812e810d658e53370cb1
93+
created: 1763445405877
94+
modified: 1763445982970
95+
isPrivate: false

packages/insomnia-smoke-test/server/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { startGRPCServer } from './grpc';
1616
import insomniaApi from './insomnia-api';
1717
import { mtlsRouter } from './mtls';
1818
import { oauthRoutes } from './oauth';
19+
import simpleCrud from './simple-crud';
1920
import { startSocketIOServer } from './socket-io';
2021
import { startWebSocketServer } from './websocket';
2122

@@ -71,6 +72,7 @@ app.use('/protected', mtlsRouter);
7172
githubApi(app);
7273
gitlabApi(app);
7374
insomniaApi(app);
75+
simpleCrud(app);
7476

7577
app.get('/delay/seconds/:duration', (req, res) => {
7678
const delaySec = Number.parseInt(req.params.duration || '2');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import express from 'express';
2+
3+
const db = new Map<string, any>();
4+
5+
export default (app: express.Application) => {
6+
app.get('/simple-crud/:id', (req, res) => {
7+
const { id } = req.params;
8+
const item = db.get(id);
9+
if (!item) {
10+
res.status(404).send();
11+
return;
12+
}
13+
res.status(200).send({ id, ...item });
14+
});
15+
16+
app.post('/simple-crud', express.json(), (req, res) => {
17+
const id = crypto.randomUUID();
18+
db.set(id, req.body);
19+
res.status(201).send({ id, ...req.body });
20+
});
21+
};

packages/insomnia/src/common/send-request.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export async function getSendRequestCallbackMemDb(
8989
environment: mutatedContext.environment,
9090
purpose: 'send',
9191
extraInfo: undefined,
92+
transientVariables: mutatedContext.transientVariables || transientVariables,
9293
baseEnvironment: mutatedContext.baseEnvironment,
9394
userUploadEnvironment: mutatedContext.userUploadEnvironment,
9495
ignoreUndefinedEnvVariable,

0 commit comments

Comments
 (0)