Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

chore(build): fix version placeholder matching #15016

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/grunt/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could find this anywhere inside the codebase. It is probably not needed, but left it just in case.

.replace(/(['"])NG_VERSION_CODENAME\1/, NG_VERSION.codeName);
if (strict !== false) processed = this.singleStrict(processed, '\n\n', true);
return processed;
},
Expand Down
6 changes: 4 additions & 2 deletions src/AngularPublic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"'
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/fixtures/version/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html ng-app>
<body>
<script src="angular.js"></script>
</body>
</html>
57 changes: 57 additions & 0 deletions test/e2e/tests/version.spec.js
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just ver.full === [ver.major, ver.minor, ver.dot].join('.')?

Copy link
Member Author

@gkalpak gkalpak Aug 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not always true. E.g. full can be 1.5.0-rc.2 or 1.5.9-build.4949 or 1.5.9-local+sha.859348c (this last one is what we actually have in the tests most of the time).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Can you add a comment with that info?

}
});


// Helpers
function get(prop) {
return function getter(obj) {
return obj[prop];
};
}
});