Skip to content

Commit b43a757

Browse files
author
Frank Schmid
committed
Unit tests for --no-build
1 parent 0fc7de3 commit b43a757

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

index.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,17 @@ describe('ServerlessWebpack', () => {
200200
return null;
201201
});
202202
});
203+
204+
it('should skip compile if requested', () => {
205+
slsw.options.build = false;
206+
return expect(slsw.hooks['before:invoke:local:invoke']()).to.be.fulfilled
207+
.then(() => {
208+
expect(slsw.serverless.pluginManager.spawn).to.have.been.calledOnce;
209+
expect(slsw.serverless.pluginManager.spawn).to.have.been.calledWithExactly('webpack:validate');
210+
expect(slsw.prepareLocalInvoke).to.have.been.calledOnce;
211+
return null;
212+
});
213+
});
203214
}
204215
},
205216
{

tests/mocks/fs-extra.mock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports.create = sandbox => {
88
const fsExtraMock = {
99
copy: sandbox.stub().yields(),
1010
pathExists: sandbox.stub().yields(),
11+
pathExistsSync: sandbox.stub().returns(false),
1112
removeSync: sandbox.stub()
1213
};
1314

tests/validate.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ describe('validate', () => {
5353

5454
afterEach(() => {
5555
fsExtraMock.removeSync.reset();
56+
fsExtraMock.pathExistsSync.reset();
5657
sandbox.restore();
5758
});
5859

@@ -733,6 +734,38 @@ describe('validate', () => {
733734
});
734735
});
735736
});
737+
});
736738

739+
describe('with skipped builds', () => {
740+
it('should keep output directory', () => {
741+
const testConfig = {
742+
entry: 'test',
743+
output: {},
744+
};
745+
const testServicePath = 'testpath';
746+
module.serverless.config.servicePath = testServicePath;
747+
_.set(module.serverless.service, 'custom.webpack.config', testConfig);
748+
module.skipCompile = true;
749+
fsExtraMock.pathExistsSync.returns(true);
750+
return module
751+
.validate()
752+
.then(() => {
753+
expect(module.keepOutputDirectory).to.be.true;
754+
return null;
755+
});
756+
});
757+
758+
it('should fail without exiting output', () => {
759+
const testConfig = {
760+
entry: 'test',
761+
output: {},
762+
};
763+
const testServicePath = 'testpath';
764+
module.serverless.config.servicePath = testServicePath;
765+
_.set(module.serverless.service, 'custom.webpack.config', testConfig);
766+
module.skipCompile = true;
767+
fsExtraMock.pathExistsSync.returns(false);
768+
return expect(module.validate()).to.be.rejectedWith(/No compiled output found/);
769+
});
737770
});
738771
});

0 commit comments

Comments
 (0)