From 54dcce31ea59ba8a425ee656be8b507ffe7d8248 Mon Sep 17 00:00:00 2001 From: Luke Page Date: Thu, 18 Jun 2015 15:29:42 +0100 Subject: [PATCH] fix(init): Make the requirejs config template normalize paths By removing the base path and file extension of files, this normalizes files to be in a standard requirejs format and means mean sub dependencies of the test files will not be loaded as-is. See https://github.com/karma-runner/karma/issues/513#issuecomment-48616784 --- requirejs.config.tpl.coffee | 9 +++++++-- requirejs.config.tpl.js | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/requirejs.config.tpl.coffee b/requirejs.config.tpl.coffee index 492c9e3f5..39edb5ea0 100644 --- a/requirejs.config.tpl.coffee +++ b/requirejs.config.tpl.coffee @@ -1,9 +1,14 @@ allTestFiles = [] TEST_REGEXP = /(spec|test)(\.coffee)?(\.js)?$/i +# Get a list of all the test files to include Object.keys(window.__karma__.files).forEach (file) -> - # Normalize paths to RequireJS module names. - allTestFiles.push file if TEST_REGEXP.test(file) + + if TEST_REGEXP.test(file) + # Normalize paths to RequireJS module names. + # If you require sub-dependencies of test files to be loaded as-is (requiring file extension) + # then do not normalize the paths + allTestFiles.push file.replace(/^\/base\/|\.js$/g, '') return require.config diff --git a/requirejs.config.tpl.js b/requirejs.config.tpl.js index 1509a558d..c2173ad60 100644 --- a/requirejs.config.tpl.js +++ b/requirejs.config.tpl.js @@ -1,10 +1,14 @@ var allTestFiles = []; var TEST_REGEXP = /(spec|test)\.js$/i; +// Get a list of all the test files to include Object.keys(window.__karma__.files).forEach(function(file) { if (TEST_REGEXP.test(file)) { // Normalize paths to RequireJS module names. - allTestFiles.push(file); + // If you require sub-dependencies of test files to be loaded as-is (requiring file extension) + // then do not normalize the paths + var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, ''); + allTestFiles.push(normalizedTestModule); } });