Skip to content

Commit ac82119

Browse files
authored
Merge pull request #748 from daryl-c/fix-keepoutputdirectory-cleanup
Fix configuration check for keepoutputdirectory in cleanup
2 parents 9d87ddb + 7cda049 commit ac82119

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

lib/cleanup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const fse = require('fs-extra');
77
module.exports = {
88
cleanup() {
99
const webpackOutputPath = this.webpackOutputPath;
10-
const keepOutputDirectory = this.keepOutputDirectory;
10+
const keepOutputDirectory = this.keepOutputDirectory || this.configuration.keepOutputDirectory;
1111
const cli = this.options.verbose ? this.serverless.cli : { log: _.noop };
1212

1313
if (!keepOutputDirectory) {

tests/cleanup.test.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const chai = require('chai');
66
const sinon = require('sinon');
77
const mockery = require('mockery');
88
const Serverless = require('serverless');
9+
const Configuration = require('../lib/Configuration');
910

1011
chai.use(require('chai-as-promised'));
1112
chai.use(require('sinon-chai'));
@@ -58,7 +59,8 @@ describe('cleanup', () => {
5859
options: {
5960
verbose: true
6061
},
61-
webpackOutputPath: 'my/Output/Path'
62+
webpackOutputPath: 'my/Output/Path',
63+
configuration: new Configuration()
6264
},
6365
baseModule
6466
);
@@ -88,16 +90,7 @@ describe('cleanup', () => {
8890
dirExistsSyncStub.returns(true);
8991
fseMock.remove.resolves(true);
9092

91-
module = _.assign(
92-
{
93-
serverless,
94-
options: {
95-
verbose: false
96-
},
97-
webpackOutputPath: 'my/Output/Path'
98-
},
99-
baseModule
100-
);
93+
module = _.assign({}, module, { options: { verbose: false } });
10194

10295
return expect(module.cleanup()).to.be.fulfilled.then(() => {
10396
expect(dirExistsSyncStub).to.have.been.calledOnce;
@@ -142,4 +135,18 @@ describe('cleanup', () => {
142135
return null;
143136
});
144137
});
138+
139+
it('should keep output dir if keepOutputDir = true in configuration', () => {
140+
dirExistsSyncStub.returns(true);
141+
142+
const configuredModule = _.assign({}, module, {
143+
configuration: new Configuration({ webpack: { keepOutputDirectory: true } })
144+
});
145+
146+
return expect(configuredModule.cleanup()).to.be.fulfilled.then(() => {
147+
expect(dirExistsSyncStub).to.not.have.been.calledOnce;
148+
expect(fseMock.remove).to.not.have.been.called;
149+
return null;
150+
});
151+
});
145152
});

0 commit comments

Comments
 (0)