Skip to content

Commit bcc0f85

Browse files
NathanaelAFatme
authored andcommitted
Update Test to use npm config
1 parent ce5278c commit bcc0f85

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

test/services/pacote-service.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { PacoteService } from '../../lib/services/pacote-service';
44
import { LoggerStub } from "../stubs";
55
import { sandbox, SinonSandbox, SinonStub } from "sinon";
66
import { EventEmitter } from "events";
7+
8+
const npmconfig = require("libnpmconfig");
79
const pacote = require("pacote");
810
const tar = require("tar");
911
const path = require("path");
@@ -12,7 +14,7 @@ const npmCachePath = "npmCachePath";
1214
const packageName = "testPackage";
1315
const fullPath = `/Users/username/${packageName}`;
1416
const destinationDir = "destinationDir";
15-
const defaultPacoteOpts: IPacoteBaseOptions = { cache: npmCachePath };
17+
const defaultPacoteOpts: IPacoteBaseOptions = createPacoteOptions({ cache: npmCachePath });
1618
const errorMessage = "error message";
1719
const 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+
3949
const createTestInjector = (opts?: ITestSetup): IInjector => {
4050
opts = opts || {};
4151

0 commit comments

Comments
 (0)