@@ -4,6 +4,8 @@ import { PacoteService } from '../../lib/services/pacote-service';
44import { LoggerStub } from "../stubs" ;
55import { sandbox , SinonSandbox , SinonStub } from "sinon" ;
66import { EventEmitter } from "events" ;
7+
8+ const npmconfig = require ( "libnpmconfig" ) ;
79const pacote = require ( "pacote" ) ;
810const tar = require ( "tar" ) ;
911const path = require ( "path" ) ;
@@ -12,7 +14,7 @@ const npmCachePath = "npmCachePath";
1214const packageName = "testPackage" ;
1315const fullPath = `/Users/username/${ packageName } ` ;
1416const destinationDir = "destinationDir" ;
15- const defaultPacoteOpts : IPacoteBaseOptions = { cache : npmCachePath } ;
17+ const defaultPacoteOpts : IPacoteBaseOptions = createPacoteOptions ( { cache : npmCachePath } ) ;
1618const errorMessage = "error message" ;
1719const proxySettings : IProxySettings = {
1820 hostname : "hostname" ,
@@ -36,6 +38,14 @@ interface ITestCase extends ITestSetup {
3638 expectedArgs : any [ ] ;
3739}
3840
41+ function createPacoteOptions ( options : Object ) : Object {
42+ npmconfig . read ( ) . forEach ( ( value : any , key : string ) => {
43+ // replace env ${VARS} in strings with the process.env value
44+ options [ key ] = typeof value !== 'string' ? value : value . replace ( / \$ { ( [ ^ } ] + ) } / , ( _ , envVar ) => process . env [ envVar ] ) ;
45+ } ) ;
46+ return options ;
47+ }
48+
3949const createTestInjector = ( opts ?: ITestSetup ) : IInjector => {
4050 opts = opts || { } ;
4151
0 commit comments