File tree Expand file tree Collapse file tree 4 files changed +46
-11
lines changed Expand file tree Collapse file tree 4 files changed +46
-11
lines changed Original file line number Diff line number Diff line change 1- default_stages : [commit]
1+ default_stages : [pre- commit]
22repos :
33 - repo : https://github.com/pre-commit/pre-commit-hooks
44 rev : v4.1.0
Original file line number Diff line number Diff line change @@ -317,7 +317,6 @@ export function ggshieldApiKey(
317317 console . log ( proc . stderr ) ;
318318 return undefined ;
319319 } else {
320- console . log ( proc . stdout ) ;
321320 const apiUrl = configuration . apiUrl ;
322321
323322 const regexInstanceSection = `\\[${ apiToDashboard (
Original file line number Diff line number Diff line change @@ -20,20 +20,14 @@ export function runGGShieldCommand(
2020 args : string [ ]
2121) : SpawnSyncReturns < string > {
2222 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 ,
2825 GITGUARDIAN_API_URL : apiUrl ,
2926 GG_USER_AGENT : "gitguardian-vscode" ,
3027 } ;
3128
3229 if ( apiKey ) {
33- env = {
34- ...env ,
35- GITGUARDIAN_API_KEY : apiKey ,
36- } ;
30+ env . GITGUARDIAN_API_KEY = apiKey ;
3731 }
3832
3933 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