diff --git a/docs/plus/01-requirejs.md b/docs/plus/01-requirejs.md index 874c491ec..49c29dfad 100644 --- a/docs/plus/01-requirejs.md +++ b/docs/plus/01-requirejs.md @@ -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 }); ``` diff --git a/lib/init.js b/lib/init.js index 49f0612a3..11d277b3d 100755 --- a/lib/init.js +++ b/lib/init.js @@ -125,6 +125,13 @@ var questions = [{ 'Enter empty string to move to the next question.', multiple: true, validate: validatePattern +}, { + id: 'generateTestMain', + question: 'Do you wanna generate a bootstrap file for RequireJS?', + hint: 'This will generate test-main.js/coffee that configures RequiseJS and starts the tests.', + options: ['no', 'yes'], + boolean: true, + condition: function(answers) {return answers.requirejs;} }, { id: 'includedFiles', question: 'Which files do you want to include with