Make it windows friendly

This commit is contained in:
Guido Zuidhof
2021-07-27 04:08:09 +01:00
parent 7e5607f443
commit e44e49683d
9 changed files with 19495 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
const fs = require('fs');
const common = require('../../src/common');
const path = require('path');
const uninstall = require('../../src/actions/uninstall');
jest.mock('fs');
@@ -32,7 +33,7 @@ describe('uninstall()', () => {
uninstall(callback);
expect(fs.unlinkSync).toHaveBeenCalledWith('bin/command');
expect(fs.unlinkSync).toHaveBeenCalledWith(path.join('bin', 'command'));
});
it('should call callback on success', () => {

View File

@@ -1,6 +1,7 @@
const fs = require('fs');
const common = require('../../src/common');
const verifyAndPlaceBinary = require('../../src/assets/binary');
const path = require('path');
jest.mock('fs');
jest.mock('../../src/common');
@@ -33,7 +34,7 @@ describe('verifyAndPlaceBinary()', () => {
it('should call callback with null on success', () => {
fs.existsSync.mockReturnValueOnce(true);
common.getInstallationPath.mockImplementationOnce((cb) => cb(null, '/usr/local/bin'));
common.getInstallationPath.mockImplementationOnce((cb) => cb(null, path.sep + path.join('usr', 'local', 'bin')));
verifyAndPlaceBinary('command', './bin', callback);
@@ -42,10 +43,10 @@ describe('verifyAndPlaceBinary()', () => {
it('should move the binary to installation directory', () => {
fs.existsSync.mockReturnValueOnce(true);
common.getInstallationPath.mockImplementationOnce((cb) => cb(null, '/usr/local/bin'));
common.getInstallationPath.mockImplementationOnce((cb) => cb(null, path.sep + path.join('usr', 'local', 'bin')));
verifyAndPlaceBinary('command', './bin', callback);
expect(fs.renameSync).toHaveBeenCalledWith('bin/command', '/usr/local/bin/command');
expect(fs.renameSync).toHaveBeenCalledWith(path.join('bin', 'command'), path.sep + path.join('usr', 'local', 'bin', 'command'));
});
});

View File

@@ -1,5 +1,6 @@
const { EventEmitter } = require('events');
const fs = require('fs');
const path = require('path');
const move = require('../../src/assets/move');
jest.mock('fs');
@@ -24,7 +25,7 @@ describe('move()', () => {
move({ opts: { binPath: './bin', binName: 'command' }, req: { pipe }, onSuccess, onError });
expect(fs.createWriteStream).toHaveBeenCalledWith('bin/command');
expect(fs.createWriteStream).toHaveBeenCalledWith(path.join("bin", "command"));
});
it('should call onSuccess on stream closed', () => {

View File

@@ -1,6 +1,7 @@
const fs = require('fs');
const childProcess = require('child_process');
const common = require('../src/common');
const path = require('path');
jest.mock('fs');
jest.mock('child_process');
@@ -21,11 +22,11 @@ describe('common', () => {
});
it('should get binaries path from `npm bin`', () => {
childProcess.exec.mockImplementationOnce((_cmd, cb) => cb(null, '/usr/local/bin'));
childProcess.exec.mockImplementationOnce((_cmd, cb) => cb(null, path.sep + path.join('usr', 'local', 'bin')));
common.getInstallationPath(callback);
expect(callback).toHaveBeenCalledWith(null, '/usr/local/bin');
expect(callback).toHaveBeenCalledWith(null, path.sep + path.join('usr', 'local', 'bin'));
});
it('should get binaries path from env', () => {
@@ -35,7 +36,7 @@ describe('common', () => {
common.getInstallationPath(callback);
expect(callback).toHaveBeenCalledWith(null, '/usr/local/bin');
expect(callback).toHaveBeenCalledWith(null, path.sep + path.join('usr', 'local', 'bin'));
});
it('should call callback with error if binaries path is not found', () => {