Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tests for NpmUtilities.getExecOpts() #663

Merged
merged 3 commits into from Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/NpmUtilities.js
Expand Up @@ -17,16 +17,8 @@ export default class NpmUtilities {

const args = ["install"];

const opts = {
cwd: directory,
stdio: ["ignore", "pipe", "pipe"],
};

if (registry) {
opts.env = Object.assign({}, process.env, {
npm_config_registry: registry,
});
}
const opts = NpmUtilities.getExecOpts(directory, registry);
opts.stdio = ["ignore", "pipe", "pipe"];

const packageJson = path.join(directory, "package.json");
const packageJsonBkp = packageJson + ".lerna_backup";
Expand Down
3 changes: 1 addition & 2 deletions test/BootstrapCommand.js
Expand Up @@ -784,12 +784,11 @@ describe("BootstrapCommand", () => {
// mock out the ENV to a simpler version for testing
process.env = mockEnv;

const bootstrapCommand = new BootstrapCommand([], {});
const env = Object.assign({}, mockEnv, {
npm_config_registry: "https://my-secure-registry/npm",
});

const bootstrapCommand = new BootstrapCommand([], {});

bootstrapCommand.runValidations();
bootstrapCommand.runPreparations();

Expand Down
29 changes: 29 additions & 0 deletions test/NpmUtilities.js
Expand Up @@ -21,4 +21,33 @@ describe("NpmUtilities", () => {
});
});
});

describe(".getExecOpts()", () => {
const originalEnv = Object.assign({}, process.env);
const mockEnv = {
mock_value: 1,
NODE_ENV: "lerna-test",
};

afterEach(() => {
process.env = originalEnv;
});

it("should handle environment variables properly", () => {
process.env = mockEnv;
const want = {
cwd: "test_dir",
env: Object.assign({}, mockEnv, {
npm_config_registry: "https://my-secure-registry/npm"
})
};
assert.deepEqual(NpmUtilities.getExecOpts("test_dir", "https://my-secure-registry/npm"), want);
});

it("should handle missing environment variables", () => {
process.env = mockEnv;
const want = {cwd: "test_dir"};
assert.deepEqual(NpmUtilities.getExecOpts("test_dir"), want);
});
});
});