From 37d9e0f299f99219c3f4a89aec9d29ecc27f19d9 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Wed, 13 Oct 2021 13:02:32 +0200 Subject: [PATCH] fix: Fix processing resolution --- lib/run.js | 43 +++++++++++++++++++++++-------------------- tests/run.test.js | 2 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/run.js b/lib/run.js index fb964aa50..fbb8bf46e 100644 --- a/lib/run.js +++ b/lib/run.js @@ -21,29 +21,32 @@ module.exports = { this.serverless.cli.log(`Enabled polling (${watchOptions.poll} ms)`); } - compiler.watch(watchOptions, (err /*, stats */) => { - if (err) { - throw err; - } - // eslint-disable-next-line promise/catch-or-return, promise/no-promise-in-callback - BbPromise.try(() => { - if (this.originalServicePath) { - process.chdir(this.originalServicePath); - this.serverless.config.servicePath = this.originalServicePath; + return new BbPromise((resolve, reject) => { + compiler.watch(watchOptions, (err /*, stats */) => { + if (err) { + reject(err); + return; } + // eslint-disable-next-line promise/catch-or-return, promise/no-promise-in-callback + BbPromise.try(() => { + if (this.originalServicePath) { + process.chdir(this.originalServicePath); + this.serverless.config.servicePath = this.originalServicePath; + } - if (!this.isWatching) { - this.isWatching = true; - return BbPromise.resolve(); - } + if (!this.isWatching) { + this.isWatching = true; + return BbPromise.resolve(); + } - this.serverless.cli.log('Sources changed.'); - if (_.isFunction(command)) { - return command(); - } - this.options.verbose && this.serverless.cli.log(`Invoke ${command}`); - return this.serverless.pluginManager.spawn(command); - }).then(() => this.serverless.cli.log('Waiting for changes ...')); + this.serverless.cli.log('Sources changed.'); + if (_.isFunction(command)) { + return command(); + } + this.options.verbose && this.serverless.cli.log(`Invoke ${command}`); + return this.serverless.pluginManager.spawn(command); + }).then(() => this.serverless.cli.log('Waiting for changes ...'), reject); + }); }); } }; diff --git a/tests/run.test.js b/tests/run.test.js index 5efa2b83a..7cc191b1c 100644 --- a/tests/run.test.js +++ b/tests/run.test.js @@ -76,7 +76,7 @@ describe('run', () => { const watch = module.watch.bind(module); webpackMock.compilerMock.watch = sandbox.stub().yields(new Error('Failed')); - expect(() => watch()).to.throw('Failed'); + expect(watch()).to.eventually.be.rejectedWith('Failed'); }); it('should not spawn invoke local on first run', () => {