From d6ff8287a4cd52ac923f702e20d17bcd3ae9791a Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 23 Jan 2019 12:58:52 +0100 Subject: [PATCH] Add a public method to know whether the runtime is configured --- index.js | 5 +++++ test/index.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/index.js b/index.js index c05e3587..e5bc5af2 100644 --- a/index.js +++ b/index.js @@ -1157,6 +1157,10 @@ class Encore { return this; } + isRuntimeEnvironmentConfigured() { + return runtimeConfig !== null; + } + /** * Clear the runtime environment. * @@ -1213,6 +1217,7 @@ const EncoreProxy = new Proxy(new Encore(), { const safeMethods = [ 'configureRuntimeEnvironment', 'clearRuntimeEnvironment', + 'isRuntimeEnvironmentConfigured', ]; if (!webpackConfig && (safeMethods.indexOf(prop) === -1)) { diff --git a/test/index.js b/test/index.js index 0516c64f..abc649de 100644 --- a/test/index.js +++ b/test/index.js @@ -414,6 +414,22 @@ describe('Public API', () => { }); + describe('isRuntimeEnvironmentConfigured', () => { + + it('should return true if the runtime environment has been configured', () => { + const returnedValue = api.isRuntimeEnvironmentConfigured(); + expect(returnedValue).to.be.true; + }); + + it('should return false if the runtime environment has not been configured', () => { + api.clearRuntimeEnvironment(); + + const returnedValue = api.isRuntimeEnvironmentConfigured(); + expect(returnedValue).to.be.false; + }); + + }); + describe('Runtime environment proxy', () => { beforeEach(() => { api.clearRuntimeEnvironment();