Skip to content

Commit

Permalink
docs(requirejs): normalize paths to RequireJS modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cironunes authored and vojtajina committed Mar 10, 2014
1 parent 85900c9 commit a99c387
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions docs/plus/01-requirejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,35 +114,41 @@ asynchronously as dependencies must be fetched before the tests are run.
The `test/main-test.js` file ends up looking like this:

```javascript
var tests = [];
for (var file in window.__karma__.files) {
if (window.__karma__.files.hasOwnProperty(file)) {
if (/Spec\.js$/.test(file)) {
tests.push(file);
}
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));
}
}
});

requirejs.config({
// Karma serves files from '/base'
baseUrl: '/base/src',
require.config({
// Karma serves files under /base, which is the basePath from your config file
baseUrl: '/base/src',

paths: {
'jquery': '../lib/jquery',
'underscore': '../lib/underscore',
},
// example of using shim, to load non AMD libraries (such as underscore and jquery)
paths: {
'jquery': '../lib/jquery',
'underscore': '../lib/underscore',
},

shim: {
'underscore': {
exports: '_'
}
},
shim: {
'underscore': {
exports: '_'
}
},

// ask Require.js to load these files (all our tests)
deps: tests,
// dynamically load all test files
deps: allTestFiles,

// start test run, once Require.js is done
callback: window.__karma__.start
// we have to kickoff jasmine, as it is asynchronous
callback: window.__karma__.start
});
```

Expand Down

0 comments on commit a99c387

Please sign in to comment.