diff --git a/src/adapter.js b/src/adapter.js index 8d89ec6..e63d054 100644 --- a/src/adapter.js +++ b/src/adapter.js @@ -51,18 +51,20 @@ System.bundles = []; } - var systemInstantiate = System.instantiate; - var http = location.protocol; - var slashes = http.concat('//'); - var host = slashes.concat(window.location.host) + '/base/'; - System.instantiate = function(load) { - var fileKey = load.name.replace(host, ''); - if (karma.config.jspm.coverageFiles[fileKey]) { - var re = new RegExp('file://' + karma.config.jspm.basePath + '/','g'); - load.source = karma.config.jspm.coverageFiles[fileKey].replace(re, host); - } - return systemInstantiate.call(System, load); - }; + if (typeof karma.config.jspm.coverage === 'object') { + var systemInstantiate = System.instantiate; + var http = location.protocol; + var slashes = http.concat('//'); + var host = slashes.concat(window.location.host) + '/base/'; + System.instantiate = function(load) { + var fileKey = load.name.replace(host, ''); + if (karma.config.jspm.coverage.files[fileKey]) { + var re = new RegExp('file://' + karma.config.jspm.coverage.basePath + '/','g'); + load.source = karma.config.jspm.coverage.files[fileKey].replace(re, host); + } + return systemInstantiate.call(System, load); + }; + } // Load everything specified in loadFiles in the specified order var promiseChain = Promise.resolve(); diff --git a/src/init.js b/src/init.js index 233a29b..d208f19 100644 --- a/src/init.js +++ b/src/init.js @@ -102,13 +102,13 @@ module.exports = function(files, basePath, jspm, client, emitter) { return packagesPath + fileName + '.js'; } } - + Array.prototype.unshift.apply(files, configPaths.map(function(configPath) { return createPattern(configPath) }) ); - + // Needed for JSPM 0.17 beta if(jspm.browser) { files.unshift(createPattern(browserPath)); @@ -139,7 +139,9 @@ module.exports = function(files, basePath, jspm, client, emitter) { // Allow Karma to serve all files within jspm_packages. // This allows jspm/SystemJS to load them - var jspmPattern = createServedPattern(packagesPath + '**/*', {nocache: jspm.cachePackages !== true}); + var jspmPattern = createServedPattern( + packagesPath + '!(system-polyfills.src.js|system.src.js)/**', {nocache: jspm.cachePackages !== true} + ); jspmPattern.watched = false; files.push(jspmPattern); }; diff --git a/src/preprocessor.js b/src/preprocessor.js index 60df10d..2297901 100644 --- a/src/preprocessor.js +++ b/src/preprocessor.js @@ -27,14 +27,16 @@ function CoveragePreprocessor(basePath, client, reporters, helper, logger) { // create a jspm namespace to pass data to the browsers if (!client.jspm) client.jspm = {}; // store instrumented sources to be executed by browser - client.jspm.coverageFiles = {}; + client.jspm.coverage = { + files: {} + }; // store basePath used to generate the key for each source in the obj above - client.jspm.basePath = basePath; + client.jspm.coverage.basePath = basePath; // temp folder to store instrumented files for sourcemap remapping - client.jspm.tempDirectory = path.join(__dirname, '../no-source-map/'); + client.jspm.coverage.tempDirectory = path.join(__dirname, '../no-source-map/'); // make temp directory - var tempDirectory = client.jspm.tempDirectory; + var tempDirectory = client.jspm.coverage.tempDirectory; if (!fs.existsSync(tempDirectory)) { fs.mkdirSync(tempDirectory); } @@ -50,7 +52,7 @@ function CoveragePreprocessor(basePath, client, reporters, helper, logger) { // create a unique key to store the sources of modules for the browser var fileKey = getFileKey(getOSFilePath(load.address), basePath); // exclude the dependency modules (i.e. libraries) from instrumentation - if (client.jspm.coverageFiles[fileKey]) { + if (client.jspm.coverage.files[fileKey]) { // put file's transpiled counterpart in temp folder var filename; var sourceMap = ''; @@ -87,7 +89,7 @@ function CoveragePreprocessor(basePath, client, reporters, helper, logger) { } // instrument with istanbul - client.jspm.coverageFiles[fileKey] = instrument.instrumentSync( + client.jspm.coverage.files[fileKey] = instrument.instrumentSync( load.source, // make the path-like file key into something that can be used as a name filename @@ -106,7 +108,7 @@ function CoveragePreprocessor(basePath, client, reporters, helper, logger) { // only files to be instrumented pass through here // store this information to allow "instantiate" to exclude // dependency modules (i.e. libraries) - client.jspm.coverageFiles[getFileKey(file.path, basePath)] = true; + client.jspm.coverage.files[getFileKey(file.path, basePath)] = true; // import modules systemJS.import(file.path).then(function () { done(content); diff --git a/src/reporter.js b/src/reporter.js index 738a09f..19dfe42 100644 --- a/src/reporter.js +++ b/src/reporter.js @@ -15,7 +15,7 @@ function CoverageReporter(rootConfig, helper, logger, emitter) { }; config._onExit = function (done) { try { - rimraf.sync(rootConfig.client.jspm.tempDirectory); + rimraf.sync(rootConfig.client.jspm.coverage.tempDirectory); } catch(e) { log.error(e); } diff --git a/test/testInit.spec.js b/test/testInit.spec.js index a04f70c..2370a15 100644 --- a/test/testInit.spec.js +++ b/test/testInit.spec.js @@ -74,7 +74,7 @@ describe('jspm plugin init', function(){ }); it('should use the configured jspm_packages path and include it at the end of the files array', function(){ - expect(normalPath(files[files.length - 1].pattern)).toEqual(normalPath(path.resolve(cwd, './custom_packages/**/*'))); + expect(normalPath(files[files.length - 1].pattern)).toEqual(normalPath(path.resolve(cwd, './custom_packages/!(system-polyfills.src.js|system.src.js)/**'))); expect(files[files.length - 1].included).toEqual(false); expect(files[files.length - 1].served).toEqual(true); expect(files[files.length - 1].watched).toEqual(false);