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

Fix configuration check for keepoutputdirectory in cleanup #748

Merged
merged 1 commit into from
Apr 6, 2021
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 lib/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const fse = require('fs-extra');
module.exports = {
cleanup() {
const webpackOutputPath = this.webpackOutputPath;
const keepOutputDirectory = this.keepOutputDirectory;
const keepOutputDirectory = this.keepOutputDirectory || this.configuration.keepOutputDirectory;
const cli = this.options.verbose ? this.serverless.cli : { log: _.noop };

if (!keepOutputDirectory) {
Expand Down
29 changes: 18 additions & 11 deletions tests/cleanup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const chai = require('chai');
const sinon = require('sinon');
const mockery = require('mockery');
const Serverless = require('serverless');
const Configuration = require('../lib/Configuration');

chai.use(require('chai-as-promised'));
chai.use(require('sinon-chai'));
Expand Down Expand Up @@ -58,7 +59,8 @@ describe('cleanup', () => {
options: {
verbose: true
},
webpackOutputPath: 'my/Output/Path'
webpackOutputPath: 'my/Output/Path',
configuration: new Configuration()
},
baseModule
);
Expand Down Expand Up @@ -88,16 +90,7 @@ describe('cleanup', () => {
dirExistsSyncStub.returns(true);
fseMock.remove.resolves(true);

module = _.assign(
{
serverless,
options: {
verbose: false
},
webpackOutputPath: 'my/Output/Path'
},
baseModule
);
module = _.assign({}, module, { options: { verbose: false } });

return expect(module.cleanup()).to.be.fulfilled.then(() => {
expect(dirExistsSyncStub).to.have.been.calledOnce;
Expand Down Expand Up @@ -142,4 +135,18 @@ describe('cleanup', () => {
return null;
});
});

it('should keep output dir if keepOutputDir = true in configuration', () => {
dirExistsSyncStub.returns(true);

const configuredModule = _.assign({}, module, {
configuration: new Configuration({ webpack: { keepOutputDirectory: true } })
});

return expect(configuredModule.cleanup()).to.be.fulfilled.then(() => {
expect(dirExistsSyncStub).to.not.have.been.calledOnce;
expect(fseMock.remove).to.not.have.been.called;
return null;
});
});
});