Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

Commit

Permalink
fix(tests): performance improvements and fixes to jasmine testing
Browse files Browse the repository at this point in the history
*  Refactor internal test utils to angular-material-spec.js
*  Publish material mocks `angular-material-mocks.js` to work with angular-mocks.js for 3rd party unit testing.
*  Removed module wrappers around all components
  *  now only has a single module wrapper protecting all the angular material code
*  Replaced use of `Function.bind( )` with `angular.bind()`
*  Fixed tests runs with uncompiled source **or** compiled, deployed `angular-material.js`
*  Use angular-material-mocks.js to decorate $$rAF.throttle(), force $mdAria.expectWithText() to be synchronous, and disable the generation of Theme CSS rules.
*  Major testing speed improvements by disabling Theme CSS generation.
*  Theme improvements: test existence of Theme CSS rule before regenerating.
*  Now works with Safari, Firefox, PhantomJS, and Chrome browser testing.
*  Running karma on ci was not exiting with non zero code, giving the impression the specs passed
*  fix(tests): karma tests with minified source now pass properly
  *  Restored module wrapper to material theme constants.
  *  Passed global args to module wrapper for JS modules
  *  Minified code no longer contains angular-material-mocks; which is not deployed as external file.
*  fix(tests): improve use of module wrappers
  *  Auto-wrap all JS files in module wrapper.
  *  Repackage angular-material-mocks.js to `/test/` directory
  *  Change karma logLevel to 'warn'

Closes #2800. Closes #2535.
  • Loading branch information
ThomasBurleson committed May 11, 2015
1 parent a8fd0f4 commit 786b0ed
Show file tree
Hide file tree
Showing 37 changed files with 826 additions and 728 deletions.
91 changes: 62 additions & 29 deletions config/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@

module.exports = function(config) {

var UNCOMPILED_SRC = [
'config/test-utils.js',
'src/core/**/*.js',

// Test utilities, source, and specifications.
// We are explicit like this because we don't want to put
// demos in the tests, and Karma doesn't support advanced
// globbing.
'src/components/*/*.js',
'src/components/*/js/*.js'

// To enabled use of `gulp karma-watch`,
// don't use the dist/angular-material.js
//
//'dist/angular-material.js', // Un-minified source


// Test utilities, source, and specifications.
// We are explicit like this because we don't want to put
// demos in the tests, and Karma doesn't support advanced
// globbing.

'src/core/**/*.js',
'src/components/*/*.js',
'src/components/*/js/*.js',

'src/**/*.spec.js'

];

var COMPILED_SRC = [
// Minified source
'dist/angular-material.min.js',

// Test utilties and specifications
'config/test-utils.js',
'dist/angular-material.min.js', // Minified source
'src/**/*.spec.js'
];

// releaseMode is a custom configuration option.
var testSrc = process.env.KARMA_TEST_COMPRESSED ? COMPILED_SRC : UNCOMPILED_SRC;
var dependencies = process.env.KARMA_TEST_JQUERY ?
['node_modules/jquery/dist/jquery.js'] : [];

dependencies = dependencies.concat([
'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'
]);
var dependencies = process.env.KARMA_TEST_JQUERY ? ['node_modules/jquery/dist/jquery.js'] : [];
dependencies = dependencies.concat([
'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',
'test/angular-material-mocks.js',
'test/angular-material-spec.js'
]);

var testSrc = process.env.KARMA_TEST_COMPRESSED ? COMPILED_SRC : UNCOMPILED_SRC;

config.set({

basePath: __dirname + '/..',
frameworks: ['jasmine'],
files: dependencies.concat(testSrc),

logLevel:'warn',
port: 9876,
reporters: ['progress'],
colors: true,

// Continuous Integration mode
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
singleRun: false,
singleRun: true,

// Start these browsers, currently available:
// - Chrome
Expand All @@ -58,7 +63,35 @@ module.exports = function(config) {
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['Chrome']
browsers: ['Chrome'],

// you can define custom flags
customLaunchers: {
Chrome_without_security: {
base: 'Chrome',
flags: ['--disable-web-security']
},
PhantomJS_without_security: {
base: 'PhantomJS',
options : {
onResourceRequested : function (request) {
console.log('Request ' + JSON.stringify(request, undefined, 4));
},
onError : function (msg, trace) {
console.log(msg);
trace.forEach(function(item) {
console.log(' ', item.file, ':', item.line);
});
}
},
flags: [
'--web-security=no',
'--proxy-type=none',
'--remote-debugger-port=9000',
'--remote-debugger-autorun=yes'
]
}
}
});

};
157 changes: 0 additions & 157 deletions config/test-utils.js

This file was deleted.

9 changes: 6 additions & 3 deletions gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ module.exports = {
' * v' + VERSION + '\n' +
' */\n',
jsBaseFiles: [
'src/core/**/*.js',
'!src/core/**/*.spec.js'
'src/core/**/*.js'
],
jsFiles: [
'src/**/*.js'
'src/**/*.js',
'!src/**/*.spec.js'
],
mockFiles : [
'test/angular-material-mocks.js'
],
themeBaseFiles: [
'src/core/style/variables.scss',
Expand Down
24 changes: 22 additions & 2 deletions gulp/tasks/karma.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
exports.task = function (done) {
var errorCount = 0;
var karmaConfig = {
logLevel: 'warn',
singleRun: true,
autoWatch: false,
browsers : argv.browsers ? argv.browsers.trim().split(',') : ['Chrome'],
configFile: root + '/config/karma.conf.js'
};

/**
* For each cycle of testings (unminified, minified, minified w/ jQuery)
* interrogate the exitCode to capture the exitCode...
* Then report any errors that may manifest [e.g. in the minified tests]
*/
function captureError(next) {
return function(exitCode) {
if (exitCode != 0) {
gutil.log(gutil.colors.red("Karma exited with the following exit code: " + exitCode));
errorCount++;
}
next();
};
}


gutil.log('Running unit tests on unminified source.');
buildJs(true);
karma.start(karmaConfig, testMinified);
karma.start(karmaConfig, captureError(testMinified));

function testMinified() {
gutil.log('Running unit tests on minified source.');
process.env.KARMA_TEST_COMPRESSED = true;
karma.start(karmaConfig, testMinifiedJquery);
karma.start(karmaConfig, captureError(testMinifiedJquery));
}

function testMinifiedJquery() {
Expand All @@ -26,6 +44,8 @@ exports.task = function (done) {
function clearEnv() {
process.env.KARMA_TEST_COMPRESSED = undefined;
process.env.KARMA_TEST_JQUERY = undefined;

if (errorCount > 0) { process.exit(errorCount); }
done();
}
};
Loading

0 comments on commit 786b0ed

Please sign in to comment.