File tree Expand file tree Collapse file tree 3 files changed +45
-10
lines changed Expand file tree Collapse file tree 3 files changed +45
-10
lines changed Original file line number Diff line number Diff line change @@ -317,7 +317,6 @@ export function ggshieldApiKey(
317
317
console . log ( proc . stderr ) ;
318
318
return undefined ;
319
319
} else {
320
- console . log ( proc . stdout ) ;
321
320
const apiUrl = configuration . apiUrl ;
322
321
323
322
const regexInstanceSection = `\\[${ apiToDashboard (
Original file line number Diff line number Diff line change @@ -20,20 +20,14 @@ export function runGGShieldCommand(
20
20
args : string [ ]
21
21
) : SpawnSyncReturns < string > {
22
22
const { ggshieldPath, apiUrl, apiKey } = configuration ;
23
- let env : {
24
- GITGUARDIAN_API_URL : string ;
25
- GG_USER_AGENT : string ;
26
- GITGUARDIAN_API_KEY ?: string ;
27
- } = {
23
+ let env : NodeJS . ProcessEnv = {
24
+ ...process . env ,
28
25
GITGUARDIAN_API_URL : apiUrl ,
29
26
GG_USER_AGENT : "gitguardian-vscode" ,
30
27
} ;
31
28
32
29
if ( apiKey ) {
33
- env = {
34
- ...env ,
35
- GITGUARDIAN_API_KEY : apiKey ,
36
- } ;
30
+ env . GITGUARDIAN_API_KEY = apiKey ;
37
31
}
38
32
39
33
let options : SpawnSyncOptionsWithStringEncoding = {
Original file line number Diff line number Diff line change
1
+ import * as simple from "simple-mock" ;
2
+ import * as childProcess from "child_process" ;
3
+ import * as runGGShield from "../../../lib/run-ggshield" ;
4
+ import assert = require( "assert" ) ;
5
+ import { GGShieldConfiguration } from "../../../lib/ggshield-configuration" ;
6
+
7
+ suite ( "runGGShieldCommand" , ( ) => {
8
+ let spawnSyncMock : simple . Stub < Function > ;
9
+
10
+ setup ( ( ) => {
11
+ spawnSyncMock = simple . mock ( childProcess , "spawnSync" ) ; // Mock spawnSync
12
+ } ) ;
13
+
14
+ teardown ( ( ) => {
15
+ simple . restore ( ) ;
16
+ } ) ;
17
+
18
+ test ( "Global env variables are set correctly" , async ( ) => {
19
+ process . env . TEST_GLOBAL_VAR = "GlobalValue" ;
20
+
21
+ const spawnSyncSpy = simple . mock ( childProcess , "spawnSync" ) ;
22
+ runGGShield . runGGShieldCommand (
23
+ {
24
+ ggshieldPath : "path/to/ggshield" ,
25
+ apiUrl : "" ,
26
+ apiKey : "" ,
27
+ } as GGShieldConfiguration ,
28
+ [ ]
29
+ ) ;
30
+
31
+ // Assert that spawnSync was called
32
+ assert ( spawnSyncSpy . called , "spawnSync should be called once" ) ;
33
+
34
+ // Check the arguments passed to spawnSync
35
+ const spawnSyncArgs = spawnSyncSpy . lastCall . args ;
36
+ const options = spawnSyncArgs [ 2 ] ;
37
+ assert . strictEqual ( options . env . TEST_GLOBAL_VAR , "GlobalValue" ) ;
38
+
39
+ simple . restore ( ) ;
40
+ delete process . env . TEST_GLOBAL_VAR ;
41
+ } ) ;
42
+ } ) ;
You can’t perform that action at this time.
0 commit comments