mirror of
https://github.com/ershisan99/go-npm.git
synced 2025-12-17 20:59:33 +00:00
ADD unzip support
This commit is contained in:
@@ -4,6 +4,7 @@ const common = require('../../src/common');
|
||||
const install = require('../../src/actions/install');
|
||||
const move = require('../../src/assets/move');
|
||||
const untar = require('../../src/assets/untar');
|
||||
const unzip = require('../../src/assets/unzip');
|
||||
const verifyAndPlaceCallback = require('../../src/assets/binary');
|
||||
|
||||
jest.mock('fs');
|
||||
@@ -12,6 +13,7 @@ jest.mock('request');
|
||||
jest.mock('../../src/common');
|
||||
jest.mock('../../src/assets/move');
|
||||
jest.mock('../../src/assets/untar');
|
||||
jest.mock('../../src/assets/unzip');
|
||||
jest.mock('../../src/assets/binary');
|
||||
|
||||
describe('install()', () => {
|
||||
@@ -77,6 +79,17 @@ describe('install()', () => {
|
||||
expect(untar).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should pick unzip strategy if url ends with .zip', () => {
|
||||
request.mockReturnValueOnce(requestEvents);
|
||||
common.parsePackageJson.mockReturnValueOnce({ url: 'http://url.zip' });
|
||||
|
||||
install(callback);
|
||||
|
||||
requestEvents.emit('response', { statusCode: 200 });
|
||||
|
||||
expect(unzip).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call verifyAndPlaceCallback on success', () => {
|
||||
request.mockReturnValueOnce(requestEvents);
|
||||
common.parsePackageJson.mockReturnValueOnce({ url: 'http://url', binName: 'command', binPath: './bin' });
|
||||
|
||||
50
__test__/assets/unzip.spec.js
Normal file
50
__test__/assets/unzip.spec.js
Normal file
@@ -0,0 +1,50 @@
|
||||
const { EventEmitter } = require('events');
|
||||
const unzipper = require('unzipper');
|
||||
const unzip = require('../../src/assets/unzip');
|
||||
|
||||
jest.mock('unzipper', () => ({
|
||||
Extract: jest.fn()
|
||||
}));
|
||||
|
||||
describe('unzip()', () => {
|
||||
|
||||
let unzipEvents, pipe, onSuccess, onError;
|
||||
|
||||
beforeEach(() => {
|
||||
unzipEvents = new EventEmitter();
|
||||
|
||||
pipe = jest.fn();
|
||||
onSuccess = jest.fn();
|
||||
onError = jest.fn();
|
||||
|
||||
pipe.mockReturnValueOnce({ pipe });
|
||||
unzipper.Extract.mockReturnValueOnce(unzipEvents);
|
||||
});
|
||||
|
||||
it('should download resource and unzip to given binPath', () => {
|
||||
|
||||
unzip({ opts: { binPath: './bin', binName: 'command' }, req: { pipe }, onSuccess, onError });
|
||||
|
||||
expect(unzipper.Extract).toHaveBeenCalledWith({ path: './bin' });
|
||||
});
|
||||
|
||||
it('should call onSuccess on unzip close', () => {
|
||||
|
||||
unzip({ opts: { binPath: './bin', binName: 'command' }, req: { pipe }, onSuccess, onError });
|
||||
|
||||
unzipEvents.emit('close');
|
||||
|
||||
expect(onSuccess).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should call onError with error on unzip error', () => {
|
||||
|
||||
const error = new Error();
|
||||
|
||||
unzip({ opts: { binPath: './bin', binName: 'command' }, req: { pipe }, onSuccess, onError });
|
||||
|
||||
unzipEvents.emit('error', error);
|
||||
|
||||
expect(onError).toHaveBeenCalledWith(error);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user