Skip to content

Commit

Permalink
Increase coverage
Browse files Browse the repository at this point in the history
Also:
- remove useless `console.log`
- add a test to cover an exception when container image is badly defined
- run format command
  • Loading branch information
j0k3r committed Jun 10, 2021
1 parent b51bd58 commit b4a7014
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
5 changes: 3 additions & 2 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ describe('ServerlessWebpack', () => {

before(() => {
slsw = new ServerlessWebpack(serverless, rawOptions);
if(serverless.processedInput) { // serverless.processedInput does not exist in serverless@<2.0.0
if (serverless.processedInput) {
// serverless.processedInput does not exist in serverless@<2.0.0
serverless.processedInput.options = processedOptions;
}
sandbox.stub(slsw, 'cleanup').returns(BbPromise.resolve());
Expand Down Expand Up @@ -477,7 +478,7 @@ describe('ServerlessWebpack', () => {
test: () => {
it('should override the raw options with the processed ones', () => {
slsw.hooks.initialize();
if(serverless.processedInput) {
if (serverless.processedInput) {
expect(slsw.options).to.equal(processedOptions);
} else {
// serverless.processedInput does not exist in serverless@<2.0.0
Expand Down
6 changes: 3 additions & 3 deletions lib/wpwatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ module.exports = {
callback();
} else if (canEmit && currentCompileWatch === null) {
// eslint-disable-next-line promise/no-promise-in-callback
currentCompileWatch = BbPromise.resolve(
this.serverless.pluginManager.spawn('webpack:compile:watch')
).then(() => this.serverless.cli.log('Watching for changes...'));
currentCompileWatch = BbPromise.resolve(this.serverless.pluginManager.spawn('webpack:compile:watch')).then(
() => this.serverless.cli.log('Watching for changes...')
);
}
});
};
Expand Down
1 change: 0 additions & 1 deletion tests/compile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ describe('compile', () => {
webpackMock.compilerMock.run.reset();
webpackMock.compilerMock.run.yields(null, multiStats);
return expect(module.compile()).to.be.fulfilled.then(() => {
console.log(JSON.stringify(module.compileStats.stats[0].externalModules));
expect(module.compileStats.stats[0].externalModules).to.eql([
{ external: '@scoped/vendor', origin: undefined },
{ external: 'uuid', origin: undefined },
Expand Down
42 changes: 42 additions & 0 deletions tests/validate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,48 @@ describe('validate', () => {
});
});

it('should throw error if container image is not well defined', () => {
const testOutPath = 'test';
const testFunctionsConfig = {
func1: {
artifact: 'artifact-func1.zip',
events: [
{
http: {
method: 'POST',
path: 'func1path'
}
},
{
nonhttp: 'non-http'
}
],
image: {
name: 'custom-image',
command: []
}
}
};

const testConfig = {
entry: 'test',
context: 'testcontext',
output: {
path: testOutPath
},
getFunction: func => {
return testFunctionsConfig[func];
}
};

_.set(module.serverless.service, 'custom.webpack.config', testConfig);
module.serverless.service.functions = testFunctionsConfig;
globSyncStub.callsFake(filename => [_.replace(filename, '*', 'js')]);
expect(() => {
module.validate();
}).to.throw(/Either function.handler or function.image must be defined/);
});

describe('google provider', () => {
beforeEach(() => {
_.set(module.serverless, 'service.provider.name', 'google');
Expand Down

0 comments on commit b4a7014

Please sign in to comment.