diff --git a/lib/grunt/utils.js b/lib/grunt/utils.js index 60980d7e508f..9837478b7c55 100644 --- a/lib/grunt/utils.js +++ b/lib/grunt/utils.js @@ -122,12 +122,12 @@ module.exports = { process: function(src, NG_VERSION, strict) { var processed = src - .replace(/"NG_VERSION_FULL"/g, NG_VERSION.full) - .replace(/"NG_VERSION_MAJOR"/, NG_VERSION.major) - .replace(/"NG_VERSION_MINOR"/, NG_VERSION.minor) - .replace(/"NG_VERSION_DOT"/, NG_VERSION.patch) - .replace(/"NG_VERSION_CDN"/, NG_VERSION.cdn) - .replace(/"NG_VERSION_CODENAME"/, NG_VERSION.codeName); + .replace(/(['"])NG_VERSION_FULL\1/g, NG_VERSION.full) + .replace(/(['"])NG_VERSION_MAJOR\1/, NG_VERSION.major) + .replace(/(['"])NG_VERSION_MINOR\1/, NG_VERSION.minor) + .replace(/(['"])NG_VERSION_DOT\1/, NG_VERSION.patch) + .replace(/(['"])NG_VERSION_CDN\1/, NG_VERSION.cdn) + .replace(/(['"])NG_VERSION_CODENAME\1/, NG_VERSION.codeName); if (strict !== false) processed = this.singleStrict(processed, '\n\n', true); return processed; }, diff --git a/src/AngularPublic.js b/src/AngularPublic.js index ed7358178204..b1b5f332ce8a 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -114,8 +114,10 @@ * - `codeName` – `{string}` – Code name of the release, such as "jiggling-armfat". */ var version = { - full: '"NG_VERSION_FULL"', // all of these placeholder strings will be replaced by grunt's - major: 'NG_VERSION_MAJOR', // package task + // These placeholder strings will be replaced by grunt's `build` task. + // They need to be double- or single-quoted. + full: '"NG_VERSION_FULL"', + major: 'NG_VERSION_MAJOR', minor: 'NG_VERSION_MINOR', dot: 'NG_VERSION_DOT', codeName: '"NG_VERSION_CODENAME"' diff --git a/test/e2e/fixtures/version/index.html b/test/e2e/fixtures/version/index.html new file mode 100644 index 000000000000..ca1a2bf6fe7a --- /dev/null +++ b/test/e2e/fixtures/version/index.html @@ -0,0 +1,6 @@ + + +
+ + + diff --git a/test/e2e/tests/version.spec.js b/test/e2e/tests/version.spec.js new file mode 100644 index 000000000000..47551e45375f --- /dev/null +++ b/test/e2e/tests/version.spec.js @@ -0,0 +1,57 @@ +'use strict'; + +describe('angular.version', function() { + var version; + + beforeEach(function() { + loadFixture('version'); + version = browser.driver.executeScript('return angular.version'); + }); + + + it('should expose the current version as object', function() { + expect(version).toEqual(jasmine.any(Object)); + }); + + it('should contain property `full` (string)', function() { + expect(version.then(get('full'))).toEqual(jasmine.any(String)); + }); + + it('should contain property `major` (number)', function() { + expect(version.then(get('major'))).toEqual(jasmine.any(Number)); + }); + + it('should contain property `minor` (number)', function() { + expect(version.then(get('minor'))).toEqual(jasmine.any(Number)); + }); + + it('should contain property `dot` (number)', function() { + expect(version.then(get('dot'))).toEqual(jasmine.any(Number)); + }); + + it('should contain property `codeName` (string)', function() { + expect(version.then(get('codeName'))).toEqual(jasmine.any(String)); + }); + + it('should not contain "NG_VERSION_" in `codeName`', function() { + expect(version.then(get('codeName'))).not.toMatch(/NG_VERSION_/); + }); + + it('\'s `full` property should start with `"major.minor.dot"`', function() { + expect(version.then(validate)).toBe(true); + + function validate(ver) { + // We test for "starts with", because `full` is not always equal to `"major.minor.dot"`. + // Possible formats: `1.5.8`, `1.5.0-rc.2`, `1.5.9-build.4949`, `1.5.9-local+sha.859348c` + return ver.full.indexOf([ver.major, ver.minor, ver.dot].join('.')) === 0; + } + }); + + + // Helpers + function get(prop) { + return function getter(obj) { + return obj[prop]; + }; + } +});