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

fix(tests): performance improvements and fixes to jasmine testing #2800

Closed
wants to merge 6 commits into from
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
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) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment explaining what this function does?

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