Skip to content

Commit

Permalink
Add a test to get the correct global bin installation path on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
sounisi5011 committed May 24, 2023
1 parent 5b4b644 commit e1591df
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions __test__/common.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ jest.mock('mkdirp');

describe('common', () => {
describe('getInstallationPath()', () => {
let callback, env;
let callback, _process;

beforeEach(() => {
callback = jest.fn();

env = { ...process.env };
_process = { ...global.process, env: { ...process.env } };
});

afterEach(() => {
process.env = env;
global.process = _process;
});

it('should get binaries path from `npm bin`', () => {
Expand All @@ -29,9 +29,21 @@ describe('common', () => {
expect(callback).toHaveBeenCalledWith(null, path.sep + path.join('usr', 'local', 'bin'));
});

it('should get binaries path from env', () => {
it('should get binaries path from env on windows platform', () => {
childProcess.exec.mockImplementationOnce((_cmd, cb) => cb(new Error()));

process.platform = 'win32';
process.env.npm_config_prefix = String.raw`C:\Users\John Smith\AppData\npm`;

common.getInstallationPath(callback);

expect(callback).toHaveBeenCalledWith(null, path.win32.join('C:', 'Users', 'John Smith', 'AppData', 'npm'));
});

it('should get binaries path from env on platform different than windows', () => {
childProcess.exec.mockImplementationOnce((_cmd, cb) => cb(new Error()));

process.platform = 'linux';
process.env.npm_config_prefix = '/usr/local';

common.getInstallationPath(callback);
Expand Down

0 comments on commit e1591df

Please sign in to comment.