Skip to content

Commit 54dcce3

Browse files
committed
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 #513 (comment)
1 parent d83fab9 commit 54dcce3

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

requirejs.config.tpl.coffee

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
allTestFiles = []
22
TEST_REGEXP = /(spec|test)(\.coffee)?(\.js)?$/i
33

4+
# Get a list of all the test files to include
45
Object.keys(window.__karma__.files).forEach (file) ->
5-
# Normalize paths to RequireJS module names.
6-
allTestFiles.push file if TEST_REGEXP.test(file)
6+
7+
if TEST_REGEXP.test(file)
8+
# Normalize paths to RequireJS module names.
9+
# If you require sub-dependencies of test files to be loaded as-is (requiring file extension)
10+
# then do not normalize the paths
11+
allTestFiles.push file.replace(/^\/base\/|\.js$/g, '')
712
return
813

914
require.config

requirejs.config.tpl.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
var allTestFiles = [];
22
var TEST_REGEXP = /(spec|test)\.js$/i;
33

4+
// Get a list of all the test files to include
45
Object.keys(window.__karma__.files).forEach(function(file) {
56
if (TEST_REGEXP.test(file)) {
67
// Normalize paths to RequireJS module names.
7-
allTestFiles.push(file);
8+
// If you require sub-dependencies of test files to be loaded as-is (requiring file extension)
9+
// then do not normalize the paths
10+
var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '');
11+
allTestFiles.push(normalizedTestModule);
812
}
913
});
1014

0 commit comments

Comments
 (0)