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

Extract package bugfix #319

Merged
merged 3 commits into from
Nov 7, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/registry/domain/extract-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function(files, callback){
packageUntarOutput = path.resolve(packageFile.path, '..', packageFile.name.replace('.tar.gz', '')),
packageOutput = path.resolve(packageUntarOutput, '_package');

targz.extract({
targz.decompress({
src: packagePath,
dest: packageUntarOutput
}, function(err){
Expand Down
84 changes: 84 additions & 0 deletions test/unit/registry-domain-extract-package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'use strict';

var expect = require('chai').expect;
var injectr = require('injectr');
var sinon = require('sinon');

describe('registry : domain : extract-package', function(){

var decompressStub = sinon.stub(),
pathResolveStub = sinon.stub();

var extractPackage = injectr('../../src/registry/domain/extract-package.js', {
targz: { decompress: decompressStub },
path: { resolve: pathResolveStub },
'./get-package-json-from-temp-dir': sinon.stub().yields(null, { package: 'hello' })
}, { console: console});

describe('when successfully extracting package', function(){

var error, response;

beforeEach(function(done){
pathResolveStub.reset();
pathResolveStub.onCall(0).returns('/some-path/registry/temp/1478279453422.tar.gz');
pathResolveStub.onCall(1).returns('/some-path/registry/temp/1478279453422/');
pathResolveStub.onCall(2).returns('/some-path/registry/temp/1478279453422/_package/');

decompressStub.yields();

extractPackage({
'1478279453422.tar.gz': {
name: '1478279453422.tar.gz',
path: '/some-path/registry/temp/1478279453422.tar.gz'
}
}, function(err, res){
error = err;
response = res;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should assert against res as it is what your component actually returns; maybe also add a test against the sad path?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

done();
});
});

it('should decompress tar.gz file', function(){
expect(decompressStub.args[0][0]).to.eql({
src: '/some-path/registry/temp/1478279453422.tar.gz',
dest: '/some-path/registry/temp/1478279453422/'
});
});

it('should respond', function(){
expect(response).to.eql({
outputFolder: '/some-path/registry/temp/1478279453422/_package/',
packageJson: { package: 'hello' }
});
});
});

describe('when extracting package fails', function(){

var error, response;

beforeEach(function(done){
pathResolveStub.reset();
pathResolveStub.onCall(0).returns('/some-path/registry/temp/1478279453422.tar.gz');
pathResolveStub.onCall(1).returns('/some-path/registry/temp/1478279453422/');
pathResolveStub.onCall(2).returns('/some-path/registry/temp/1478279453422/_package/');

decompressStub.yields('error!');

extractPackage({
'1478279453422.tar.gz': {
name: '1478279453422.tar.gz',
path: '/some-path/registry/temp/1478279453422.tar.gz'
}
}, function(err, res){
error = err;
done();
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind to swap the properties order? src then dest plz? 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

});

it('should respond with error', function(){
expect(error).to.equal('error!');
});
});
});