Skip to content

Commit

Permalink
Added unit tests for packageModules
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Schmid committed Aug 1, 2017
1 parent a1b5a24 commit 007a925
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/packageModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function zip(directory, name) {
}

module.exports = {

packageModules(stats) {
return BbPromise.mapSeries(stats.stats, (compileStats, index) => {
const entryFunction = _.get(this.entryFunctions, index, {});
Expand All @@ -94,7 +93,7 @@ module.exports = {
});
})
.then(artifacts => {
if (!_.get(this.serverless, 'service.package.individually')) {
if (!_.get(this.serverless, 'service.package.individually') && !_.isEmpty(artifacts)) {
// Set the service artifact to all functions
const allFunctionNames = this.serverless.service.getAllFunctions();
_.forEach(allFunctionNames, funcName => {
Expand All @@ -106,5 +105,4 @@ module.exports = {
return null;
});
}

};
1 change: 1 addition & 0 deletions tests/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe('serverless-webpack', () => {
require('./validate.test');
require('./compile.test');
require('./packageModules.test');
require('./run.test');
require('./cleanup.test');
});
23 changes: 23 additions & 0 deletions tests/mocks/archiver.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

/**
* Mock object for glob
*/

const sinon = require('sinon');

const ZipMock = sandbox => ({
pipe: sandbox.stub(),
append: sandbox.stub(),
finalize: sandbox.stub(),
on: sandbox.stub()
});

module.exports.create = sandbox => {
const zipMock = ZipMock(sandbox);
const mock = {
create: sinon.stub().returns(zipMock),
_zipMock: zipMock
};
return mock;
};
32 changes: 32 additions & 0 deletions tests/mocks/fs.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

/**
* Mock object for fs
*/

// We need sinon to create persistent stubs that are not cleared with the sandbox
const sinon = require('sinon');

const StreamMock = sandbox => ({
on: sandbox.stub()
});

const StatMock = sandbox => ({
isDirectory: sandbox.stub()
});

module.exports.create = sandbox => {
const streamMock = StreamMock(sandbox);
const statMock = StatMock(sandbox);
const fsMock = {
createWriteStream: sinon.stub().returns(streamMock), // Persistent stub
readFileSync: sandbox.stub(),
statSync: sinon.stub().returns(statMock), // Persistent stub
writeFileSync: sandbox.stub(),

_streamMock: streamMock,
_statMock: statMock
};

return fsMock;
};
13 changes: 13 additions & 0 deletions tests/mocks/glob.mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

/**
* Mock object for glob
*/

const GlobMock = sandbox => ({
sync: sandbox.stub()
});

module.exports.create = sandbox => {
return GlobMock(sandbox);
};
Loading

0 comments on commit 007a925

Please # to comment.