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

Commit 3930720

Browse files
authored
test(modules): properly isolate module tests
Closes #16712
1 parent 52ad819 commit 3930720

File tree

8 files changed

+139
-31
lines changed

8 files changed

+139
-31
lines changed

Gruntfile.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,16 @@ module.exports = function(grunt) {
141141
'jquery-2.2': 'karma-jquery-2.2.conf.js',
142142
'jquery-2.1': 'karma-jquery-2.1.conf.js',
143143
docs: 'karma-docs.conf.js',
144-
modules: 'karma-modules.conf.js'
144+
'modules-ngAnimate': 'ngAnimate',
145+
'modules-ngAria': 'ngAria',
146+
'modules-ngCookies': 'ngCookies',
147+
'modules-ngMessageFormat': 'ngMessageFormat',
148+
'modules-ngMessages': 'ngMessages',
149+
'modules-ngMock': 'ngMock',
150+
'modules-ngResource': 'ngResource',
151+
'modules-ngRoute': 'ngRoute',
152+
'modules-ngSanitize': 'ngSanitize',
153+
'modules-ngTouch': 'ngTouch'
145154
},
146155

147156

@@ -430,7 +439,16 @@ module.exports = function(grunt) {
430439
grunt.registerTask('test:jquery-2.1', 'Run the jQuery 2.1 unit tests with Karma', ['tests:jquery-2.1']);
431440
grunt.registerTask('test:modules', 'Run the Karma module tests with Karma', [
432441
'build',
433-
'tests:modules'
442+
'tests:modules-ngAnimate',
443+
'tests:modules-ngAria',
444+
'tests:modules-ngCookies',
445+
'tests:modules-ngMessageFormat',
446+
'tests:modules-ngMessages',
447+
'tests:modules-ngMock',
448+
'tests:modules-ngResource',
449+
'tests:modules-ngRoute',
450+
'tests:modules-ngSanitize',
451+
'tests:modules-ngTouch'
434452
]);
435453
grunt.registerTask('test:docs', 'Run the doc-page tests with Karma', ['package', 'tests:docs']);
436454
grunt.registerTask('test:unit', 'Run unit, jQuery and Karma module tests with Karma', [

angularFiles.js

+86-13
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,84 @@ var angularFiles = {
189189
'src/angular.bind.js'
190190
],
191191

192-
'karmaModules': [
192+
'karmaModulesBase': [
193193
'build/angular.js',
194-
'@angularSrcModules',
194+
'build/angular-mocks.js',
195195
'test/modules/no_bootstrap.js',
196-
'test/helpers/*.js',
197-
'test/ngAnimate/*.js',
198-
'test/ngMessageFormat/*.js',
199-
'test/ngMessages/*.js',
200-
'test/ngMock/*.js',
201-
'test/ngCookies/*.js',
202-
'test/ngRoute/**/*.js',
203-
'test/ngResource/*.js',
204-
'test/ngSanitize/**/*.js',
205-
'test/ngTouch/**/*.js',
206-
'test/ngAria/*.js'
196+
'test/helpers/matchers.js',
197+
'test/helpers/privateMocks.js',
198+
'test/helpers/support.js',
199+
'test/helpers/testabilityPatch.js'
200+
],
201+
202+
'karmaModules-ngAnimate': [
203+
'@karmaModulesBase',
204+
'@angularSrcModuleNgAnimate',
205+
'test/ngAnimate/**/*.js'
206+
],
207+
208+
'karmaModules-ngAria': [
209+
'@karmaModulesBase',
210+
'@angularSrcModuleNgAria',
211+
'test/ngAria/**/*.js'
212+
],
213+
214+
'karmaModules-ngCookies': [
215+
'@karmaModulesBase',
216+
'@angularSrcModuleNgCookies',
217+
'test/ngCookies/**/*.js'
218+
],
219+
220+
'karmaModules-ngMessageFormat': [
221+
'@karmaModulesBase',
222+
'@angularSrcModuleNgMessageFormat',
223+
'test/ngMessageFormat/**/*.js'
224+
],
225+
226+
'karmaModules-ngMessages': [
227+
'@karmaModulesBase',
228+
'build/angular-animate.js',
229+
'@angularSrcModuleNgMessages',
230+
'test/ngMessages/**/*.js'
231+
],
232+
233+
// ngMock doesn't include the base because it must use the ngMock src files
234+
'karmaModules-ngMock': [
235+
'build/angular.js',
236+
'src/ngMock/*.js',
237+
'test/modules/no_bootstrap.js',
238+
'test/helpers/matchers.js',
239+
'test/helpers/privateMocks.js',
240+
'test/helpers/support.js',
241+
'test/helpers/testabilityPatch.js',
242+
'src/routeToRegExp.js',
243+
'build/angular-animate.js',
244+
'test/ngMock/**/*.js'
245+
],
246+
247+
'karmaModules-ngResource': [
248+
'@karmaModulesBase',
249+
'@angularSrcModuleNgResource',
250+
'test/ngResource/**/*.js'
251+
],
252+
253+
'karmaModules-ngRoute': [
254+
'@karmaModulesBase',
255+
'build/angular-animate.js',
256+
'@angularSrcModuleNgRoute',
257+
'test/ngRoute/**/*.js'
258+
],
259+
260+
'karmaModules-ngSanitize': [
261+
'@karmaModulesBase',
262+
'@angularSrcModuleNgSanitize',
263+
'test/ngSanitize/**/*.js'
264+
],
265+
266+
'karmaModules-ngTouch': [
267+
'@karmaModulesBase',
268+
'@angularSrcModuleNgTouch',
269+
'test/ngTouch/**/*.js'
207270
],
208271

209272
'karmaJquery': [
@@ -232,6 +295,16 @@ var angularFiles = {
232295
});
233296
});
234297

298+
angularFiles['angularSrcModuleNgAnimate'] = angularFiles['angularModules']['ngAnimate'];
299+
angularFiles['angularSrcModuleNgAria'] = angularFiles['angularModules']['ngAria'];
300+
angularFiles['angularSrcModuleNgCookies'] = angularFiles['angularModules']['ngCookies'];
301+
angularFiles['angularSrcModuleNgMessageFormat'] = angularFiles['angularModules']['ngMessageFormat'];
302+
angularFiles['angularSrcModuleNgMessages'] = angularFiles['angularModules']['ngMessages'];
303+
angularFiles['angularSrcModuleNgResource'] = angularFiles['angularModules']['ngResource'];
304+
angularFiles['angularSrcModuleNgRoute'] = angularFiles['angularModules']['ngRoute'];
305+
angularFiles['angularSrcModuleNgSanitize'] = angularFiles['angularModules']['ngSanitize'];
306+
angularFiles['angularSrcModuleNgTouch'] = angularFiles['angularModules']['ngTouch'];
307+
235308
angularFiles['angularSrcModules'] = [].concat(
236309
angularFiles['angularModules']['ngAnimate'],
237310
angularFiles['angularModules']['ngMessageFormat'],

karma-modules.conf.js

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ var angularFiles = require('./angularFiles');
44
var sharedConfig = require('./karma-shared.conf');
55

66
module.exports = function(config) {
7-
sharedConfig(config, {testName: 'AngularJS: modules', logFile: 'karma-modules.log'});
7+
var angularModule = process.env.KARMA_MODULE;
88

9-
config.set({
10-
files: angularFiles.mergeFilesFor('karmaModules'),
9+
sharedConfig(config, {testName: 'AngularJS: module ' + angularModule, logFile: 'karma-modules-' + angularModule + '.log'});
1110

12-
junitReporter: {
13-
outputFile: 'test_out/modules.xml',
14-
suite: 'modules'
15-
}
11+
config.set({
12+
files: angularFiles.mergeFilesFor('karmaModules-' + angularModule)
1613
});
1714
};

lib/grunt/plugins.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ module.exports = function(grunt) {
4343

4444

4545
grunt.registerMultiTask('tests', '**Use `grunt test` instead**', function() {
46-
util.startKarma(this.data, true, this.async());
46+
var configFile;
47+
48+
if (this.nameArgs.includes('modules')) {
49+
configFile = 'karma-modules.conf.js';
50+
process.env.KARMA_MODULE = this.data;
51+
} else {
52+
configFile = this.data;
53+
}
54+
55+
util.startKarma(configFile, true, this.async());
4756
});
4857

4958

src/ngMessageFormat/messageFormatService.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ var noop;
215215
var toJson;
216216
var $$stringify;
217217

218-
var module = window['angular']['module']('ngMessageFormat', ['ng']);
219-
module['info']({ 'angularVersion': '"NG_VERSION_FULL"' });
220-
module['factory']('$$messageFormat', $$MessageFormatFactory);
221-
module['config'](['$provide', function($provide) {
218+
var ngModule = window['angular']['module']('ngMessageFormat', ['ng']);
219+
ngModule['info']({ 'angularVersion': '"NG_VERSION_FULL"' });
220+
ngModule['factory']('$$messageFormat', $$MessageFormatFactory);
221+
ngModule['config'](['$provide', function($provide) {
222222
$interpolateMinErr = window['angular']['$interpolateMinErr'];
223223
isFunction = window['angular']['isFunction'];
224224
noop = window['angular']['noop'];

test/ngCookies/cookieWriterSpec.js

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ describe('$$cookieWriter', function() {
132132

133133
describe('cookie options', function() {
134134
var fakeDocument, $$cookieWriter;
135+
var isUndefined = angular.isUndefined;
135136

136137
function getLastCookieAssignment(key) {
137138
return fakeDocument[0].cookie

test/ngMock/angular-mocksSpec.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
'use strict';
22

33
describe('ngMock', function() {
4+
45
var noop = angular.noop;
6+
var extend = angular.extend;
57

68
describe('TzDate', function() {
79

@@ -1107,11 +1109,13 @@ describe('ngMock', function() {
11071109
var mock = { log: 'module' };
11081110

11091111
beforeEach(function() {
1112+
angular.module('stringRefModule', []).service('stringRef', function() {});
1113+
11101114
module({
11111115
'service': mock,
11121116
'other': { some: 'replacement'}
11131117
},
1114-
'ngResource',
1118+
'stringRefModule',
11151119
function($provide) { $provide.value('example', 'win'); }
11161120
);
11171121
});
@@ -1130,9 +1134,9 @@ describe('ngMock', function() {
11301134
});
11311135

11321136
it('should integrate with string and function', function() {
1133-
inject(function(service, $resource, example) {
1137+
inject(function(service, stringRef, example) {
11341138
expect(service).toEqual(mock);
1135-
expect($resource).toBeDefined();
1139+
expect(stringRef).toBeDefined();
11361140
expect(example).toEqual('win');
11371141
});
11381142
});
@@ -2833,6 +2837,10 @@ describe('ngMock', function() {
28332837

28342838

28352839
describe('ngMockE2E', function() {
2840+
2841+
var noop = angular.noop;
2842+
var extend = angular.extend;
2843+
28362844
describe('$httpBackend', function() {
28372845
var hb, realHttpBackend, realHttpBackendBrowser, $http, callback;
28382846

@@ -3175,7 +3183,7 @@ describe('ngMockE2E', function() {
31753183

31763184
if (!browserSupportsCssAnimations()) return;
31773185

3178-
var element = jqLite('<div></div>');
3186+
var element = angular.element('<div></div>');
31793187
$rootElement.append(element);
31803188

31813189
// Make sure the animation has valid $animateCss options

test/ngResource/resourceSpec.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

33
describe('resource', function() {
4+
var noop = angular.noop;
5+
var extend = angular.extend;
46

57
describe('basic usage', function() {
68
var $resource, CreditCard, callback, $httpBackend, resourceProvider, $q;

0 commit comments

Comments
 (0)