Skip to content

Commit f7c692b

Browse files
committed
fix: ensure correct order if cli args are used (#773)
1 parent 0cdbdd1 commit f7c692b

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [unreleased]
2+
3+
### Fix
4+
- ensure correct order if cli args are used (#773)
5+
6+
17
## [6.16.4] (2024-11-03)
28

39
### Features

src/httpYacApi.spec.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { getVariables } from './httpYacApi';
2+
3+
import { initFileProvider, parseHttp } from './test/testUtils';
4+
5+
describe('httpYacApi', () => {
6+
describe('getVariables', () => {
7+
it('should return secret provided by environment', async () => {
8+
initFileProvider({
9+
'.env': 'secret=from .env',
10+
});
11+
const httpFile = await parseHttp(`
12+
# @name test
13+
`);
14+
15+
const variables = await getVariables({
16+
httpFile,
17+
});
18+
19+
expect(variables).toEqual(
20+
expect.objectContaining({
21+
secret: 'from .env',
22+
})
23+
);
24+
});
25+
it('should return secret provided by context variables', async () => {
26+
initFileProvider({
27+
'.env': 'secret=from.env',
28+
});
29+
const httpFile = await parseHttp(`
30+
# @name test
31+
`);
32+
33+
const variables = await getVariables({
34+
httpFile,
35+
variables: {
36+
secret: 'cli args',
37+
},
38+
});
39+
40+
expect(variables).toEqual(
41+
expect.objectContaining({
42+
secret: 'cli args',
43+
})
44+
);
45+
});
46+
it('should return secret provided by intellij', async () => {
47+
initFileProvider({
48+
'.env': 'secret=from.env',
49+
'http-client.env.json': JSON.stringify({
50+
dev: {
51+
secret: 'intellij variable',
52+
},
53+
}),
54+
});
55+
const httpFile = await parseHttp(`
56+
# @name test
57+
`);
58+
59+
const variables = await getVariables({
60+
httpFile,
61+
activeEnvironment: ['dev'],
62+
});
63+
64+
expect(variables).toEqual(
65+
expect.objectContaining({
66+
secret: 'intellij variable',
67+
})
68+
);
69+
});
70+
});
71+
});

src/httpYacApi.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ export async function getVariables(context: models.VariableProviderContext): Pro
7878
if (vars === HookCancel) {
7979
return context.variables || {};
8080
}
81+
const contextVars = {
82+
...context.variables,
83+
};
8184
const variables = Object.assign(
8285
context.variables || {},
8386
...vars.map(variables => utils.cleanVariables(variables)),
84-
context.variables
87+
contextVars
8588
);
8689
log.debug('current environment variables', variables);
8790
return variables;

0 commit comments

Comments
 (0)