Skip to content

Commit

Permalink
fix(init): fix test-main.(js/coffee) generation
Browse files Browse the repository at this point in the history
The `pathToModule` function sets a project up such that your spec
directory must be within your src directory. This approach directly
contradicts the example describing how to use RequireJS with Karma in
the documentation.

Fixes #1120, fixes #896
  • Loading branch information
freethejazz committed Mar 12, 2015
1 parent 7b1ef5e commit d8521ef
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 13 deletions.
6 changes: 1 addition & 5 deletions docs/plus/01-requirejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,10 @@ The `test/test-main.js` file ends up looking like this:
var allTestFiles = [];
var TEST_REGEXP = /test\.js$/;

var pathToModule = function(path) {
return path.replace(/^\/base\//, '').replace(/\.js$/, '');
};

Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(pathToModule(file));
allTestFiles.push(file);
}
});

Expand Down
4 changes: 1 addition & 3 deletions requirejs.config.tpl.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
allTestFiles = []
TEST_REGEXP = /(spec|test)(\.coffee)?(\.js)?$/i
pathToModule = (path) ->
path.replace(/^\/base\//, "").replace(/\.js$/, "").replace(/\.cofee$/, "")

Object.keys(window.__karma__.files).forEach (file) ->
# Normalize paths to RequireJS module names.
allTestFiles.push pathToModule(file) if TEST_REGEXP.test(file)
allTestFiles.push file if TEST_REGEXP.test(file)
return

require.config
Expand Down
6 changes: 1 addition & 5 deletions requirejs.config.tpl.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
var allTestFiles = [];
var TEST_REGEXP = /(spec|test)\.js$/i;

var pathToModule = function(path) {
return path.replace(/^\/base\//, '').replace(/\.js$/, '');
};

Object.keys(window.__karma__.files).forEach(function(file) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(pathToModule(file));
allTestFiles.push(file);
}
});

Expand Down

0 comments on commit d8521ef

Please sign in to comment.