Add tests for download functionality

This commit is contained in:
Philipp Muens 2016-10-04 13:33:17 -07:00
parent ce32e01e8d
commit f8ce285cf3
3 changed files with 37 additions and 1 deletions

View File

@ -1,13 +1,18 @@
'use strict';
const expect = require('chai').expect;
const Install = require('../install.js');
const Serverless = require('../../../Serverless');
const sinon = require('sinon');
const BbPromise = require('bluebird');
const testUtils = require('../../../../tests/utils');
const fse = require('fs-extra');
const path = require('path');
const proxyquire = require('proxyquire');
const downloadStub = sinon.stub().returns(BbPromise.resolve());
const Install = proxyquire('../install.js', {
download: downloadStub,
});
describe('Install', () => {
let install;
@ -16,6 +21,7 @@ describe('Install', () => {
beforeEach(() => {
serverless = new Serverless();
install = new Install(serverless);
serverless.init();
});
describe('#constructor()', () => {
@ -62,5 +68,14 @@ describe('Install', () => {
process.chdir(cwd);
});
it('should download the service based on the GitHub URL', () => {
install.options = { url: 'https://github.com/johndoe/service-to-be-downloaded' };
return install.install().then(() => {
expect(downloadStub.calledOnce).to.equal(true);
expect(downloadStub.args[0][0]).to.equal(`${install.options.url}/archive/master.zip`);
});
});
});
});

20
npm-shrinkwrap.json generated
View File

@ -623,6 +623,11 @@
"from": "filenamify@>=1.2.1 <2.0.0",
"resolved": "https://registry.npmjs.org/filenamify/-/filenamify-1.2.1.tgz"
},
"fill-keys": {
"version": "1.0.2",
"from": "fill-keys@>=1.0.2 <2.0.0",
"resolved": "https://registry.npmjs.org/fill-keys/-/fill-keys-1.0.2.tgz"
},
"find-up": {
"version": "1.1.2",
"from": "find-up@>=1.0.0 <2.0.0",
@ -887,6 +892,11 @@
"from": "is-natural-number@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/is-natural-number/-/is-natural-number-2.1.1.tgz"
},
"is-object": {
"version": "1.0.1",
"from": "is-object@>=1.0.1 <1.1.0",
"resolved": "https://registry.npmjs.org/is-object/-/is-object-1.0.1.tgz"
},
"is-path-cwd": {
"version": "1.0.0",
"from": "is-path-cwd@>=1.0.0 <2.0.0",
@ -1167,6 +1177,11 @@
"from": "lowercase-keys@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-1.0.0.tgz"
},
"merge-descriptors": {
"version": "1.0.1",
"from": "merge-descriptors@>=1.0.0 <1.1.0",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz"
},
"methods": {
"version": "1.1.2",
"from": "methods@>=1.1.1 <1.2.0",
@ -1209,6 +1224,11 @@
}
}
},
"module-not-found-error": {
"version": "1.0.1",
"from": "module-not-found-error@>=1.0.0 <2.0.0",
"resolved": "https://registry.npmjs.org/module-not-found-error/-/module-not-found-error-1.0.1.tgz"
},
"moment": {
"version": "2.15.1",
"from": "moment@2.15.1",

View File

@ -58,6 +58,7 @@
"mocha": "^3.0.2",
"mocha-lcov-reporter": "^1.2.0",
"mock-require": "^1.3.0",
"proxyquire": "^1.7.10",
"sinon": "^1.17.5"
},
"dependencies": {