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

chore: properly isolate module tests #16712

Merged
merged 1 commit into from
Oct 15, 2018
Merged
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
22 changes: 20 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,16 @@ module.exports = function(grunt) {
'jquery-2.2': 'karma-jquery-2.2.conf.js',
'jquery-2.1': 'karma-jquery-2.1.conf.js',
docs: 'karma-docs.conf.js',
modules: 'karma-modules.conf.js'
'modules-ngAnimate': 'ngAnimate',
'modules-ngAria': 'ngAria',
'modules-ngCookies': 'ngCookies',
'modules-ngMessageFormat': 'ngMessageFormat',
'modules-ngMessages': 'ngMessages',
'modules-ngMock': 'ngMock',
'modules-ngResource': 'ngResource',
'modules-ngRoute': 'ngRoute',
'modules-ngSanitize': 'ngSanitize',
'modules-ngTouch': 'ngTouch'
},


Expand Down Expand Up @@ -430,7 +439,16 @@ module.exports = function(grunt) {
grunt.registerTask('test:jquery-2.1', 'Run the jQuery 2.1 unit tests with Karma', ['tests:jquery-2.1']);
grunt.registerTask('test:modules', 'Run the Karma module tests with Karma', [
'build',
'tests:modules'
'tests:modules-ngAnimate',
'tests:modules-ngAria',
'tests:modules-ngCookies',
'tests:modules-ngMessageFormat',
'tests:modules-ngMessages',
'tests:modules-ngMock',
'tests:modules-ngResource',
'tests:modules-ngRoute',
'tests:modules-ngSanitize',
'tests:modules-ngTouch'
]);
grunt.registerTask('test:docs', 'Run the doc-page tests with Karma', ['package', 'tests:docs']);
grunt.registerTask('test:unit', 'Run unit, jQuery and Karma module tests with Karma', [
Expand Down
99 changes: 86 additions & 13 deletions angularFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,84 @@ var angularFiles = {
'src/angular.bind.js'
],

'karmaModules': [
'karmaModulesBase': [
'build/angular.js',
'@angularSrcModules',
'build/angular-mocks.js',
'test/modules/no_bootstrap.js',
'test/helpers/*.js',
'test/ngAnimate/*.js',
'test/ngMessageFormat/*.js',
'test/ngMessages/*.js',
'test/ngMock/*.js',
'test/ngCookies/*.js',
'test/ngRoute/**/*.js',
'test/ngResource/*.js',
'test/ngSanitize/**/*.js',
'test/ngTouch/**/*.js',
'test/ngAria/*.js'
'test/helpers/matchers.js',
'test/helpers/privateMocks.js',
'test/helpers/support.js',
'test/helpers/testabilityPatch.js'
],

'karmaModules-ngAnimate': [
'@karmaModulesBase',
'@angularSrcModuleNgAnimate',
'test/ngAnimate/**/*.js'
],

'karmaModules-ngAria': [
'@karmaModulesBase',
'@angularSrcModuleNgAria',
'test/ngAria/**/*.js'
],

'karmaModules-ngCookies': [
'@karmaModulesBase',
'@angularSrcModuleNgCookies',
'test/ngCookies/**/*.js'
],

'karmaModules-ngMessageFormat': [
'@karmaModulesBase',
'@angularSrcModuleNgMessageFormat',
'test/ngMessageFormat/**/*.js'
],

'karmaModules-ngMessages': [
'@karmaModulesBase',
'build/angular-animate.js',
Copy link
Member

Choose a reason for hiding this comment

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

Hm... 🤔
Why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some tests in ngMessages are dependent on ngAnimate, e.g.

module('ngAnimate');

Copy link
Member

Choose a reason for hiding this comment

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

Do we still need ngAnimate if we use ngAnimateMock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Theoretically yes, but I'm more comfortable with testing the actual animations instead of just the base provided by ng.

'@angularSrcModuleNgMessages',
'test/ngMessages/**/*.js'
],

// ngMock doesn't include the base because it must use the ngMock src files
'karmaModules-ngMock': [
'build/angular.js',
'src/ngMock/*.js',
'test/modules/no_bootstrap.js',
'test/helpers/matchers.js',
'test/helpers/privateMocks.js',
'test/helpers/support.js',
'test/helpers/testabilityPatch.js',
'src/routeToRegExp.js',
'build/angular-animate.js',
'test/ngMock/**/*.js'
],

'karmaModules-ngResource': [
'@karmaModulesBase',
'@angularSrcModuleNgResource',
'test/ngResource/**/*.js'
],

'karmaModules-ngRoute': [
'@karmaModulesBase',
'build/angular-animate.js',
'@angularSrcModuleNgRoute',
'test/ngRoute/**/*.js'
],

'karmaModules-ngSanitize': [
'@karmaModulesBase',
'@angularSrcModuleNgSanitize',
'test/ngSanitize/**/*.js'
],

'karmaModules-ngTouch': [
'@karmaModulesBase',
'@angularSrcModuleNgTouch',
'test/ngTouch/**/*.js'
],

'karmaJquery': [
Expand Down Expand Up @@ -232,6 +295,16 @@ var angularFiles = {
});
});

angularFiles['angularSrcModuleNgAnimate'] = angularFiles['angularModules']['ngAnimate'];
angularFiles['angularSrcModuleNgAria'] = angularFiles['angularModules']['ngAria'];
angularFiles['angularSrcModuleNgCookies'] = angularFiles['angularModules']['ngCookies'];
angularFiles['angularSrcModuleNgMessageFormat'] = angularFiles['angularModules']['ngMessageFormat'];
angularFiles['angularSrcModuleNgMessages'] = angularFiles['angularModules']['ngMessages'];
angularFiles['angularSrcModuleNgResource'] = angularFiles['angularModules']['ngResource'];
angularFiles['angularSrcModuleNgRoute'] = angularFiles['angularModules']['ngRoute'];
angularFiles['angularSrcModuleNgSanitize'] = angularFiles['angularModules']['ngSanitize'];
angularFiles['angularSrcModuleNgTouch'] = angularFiles['angularModules']['ngTouch'];

angularFiles['angularSrcModules'] = [].concat(
angularFiles['angularModules']['ngAnimate'],
angularFiles['angularModules']['ngMessageFormat'],
Expand Down
11 changes: 4 additions & 7 deletions karma-modules.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ var angularFiles = require('./angularFiles');
var sharedConfig = require('./karma-shared.conf');

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

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

junitReporter: {
outputFile: 'test_out/modules.xml',
suite: 'modules'
}
config.set({
files: angularFiles.mergeFilesFor('karmaModules-' + angularModule)
});
};
11 changes: 10 additions & 1 deletion lib/grunt/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,16 @@ module.exports = function(grunt) {


grunt.registerMultiTask('tests', '**Use `grunt test` instead**', function() {
util.startKarma(this.data, true, this.async());
var configFile;

if (this.nameArgs.includes('modules')) {
configFile = 'karma-modules.conf.js';
process.env.KARMA_MODULE = this.data;
} else {
configFile = this.data;
}

util.startKarma(configFile, true, this.async());
});


Expand Down
8 changes: 4 additions & 4 deletions src/ngMessageFormat/messageFormatService.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ var noop;
var toJson;
var $$stringify;

var module = window['angular']['module']('ngMessageFormat', ['ng']);
module['info']({ 'angularVersion': '"NG_VERSION_FULL"' });
module['factory']('$$messageFormat', $$MessageFormatFactory);
module['config'](['$provide', function($provide) {
var ngModule = window['angular']['module']('ngMessageFormat', ['ng']);
ngModule['info']({ 'angularVersion': '"NG_VERSION_FULL"' });
ngModule['factory']('$$messageFormat', $$MessageFormatFactory);
ngModule['config'](['$provide', function($provide) {
$interpolateMinErr = window['angular']['$interpolateMinErr'];
isFunction = window['angular']['isFunction'];
noop = window['angular']['noop'];
Expand Down
1 change: 1 addition & 0 deletions test/ngCookies/cookieWriterSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ describe('$$cookieWriter', function() {

describe('cookie options', function() {
var fakeDocument, $$cookieWriter;
var isUndefined = angular.isUndefined;

function getLastCookieAssignment(key) {
return fakeDocument[0].cookie
Expand Down
16 changes: 12 additions & 4 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

describe('ngMock', function() {

var noop = angular.noop;
var extend = angular.extend;

describe('TzDate', function() {

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

beforeEach(function() {
angular.module('stringRefModule', []).service('stringRef', function() {});

module({
'service': mock,
'other': { some: 'replacement'}
},
'ngResource',
'stringRefModule',
function($provide) { $provide.value('example', 'win'); }
);
});
Expand All @@ -1130,9 +1134,9 @@ describe('ngMock', function() {
});

it('should integrate with string and function', function() {
inject(function(service, $resource, example) {
inject(function(service, stringRef, example) {
expect(service).toEqual(mock);
expect($resource).toBeDefined();
expect(stringRef).toBeDefined();
expect(example).toEqual('win');
});
});
Expand Down Expand Up @@ -2833,6 +2837,10 @@ describe('ngMock', function() {


describe('ngMockE2E', function() {

var noop = angular.noop;
var extend = angular.extend;

describe('$httpBackend', function() {
var hb, realHttpBackend, realHttpBackendBrowser, $http, callback;

Expand Down Expand Up @@ -3175,7 +3183,7 @@ describe('ngMockE2E', function() {

if (!browserSupportsCssAnimations()) return;

var element = jqLite('<div></div>');
var element = angular.element('<div></div>');
$rootElement.append(element);

// Make sure the animation has valid $animateCss options
Expand Down
2 changes: 2 additions & 0 deletions test/ngResource/resourceSpec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

describe('resource', function() {
var noop = angular.noop;
var extend = angular.extend;

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