diff --git a/docs/config/02-files.md b/docs/config/02-files.md index d7d267484..fde05c962 100644 --- a/docs/config/02-files.md +++ b/docs/config/02-files.md @@ -52,6 +52,11 @@ Each pattern is either a simple string or an object with four properties: * **Default.** `true` * **Description.** Should the files be served by Karma's webserver? +### `esModule` +* **Type.** Boolean +* **Default.** `false` +* **Description.** Should the files be loaded as ECMAScript modules? + ### `nocache` * **Type.** Boolean * **Default.** `false` diff --git a/lib/config.js b/lib/config.js index deeaf6d7d..540b309eb 100644 --- a/lib/config.js +++ b/lib/config.js @@ -30,11 +30,12 @@ try { TYPE_SCRIPT_AVAILABLE = true } catch (e) {} -var Pattern = function (pattern, served, included, watched, nocache) { +var Pattern = function (pattern, served, included, watched, nocache, esModule) { this.pattern = pattern this.served = helper.isDefined(served) ? served : true this.included = helper.isDefined(included) ? included : true this.watched = helper.isDefined(watched) ? watched : true + this.esModule = helper.isDefined(esModule) ? esModule : false this.nocache = helper.isDefined(nocache) ? nocache : false this.weight = helper.mmPatternWeight(pattern) } @@ -44,7 +45,7 @@ Pattern.prototype.compare = function (other) { } var UrlPattern = function (url) { - Pattern.call(this, url, false, true, false, false) + Pattern.call(this, url, false, true, false, false, false) } var createPatternObject = function (pattern) { @@ -61,7 +62,8 @@ var createPatternObject = function (pattern) { pattern.served, pattern.included, pattern.watched, - pattern.nocache) + pattern.nocache, + pattern.esModule) } log.warn('Invalid pattern %s!\n\tObject is missing "pattern" property.', pattern) diff --git a/lib/file-list.js b/lib/file-list.js index ca9c9e2e2..0e2024461 100644 --- a/lib/file-list.js +++ b/lib/file-list.js @@ -183,7 +183,8 @@ List.prototype._refresh = function () { var mtime = mg.statCache[path].mtime var doNotCache = patternObject.nocache - var file = new File(path, mtime, doNotCache) + var esModule = patternObject.esModule + var file = new File(path, mtime, doNotCache, esModule) if (file.doNotCache) { log.debug('Not preprocessing "%s" due to nocache') diff --git a/lib/file.js b/lib/file.js index 4eabe8e00..2c261eddb 100644 --- a/lib/file.js +++ b/lib/file.js @@ -9,7 +9,7 @@ var _ = require('lodash') // Constructor -var File = function (path, mtime, doNotCache) { +var File = function (path, mtime, doNotCache, esModule) { // used for serving (processed path, eg some/file.coffee -> some/file.coffee.js) this.path = path @@ -23,6 +23,7 @@ var File = function (path, mtime, doNotCache) { this.isUrl = false this.doNotCache = _.isUndefined(doNotCache) ? false : doNotCache + this.esModule = esModule } File.prototype.toString = function () { diff --git a/lib/middleware/karma.js b/lib/middleware/karma.js index 04dd47a3f..ed0d31c59 100644 --- a/lib/middleware/karma.js +++ b/lib/middleware/karma.js @@ -178,6 +178,7 @@ var createKarmaMiddleware = function ( var file = files.included[i] var filePath = file.path var fileExt = path.extname(filePath) + var esModule = fileExt.endsWith('js') && file.esModule if (!files.included.hasOwnProperty(i)) { continue @@ -204,7 +205,7 @@ var createKarmaMiddleware = function ( } // The script tag to be placed - var scriptType = (SCRIPT_TYPE[fileExt] || 'text/javascript') + var scriptType = esModule ? 'module' : (SCRIPT_TYPE[fileExt] || 'text/javascript') // In case there is a JavaScript version specified and this is a Firefox browser if (jsVersion && jsVersion > 0 && isFirefox(request)) {