Commit a2dadeaa by Usman Khalid

Added some documentation to Karma configuration files.

parent 667a9b9a
// Karma config for cms suite. // Karma config for cms suite.
// Docs in common/static/common/js/karma.common.conf.js // Docs and troubleshooting tips in common/static/common/js/karma.common.conf.js
/* jshint node: true */ /* jshint node: true */
/*jshint -W079 */ /*jshint -W079 */
...@@ -13,6 +13,8 @@ var options = { ...@@ -13,6 +13,8 @@ var options = {
libraryFiles: [], libraryFiles: [],
// Make sure the patterns in sourceFiles and specFiles do not match the same file.
// Otherwise Istanbul which is used for coverage tracking will cause tests to not run.
sourceFiles: [ sourceFiles: [
{pattern: 'coffee/src/**/!(*spec).js'}, {pattern: 'coffee/src/**/!(*spec).js'},
{pattern: 'js/**/!(*spec|djangojs).js'} {pattern: 'js/**/!(*spec|djangojs).js'}
......
// Karma config for cms-squire suite. // Karma config for cms-squire suite.
// Docs in common/static/common/js/karma.common.conf.js // Docs and troubleshooting tips in common/static/common/js/karma.common.conf.js
/* jshint node: true */ /* jshint node: true */
/*jshint -W079 */ /*jshint -W079 */
...@@ -13,6 +13,8 @@ var options = { ...@@ -13,6 +13,8 @@ var options = {
libraryFiles: [], libraryFiles: [],
// Make sure the patterns in sourceFiles and specFiles do not match the same file.
// Otherwise Istanbul which is used for coverage tracking will cause tests to not run.
sourceFiles: [ sourceFiles: [
{pattern: 'coffee/src/**/!(*spec).js'}, {pattern: 'coffee/src/**/!(*spec).js'},
{pattern: 'js/**/!(*spec|djangojs).js'} {pattern: 'js/**/!(*spec|djangojs).js'}
......
// Karma config for xmodule suite. // Karma config for xmodule suite.
// Docs in common/static/common/js/karma.common.conf.js // Docs and troubleshooting tips in common/static/common/js/karma.common.conf.js
/* jshint node: true */ /* jshint node: true */
/*jshint -W079 */ /*jshint -W079 */
...@@ -16,6 +16,7 @@ var options = { ...@@ -16,6 +16,7 @@ var options = {
return pattern; return pattern;
}, },
// Avoid adding files to this list. Use RequireJS.
libraryFilesToInclude: [ libraryFilesToInclude: [
{pattern: 'common_static/js/vendor/requirejs/require.js', included: true}, {pattern: 'common_static/js/vendor/requirejs/require.js', included: true},
{pattern: 'RequireJS-namespace-undefine.js', included: true}, {pattern: 'RequireJS-namespace-undefine.js', included: true},
...@@ -55,6 +56,8 @@ var options = { ...@@ -55,6 +56,8 @@ var options = {
{pattern: 'common_static/edx-pattern-library/js/**/*.js'} {pattern: 'common_static/edx-pattern-library/js/**/*.js'}
], ],
// Make sure the patterns in sourceFiles and specFiles do not match the same file.
// Otherwise Istanbul which is used for coverage tracking will cause tests to not run.
sourceFiles: [ sourceFiles: [
{pattern: 'src/xmodule.js', included: true, ignoreCoverage: true}, // To prevent getting instrumented twice. {pattern: 'src/xmodule.js', included: true, ignoreCoverage: true}, // To prevent getting instrumented twice.
{pattern: 'src/**/*.js', included: true} {pattern: 'src/**/*.js', included: true}
......
...@@ -19,6 +19,19 @@ ...@@ -19,6 +19,19 @@
// //
// where `BROWSER` could be Chrome or Firefox. // where `BROWSER` could be Chrome or Firefox.
// //
//
// Troubleshooting tips:
//
// If you get an error like: "TypeError: __cov_KBCc7ZI4xZm8W2BC5NQLDg.s is undefined",
// that means the patterns in sourceFiles and specFiles are matching the same file.
// This causes Istanbul, which is used for tracking coverage to instrument the file
// multiple times.
//
//
// If you see the error: "EMFILE, too many open files" that means the files pattern
// that has been added is matching too many files. The glob library used by Karma
// does not use graceful-fs and tries to read files simultaneously.
//
/* jshint node: true */ /* jshint node: true */
...@@ -29,6 +42,7 @@ var path = require('path'); ...@@ -29,6 +42,7 @@ var path = require('path');
var _ = require('underscore'); var _ = require('underscore');
var appRoot = path.join(__dirname, '../../../../'); var appRoot = path.join(__dirname, '../../../../');
// Files which are needed by all lms/cms suites.
var commonFiles = { var commonFiles = {
libraryFiles: [ libraryFiles: [
{pattern: 'common/js/vendor/**/*.js'}, {pattern: 'common/js/vendor/**/*.js'},
...@@ -148,6 +162,12 @@ function junitSettings(config) { ...@@ -148,6 +162,12 @@ function junitSettings(config) {
}; };
} }
/**
* Return absolute path for files in common and xmodule_js symlink dirs.
* @param {String} appRoot
* @param {String} pattern
* @return {String}
*/
var defaultNormalizeFunc = function (appRoot, pattern) { var defaultNormalizeFunc = function (appRoot, pattern) {
if (pattern.match(/^common\/js/)) { if (pattern.match(/^common\/js/)) {
pattern = path.join(appRoot, '/common/static/' + pattern); pattern = path.join(appRoot, '/common/static/' + pattern);
...@@ -339,6 +359,8 @@ var configure = function(config, options) { ...@@ -339,6 +359,8 @@ var configure = function(config, options) {
files.unshift({pattern: 'common/js/utils/require-serial.js', included: true}); files.unshift({pattern: 'common/js/utils/require-serial.js', included: true});
} }
// Karma sets included=true by default.
// We set it to false by default because RequireJS should be used instead.
files = setDefaults(files); files = setDefaults(files);
// With nocache=true, Karma always serves the latest files from disk. // With nocache=true, Karma always serves the latest files from disk.
...@@ -353,6 +375,8 @@ var configure = function(config, options) { ...@@ -353,6 +375,8 @@ var configure = function(config, options) {
) )
); );
// If we give symlink paths to Istanbul, coverage for each path gets tracked
// separately. So we pass absolute paths to the karma-coverage preprocessor.
var preprocessors = _.extend( var preprocessors = _.extend(
{}, {},
options.preprocessors, options.preprocessors,
......
...@@ -181,6 +181,8 @@ ...@@ -181,6 +181,8 @@
'common/js/spec_helpers/jasmine-waituntil' 'common/js/spec_helpers/jasmine-waituntil'
]; ];
// Jasmine has a global stack for creating a tree of specs. We need to load
// spec files one by one, otherwise some end up getting nested under others.
window.requireSerial(specHelpers.concat(testFiles), function () { window.requireSerial(specHelpers.concat(testFiles), function () {
// start test run, once Require.js is done // start test run, once Require.js is done
window.__karma__.start(); window.__karma__.start();
......
// Karma config for common suite. // Karma config for common suite.
// Docs in common/static/common/js/karma.common.conf.js // Docs and troubleshooting tips in common/static/common/js/karma.common.conf.js
/* jshint node: true */ /* jshint node: true */
/*jshint -W079 */ /*jshint -W079 */
...@@ -15,6 +15,7 @@ var options = { ...@@ -15,6 +15,7 @@ var options = {
return path.join(appRoot, '/common/static/' + pattern); return path.join(appRoot, '/common/static/' + pattern);
}, },
// Avoid adding files to this list. Use RequireJS.
libraryFilesToInclude: [ libraryFilesToInclude: [
{pattern: 'coffee/src/ajax_prefix.js', included: true}, {pattern: 'coffee/src/ajax_prefix.js', included: true},
{pattern: 'js/vendor/draggabilly.js', included: true}, {pattern: 'js/vendor/draggabilly.js', included: true},
...@@ -45,6 +46,8 @@ var options = { ...@@ -45,6 +46,8 @@ var options = {
libraryFiles: [ libraryFiles: [
], ],
// Make sure the patterns in sourceFiles and specFiles do not match the same file.
// Otherwise Istanbul which is used for coverage tracking will cause tests to not run.
sourceFiles: [ sourceFiles: [
{pattern: 'js/xblock/**/*.js', included: true}, {pattern: 'js/xblock/**/*.js', included: true},
{pattern: 'coffee/src/**/*.js', included: true}, {pattern: 'coffee/src/**/*.js', included: true},
......
// Karma config for common-requirejs suite. // Karma config for common-requirejs suite.
// Docs in common/static/common/js/karma.common.conf.js // Docs and troubleshooting tips in common/static/common/js/karma.common.conf.js
/* jshint node: true */ /* jshint node: true */
/*jshint -W079 */ /*jshint -W079 */
...@@ -23,6 +23,8 @@ var options = { ...@@ -23,6 +23,8 @@ var options = {
{pattern: 'js/vendor/**/*.js'} {pattern: 'js/vendor/**/*.js'}
], ],
// Make sure the patterns in sourceFiles and specFiles do not match the same file.
// Otherwise Istanbul which is used for coverage tracking will cause tests to not run.
sourceFiles: [], sourceFiles: [],
specFiles: [ specFiles: [
......
// Karma config for lms suite. // Karma config for lms suite.
// Docs in common/static/common/js/karma.common.conf.js // Docs and troubleshooting tips in common/static/common/js/karma.common.conf.js
/* jshint node: true */ /* jshint node: true */
/*jshint -W079 */ /*jshint -W079 */
...@@ -11,6 +11,7 @@ var options = { ...@@ -11,6 +11,7 @@ var options = {
includeCommonFiles: true, includeCommonFiles: true,
// Avoid adding files to this list. Use RequireJS.
libraryFilesToInclude: [ libraryFilesToInclude: [
{pattern: 'xmodule_js/common_static/js/vendor/jquery.event.drag-2.2.js', included: true}, {pattern: 'xmodule_js/common_static/js/vendor/jquery.event.drag-2.2.js', included: true},
{pattern: 'xmodule_js/common_static/js/vendor/slick.core.js', included: true}, {pattern: 'xmodule_js/common_static/js/vendor/slick.core.js', included: true},
...@@ -21,6 +22,8 @@ var options = { ...@@ -21,6 +22,8 @@ var options = {
{pattern: 'js/RequireJS-namespace-undefine.js'} {pattern: 'js/RequireJS-namespace-undefine.js'}
], ],
// Make sure the patterns in sourceFiles and specFiles do not match the same file.
// Otherwise Istanbul which is used for coverage tracking will cause tests to not run.
sourceFiles: [ sourceFiles: [
{pattern: 'coffee/src/**/!(*spec).js'}, {pattern: 'coffee/src/**/!(*spec).js'},
{pattern: 'js/**/!(*spec|djangojs).js'}, {pattern: 'js/**/!(*spec|djangojs).js'},
......
// Karma config for lms-coffee suite. // Karma config for lms-coffee suite.
// Docs in common/static/common/js/karma.common.conf.js // Docs and troubleshooting tips in common/static/common/js/karma.common.conf.js
/* jshint node: true */ /* jshint node: true */
/*jshint -W079 */ /*jshint -W079 */
...@@ -13,6 +13,7 @@ var options = { ...@@ -13,6 +13,7 @@ var options = {
useRequireJs: false, useRequireJs: false,
includeCommonFiles: true, includeCommonFiles: true,
// Avoid adding files to this list. Use RequireJS.
libraryFilesToInclude: [ libraryFilesToInclude: [
{pattern: 'xmodule_js/common_static/js/vendor/requirejs/require.js', included: true}, {pattern: 'xmodule_js/common_static/js/vendor/requirejs/require.js', included: true},
{pattern: 'js/spec/main_requirejs_coffee.js', included: true}, {pattern: 'js/spec/main_requirejs_coffee.js', included: true},
...@@ -47,6 +48,8 @@ var options = { ...@@ -47,6 +48,8 @@ var options = {
{pattern: 'xmodule_js/common_static/js/vendor/**/*.js'} {pattern: 'xmodule_js/common_static/js/vendor/**/*.js'}
], ],
// Make sure the patterns in sourceFiles and specFiles do not match the same file.
// Otherwise Istanbul which is used for coverage tracking will cause tests to not run.
sourceFiles: [ sourceFiles: [
{pattern: 'coffee/src/**/*.js', included: true} {pattern: 'coffee/src/**/*.js', included: true}
], ],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment