From 337b9a9418e6247bcf0a7921b99ec35a891d548a Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Fri, 12 Aug 2016 02:25:48 +0300 Subject: [PATCH 1/4] chore(build): fix version placeholder matching During the `build` task, the version placeholders will be replaced with the actual values using a RegExp, which expects the placeholders to be surrounded by double quotes. By replacing the quotes from double to single in #15011, the RegExp was not able to match the placeholders. (For reference, the RegExps that match and replace the version placeholders are in [lib/grunt/utils.js][1].) [1]: https://github.com/angular/angular.js/blob/859348c7f61ff5f93b9f81eb7f46842bd018d8e3/lib/grunt/utils.js#L125-L130 --- src/AngularPublic.js | 12 ++++--- test/e2e/fixtures/version/index.html | 6 ++++ test/e2e/tests/version.spec.js | 51 ++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 test/e2e/fixtures/version/index.html create mode 100644 test/e2e/tests/version.spec.js diff --git a/src/AngularPublic.js b/src/AngularPublic.js index ed7358178204..9ddcca2a1fe1 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -114,11 +114,15 @@ * - `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 - minor: 'NG_VERSION_MINOR', - dot: 'NG_VERSION_DOT', + // These placeholder strings will be replaced by grunt's `build` task. + // They need to be surrounded by double-quotes. + /* eslint-disable quotes */ + full: '"NG_VERSION_FULL"', + major: "NG_VERSION_MAJOR", + minor: "NG_VERSION_MINOR", + dot: "NG_VERSION_DOT", codeName: '"NG_VERSION_CODENAME"' + /* eslint-enable quotes */ }; 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..4911f46ac31e --- /dev/null +++ b/test/e2e/tests/version.spec.js @@ -0,0 +1,51 @@ +'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 have `full` === `"major.minor.dot"`', function() { + expect(version.then(validate)).toBe(true); + + function validate(ver) { + return ver.full.indexOf([ver.major, ver.minor, ver.dot].join('.')) === 0; + } + }); + + + // Helpers + function get(prop) { + return function getter(obj) { + return obj[prop]; + }; + } +}); From 6883eb481ab29989999e9e5bd4bc638790f4c098 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Fri, 12 Aug 2016 11:45:13 +0300 Subject: [PATCH 2/4] fixup! chore(build): fix version placeholder matching --- test/e2e/tests/version.spec.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/e2e/tests/version.spec.js b/test/e2e/tests/version.spec.js index 4911f46ac31e..baec687a9848 100644 --- a/test/e2e/tests/version.spec.js +++ b/test/e2e/tests/version.spec.js @@ -33,6 +33,10 @@ describe('angular.version', 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('should have `full` === `"major.minor.dot"`', function() { expect(version.then(validate)).toBe(true); From 07e69580b765a505c96e902380155da92363f3ed Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Fri, 12 Aug 2016 12:24:51 +0300 Subject: [PATCH 3/4] fixup! chore(build): fix version placeholder matching --- test/e2e/tests/version.spec.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/e2e/tests/version.spec.js b/test/e2e/tests/version.spec.js index baec687a9848..47551e45375f 100644 --- a/test/e2e/tests/version.spec.js +++ b/test/e2e/tests/version.spec.js @@ -37,10 +37,12 @@ describe('angular.version', function() { expect(version.then(get('codeName'))).not.toMatch(/NG_VERSION_/); }); - it('should have `full` === `"major.minor.dot"`', function() { + 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; } }); From c3adae995c34177c4b1b3911a51cbd79d0b1a454 Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Fri, 12 Aug 2016 17:51:40 +0300 Subject: [PATCH 4/4] fixup! chore(build): fix version placeholder matching --- lib/grunt/utils.js | 12 ++++++------ src/AngularPublic.js | 10 ++++------ 2 files changed, 10 insertions(+), 12 deletions(-) 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 9ddcca2a1fe1..b1b5f332ce8a 100644 --- a/src/AngularPublic.js +++ b/src/AngularPublic.js @@ -115,14 +115,12 @@ */ var version = { // These placeholder strings will be replaced by grunt's `build` task. - // They need to be surrounded by double-quotes. - /* eslint-disable quotes */ + // They need to be double- or single-quoted. full: '"NG_VERSION_FULL"', - major: "NG_VERSION_MAJOR", - minor: "NG_VERSION_MINOR", - dot: "NG_VERSION_DOT", + major: 'NG_VERSION_MAJOR', + minor: 'NG_VERSION_MINOR', + dot: 'NG_VERSION_DOT', codeName: '"NG_VERSION_CODENAME"' - /* eslint-enable quotes */ };