From 7cda0491d43055a7b79f8eb5da7787c1d4eb5c58 Mon Sep 17 00:00:00 2001 From: Daryl Carr Date: Sun, 28 Mar 2021 16:46:15 +0300 Subject: [PATCH] Add configuration check for keepoutputir in cleanup --- lib/cleanup.js | 2 +- tests/cleanup.test.js | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/cleanup.js b/lib/cleanup.js index 9664c9bb5..4f354530f 100644 --- a/lib/cleanup.js +++ b/lib/cleanup.js @@ -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) { diff --git a/tests/cleanup.test.js b/tests/cleanup.test.js index dec18893a..a24698867 100644 --- a/tests/cleanup.test.js +++ b/tests/cleanup.test.js @@ -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')); @@ -58,7 +59,8 @@ describe('cleanup', () => { options: { verbose: true }, - webpackOutputPath: 'my/Output/Path' + webpackOutputPath: 'my/Output/Path', + configuration: new Configuration() }, baseModule ); @@ -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; @@ -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; + }); + }); });