From c1e1f69bc49c1f00061d6ff99ecee498e9ef59c6 Mon Sep 17 00:00:00 2001 From: Yusinto Ngadiman Date: Fri, 9 Sep 2016 23:35:28 +1000 Subject: [PATCH] Added 'undefined' check on VERSION otherwise unbundled usage from npm fails --- package.json | 15 ++++++++------- src/__tests__/LDClient-test.js | 13 +++++++++++++ src/index.js | 7 +++++-- 3 files changed, 26 insertions(+), 9 deletions(-) mode change 100644 => 100755 package.json diff --git a/package.json b/package.json old mode 100644 new mode 100755 index 0d68f465..eac01f02 --- a/package.json +++ b/package.json @@ -25,24 +25,25 @@ }, "devDependencies": { "chai": "3.5.0", + "gzip-size": "3.0.0", + "in-publish": "2.0.0", "karma": "0.13.22", "karma-chai": "0.1.0", + "karma-chrome-launcher": "1.0.1", "karma-mocha": "1.0.1", "karma-mocha-reporter": "2.0.4", - "karma-chrome-launcher": "1.0.1", "karma-phantomjs-launcher": "0.2.1", "karma-phantomjs-shim": "1.1.2", + "karma-sinon": "1.0.5", "karma-sourcemap-loader": "0.3.7", "karma-webpack": "1.7.0", - "karma-sinon": "1.0.5", "mocha": "2.5.3", "phantomjs": "1.9.18", - "sinon": "1.17.4", - "webpack": "1.13.1", - "gzip-size": "3.0.0", - "in-publish": "2.0.0", "pretty-bytes": "3.0.1", - "readline-sync": "1.4.4" + "readline-sync": "1.4.4", + "semver-compare": "^1.0.0", + "sinon": "1.17.4", + "webpack": "1.13.1" }, "dependencies": { "Base64": "1.0.0", diff --git a/src/__tests__/LDClient-test.js b/src/__tests__/LDClient-test.js index c5e4c21f..43358e32 100644 --- a/src/__tests__/LDClient-test.js +++ b/src/__tests__/LDClient-test.js @@ -1,4 +1,5 @@ var LDClient = require('../index'); +var semverCompare = require('semver-compare'); describe('LDClient', function() { var xhr; @@ -45,6 +46,18 @@ describe('LDClient', function() { var settingsRequest = requests[0]; expect(/sdk\/eval/.test(settingsRequest.url)).to.be.false; }); + + it('should contain package version', function () { + // Arrange + var version = LDClient.version; + + // Act: all client bundles above 1.0.7 should contain package version + // https://github.com/substack/semver-compare + var result = semverCompare(version, '1.0.6'); + + // Assert + expect(result).to.equal(1); + }); }); }); diff --git a/src/index.js b/src/index.js index 668d5f82..9ef2fced 100644 --- a/src/index.js +++ b/src/index.js @@ -282,6 +282,9 @@ function initialize(env, user, options) { } module.exports = { - initialize: initialize, - version: VERSION + initialize: initialize }; + +if(typeof VERSION !== 'undefined') { + module.exports.version = VERSION; +} \ No newline at end of file