Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(build): remove bower dependency, update npm to install angular, u…
Browse files Browse the repository at this point in the history
…pdate Jasmine 2

update tests to use ^0.12.2 and Jasmine 2
- Use of jasmine.addMatchers with revised APIs
- Update Jasmine 2 APIs

Fixes #1962.
  • Loading branch information
ThomasBurleson committed Apr 10, 2015
1 parent f881b97 commit 9398a7a
Show file tree
Hide file tree
Showing 26 changed files with 204 additions and 184 deletions.
4 changes: 0 additions & 4 deletions .bowerrc

This file was deleted.

25 changes: 0 additions & 25 deletions bower.json

This file was deleted.

1 change: 0 additions & 1 deletion config/build.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var pkg = require('../package.json');
var bower = require('../bower.json');
var fs = require('fs');
var versionFile = __dirname + '/../dist/commit';

Expand Down
10 changes: 5 additions & 5 deletions config/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ module.exports = function(config) {
// releaseMode is a custom configuration option.
var testSrc = process.env.KARMA_TEST_COMPRESSED ? COMPILED_SRC : UNCOMPILED_SRC;
var dependencies = process.env.KARMA_TEST_JQUERY ?
['bower_components/jquery/dist/jquery.js'] : [];
['node_modules/jquery/dist/jquery.js'] : [];

dependencies = dependencies.concat([
'bower_components/angular/angular.js',
'bower_components/angular-animate/angular-animate.js',
'bower_components/angular-aria/angular-aria.js',
'bower_components/angular-mocks/angular-mocks.js',
'node_modules/angular/angular.js',
'node_modules/angular-animate/angular-animate.js',
'node_modules/angular-aria/angular-aria.js',
'node_modules/angular-mocks/angular-mocks.js',
'config/test-utils.js'
]);

Expand Down
92 changes: 63 additions & 29 deletions config/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var TestUtil = {
};
});
// Un-mock focus after the test is done
test.after(function() {
afterEach(function() {
angular.element.prototype.focus = focus;
});
},
Expand All @@ -41,46 +41,80 @@ beforeEach(function() {
};
});

this.addMatchers({
// toHaveClass matcher from angularjs test helpers
toHaveClass: function(clazz) {
this.message = function() {
return "Expected '" + angular.mock.dump(this.actual) +
(this.isNot ? ' not' : '') + " to have class '" + clazz + "'.";
};
var classes = clazz.trim().split(/\s+/);
for (var i=0; i<classes.length; ++i) {
if (!angular.element(this.actual).hasClass(classes[i])) {
return false;
jasmine.addMatchers({

toHaveClass: function() {
return {
compare: function(actual, expected) {
var results = { pass : true };
var classes = expected.trim().split(/\s+/);

for (var i=0; i<classes.length; ++i) {
if (!angular.element(actual).hasClass(classes[i])) {
results.pass = false;
}
}

var negation = !results.pass ? "" : " not ";

results.message = "";
results.message += "Expected '";
results.message += angular.mock.dump(actual);
results.message += negation + "to have class '" + expected + "'.";

return results;
}
}
return true;
};
},

/**
* A helper to match the type of a given value
* @example expect(1).toBeOfType('number')
*/
toBeOfType: function(type) {
this.message = function() {
return "Expected " + angular.mock.dump(this.actual) + " of type " +
(typeof this.actual) + (this.isNot ? ' not ' : '') + " to have type '" + type + "'.";
return {
compare: function(actual, expected) {
var results = {
pass : typeof actual == expected
};

var negation = !results.pass ? "" : " not ";

results.message = "";
results.message += "Expected ";
results.message += angular.mock.dump(actual) + " of type ";
results.message += (typeof actual);
results.message += negation + "to have type '" + type + "'.";

return results;
}
};
return typeof this.actual == type;
},

toHaveFields: function(fields) {
this.message = function() {
return "Expected " + angular.mock.dump(this.actual) + (this.isNot ? ' not ' : ' ') +
"to have fields matching " + angular.mock.dump(fields);
};
for (var key in fields) {
if (!(this.actual || {}).hasOwnProperty(key) ||
!angular.equals(this.actual[key], fields[key])) {
return false;
toHaveFields: function() {
return {
compare: function(actual, expected) {
var results = { pass : true };

for (var key in expected) {
if (!(actual || {}).hasOwnProperty(key) || !angular.equals(actual[key], expected[key])) {
results.pass = false;
}
}

var negation = !results.pass ? "" : " not ";

results.message = "";
results.message += "Expected ";
results.message += angular.mock.dump(actual) + " of type ";
results.message += (typeof actual);
results.message += negation + "to have fields matching '" + angular.mock.dump(expected);

return results;
}
}
return true;
};
}

});

});
8 changes: 4 additions & 4 deletions docs/config/template/demo-index.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<title><%= name %></title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1" />

<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/angular-animate/angular-animate.js"></script>
<script src="/bower_components/angular-messages/angular-messages.js"></script>
<script src="/bower_components/angular-aria/angular-aria.js"></script>
<script src="/node_modules/angular/angular.js"></script>
<script src="/node_modules/angular-animate/angular-animate.js"></script>
<script src="/node_modules/angular-aria/angular-aria.js"></script>
<script src="/node_modules/angular-messages/angular-messages.js"></script>
<script src="/dist/angular-material.js"></script>

<link rel="stylesheet" href="/dist/angular-material.css">
Expand Down
21 changes: 15 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,48 @@
"url": "git://github.com/angular/material.git"
},
"devDependencies": {
"angular": "^1.3.15 || >1.4.0-beta.0",
"angular-animate": "^1.3.15 || >1.4.0-beta.0",
"angular-aria": "^1.3.15 || >1.4.0-beta.0",
"angular-messages": "^1.3.0 || >1.4.0-beta.0",
"angular-mocks": "^1.3.0 || >1.4.0-beta.0",
"angular-route": "^1.3.0 || >1.4.0-beta.0",
"angularytics": "^0.3.0",
"canonical-path": "0.0.2",
"conventional-changelog": "0.0.9",
"dgeni": "^0.4.1",
"dgeni-packages": "^0.10.3",
"esprima": "^1.2.2",
"glob": "~4.0.2",
"gulp": "^3.6.2",
"gulp": "^3.8.11",
"gulp-autoprefixer": "^1.0.1",
"gulp-concat": "^2.2.0",
"gulp-filter": "^1.0.2",
"gulp-if": "^1.2.0",
"gulp-insert": "^0.4.0",
"gulp-jshint": "^1.5.5",
"gulp-minify-css": "^0.3.4",
"gulp-ng-annotate": "^0.5.0",
"gulp-ng-annotate": "^0.5.2",
"gulp-ng-html2js": "^0.1.8",
"gulp-plumber": "^0.6.6",
"gulp-plumber": "^1.0.0",
"gulp-rename": "^1.2.0",
"gulp-sass": "ajoslin/gulp-sass#master",
"gulp-uglify": "^0.3.0",
"gulp-util": "^3.0.1",
"gulp-webserver": "^0.8.3",
"jasmine-core": "^2.2.0",
"jshint-summary": "^0.3.0",
"karma": "^0.12.16",
"karma": "~0.12.0",
"karma-chrome-launcher": "^0.1.4",
"karma-firefox-launcher": "^0.1.3",
"karma-jasmine": "^0.1.5",
"karma-jasmine": "^0.2.2",
"karma-phantomjs-launcher": "~0.1.4",
"karma-safari-launcher": "^0.1.1",
"karma-sauce-launcher": "^0.2.10",
"lazypipe": "^0.2.2",
"lodash": "^2.4.1",
"minimist": "^0.1.0",
"merge-stream": "^0.1.6",
"minimist": "^1.1.0",
"mkdirp": "^0.5.0",
"q": "^1.0.1",
"stream-series": "^0.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ function run {
git clone https://angular:$GH_TOKEN@github.com/angular/bower-material \
bower-material --depth=2

echo "-- Copying dependencies to external bower-material..."
BOWER_JSON=$(node -p 'var internalBower = require("./bower.json");
var externalBower = require("./bower-material/bower.json");
externalBower.dependencies = internalBower.dependencies;
JSON.stringify(externalBower, null, 2);')
echo $BOWER_JSON > bower-material/bower.json

echo "-- Copying in build files..."
cp -Rf dist/* bower-material/

Expand Down
5 changes: 2 additions & 3 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ function run {
exit 1
fi

./scripts/bower-release.sh --version=$VERSION
./scripts/bower-material-release.sh --version=$VERSION

replaceJsonProp "bower.json" "version" "$VERSION"
replaceJsonProp "package.json" "version" "$VERSION"

echo "-- Committing, tagging and pushing bower.json and package.json..."
git commit bower.json package.json -m "release: version $VERSION"
git commit package.json -m "release: version $VERSION"
git tag -f v$VERSION
git push -q origin master
git push -q origin v$VERSION
Expand Down
14 changes: 7 additions & 7 deletions src/components/autocomplete/autocomplete.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ describe('<md-autocomplete>', function() {
element.scope().$apply();

expect(scope.itemChanged).toHaveBeenCalled();
expect(scope.itemChanged.mostRecentCall.args[0].display).toBe('foo');
expect(scope.itemChanged.calls.mostRecent().args[0].display).toBe('foo');
expect(registeredWatcher).toHaveBeenCalled();
expect(registeredWatcher.mostRecentCall.args[0].display).toBe('foo');
expect(registeredWatcher.mostRecentCall.args[1]).toBeNull();
expect(registeredWatcher.calls.mostRecent().args[0].display).toBe('foo');
expect(registeredWatcher.calls.mostRecent().args[1]).toBeNull();
expect(scope.selectedItem).not.toBeNull();
expect(scope.selectedItem.display).toBe('foo');

Expand All @@ -143,11 +143,11 @@ describe('<md-autocomplete>', function() {
ctrl.clear();
element.scope().$apply();

expect(registeredWatcher.callCount).toBe(1);
expect(scope.itemChanged.callCount).toBe(2);
expect(scope.itemChanged.mostRecentCall.args[0]).toBeUndefined();
expect(registeredWatcher.calls.count()).toBe(1);
expect(scope.itemChanged.calls.count()).toBe(2);
expect(scope.itemChanged.calls.mostRecent().args[0]).toBeUndefined();
expect(scope.selectedItem).toBe(null);
}));
});

});
});
2 changes: 1 addition & 1 deletion src/components/button/button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('md-button', function() {
$rootScope.$apply();
expect($log.warn).toHaveBeenCalled();

$log.warn.reset();
$log.warn.calls.reset();
button = $compile('<md-button aria-label="something"><md-icon></md-icon></md-button>')($rootScope);
$rootScope.$apply();
expect($log.warn).not.toHaveBeenCalled();
Expand Down
8 changes: 4 additions & 4 deletions src/components/chips/chips.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ describe('<md-chips>', function() {
var ctrl = element.controller('mdChips');

var doubleText = function (text) { return "" + text + text; };
scope.appendChip = jasmine.createSpy('appendChip').andCallFake(doubleText);
scope.appendChip = jasmine.createSpy('appendChip').and.callFake(doubleText);

element.scope().$apply(function() {
ctrl.chipBuffer = 'Grape';
simulateInputEnterKey(ctrl);
});

expect(scope.appendChip).toHaveBeenCalled();
expect(scope.appendChip.mostRecentCall.args[0]).toBe('Grape');
expect(scope.appendChip.calls.mostRecent().args[0]).toBe('Grape');
expect(scope.items.length).toBe(4);
expect(scope.items[3]).toBe('GrapeGrape');
});
Expand All @@ -117,15 +117,15 @@ describe('<md-chips>', function() {
};
};

scope.appendChip = jasmine.createSpy('appendChip').andCallFake(chipObj);
scope.appendChip = jasmine.createSpy('appendChip').and.callFake(chipObj);

element.scope().$apply(function() {
ctrl.chipBuffer = 'Grape';
simulateInputEnterKey(ctrl);
});

expect(scope.appendChip).toHaveBeenCalled();
expect(scope.appendChip.mostRecentCall.args[0]).toBe('Grape');
expect(scope.appendChip.calls.mostRecent().args[0]).toBe('Grape');
expect(scope.items.length).toBe(4);
expect(scope.items[3].name).toBe('Grape');
expect(scope.items[3].uppername).toBe('GRAPE');
Expand Down
4 changes: 2 additions & 2 deletions src/components/chips/contact-chips.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('<md-contact-chips>', function() {

describe('filtering selected items', function() {
it('should filter when enabled', inject(function($timeout) {
scope.querySearch = jasmine.createSpy('querySearch').andCallFake(function(q) {
scope.querySearch = jasmine.createSpy('querySearch').and.callFake(function(q) {
return scope.allContacts;
});
scope.contacts.push(scope.allContacts[2]);
Expand All @@ -66,7 +66,7 @@ describe('<md-contact-chips>', function() {
}));

it('should not filter when disabled', inject(function($timeout) {
scope.querySearch = jasmine.createSpy('querySearch').andCallFake(function(q) {
scope.querySearch = jasmine.createSpy('querySearch').and.callFake(function(q) {
return scope.allContacts;
});
scope.contacts.push(scope.allContacts[2]);
Expand Down
4 changes: 2 additions & 2 deletions src/components/dialog/dialog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ describe('$mdDialog', function() {
beforeEach(module('material.components.dialog', 'ngAnimateMock'));

beforeEach(inject(function spyOnMdEffects($$q, $animate) {
spyOn($animate, 'leave').andCallFake(function(element) {
spyOn($animate, 'leave').and.callFake(function(element) {
element.remove();
return $$q.when();
});
spyOn($animate, 'enter').andCallFake(function(element, parent) {
spyOn($animate, 'enter').and.callFake(function(element, parent) {
parent.append(element);
return $$q.when();
});
Expand Down
2 changes: 1 addition & 1 deletion src/components/slider/slider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('md-slider', function() {
spyOn(
slider[0].querySelector('.md-track-container'),
'getBoundingClientRect'
).andReturn(angular.extend({
).and.returnValue(angular.extend({
width: 100,
left: 0,
right: 0
Expand Down
Loading

0 comments on commit 9398a7a

Please sign in to comment.