Skip to content

Commit

Permalink
Merge pull request #748 from daryl-c/fix-keepoutputdirectory-cleanup
Browse files Browse the repository at this point in the history
Fix configuration check for keepoutputdirectory in cleanup
  • Loading branch information
j0k3r authored Apr 6, 2021
2 parents 9d87ddb + 7cda049 commit ac82119
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
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;
});
});
});

0 comments on commit ac82119

Please sign in to comment.