Karma Require.js - changing directory structure kills everything

I'm trying to set up karma to work with Require.js now for a few days (and then use it later with angular), and it was amazingly unpleasant. Here is what this file tree looks like for this example:

$ tree . |-- public | |-- index.html | |-- src | |-- app.js | `-- main.js |-- config | |-- karma.conf.js |-- lib | |-- jquery.js | |-- require.js | `-- underscore.js |-- src | |-- app.js | `-- main.js `-- test |-- appSpec.js `-- test-main.js 

Note:

This repository I'm working on is a clone of the one used in the karma requirejs example . The only difference between the garmubs example code is the karma example , and my code is 3 changes in the file directory structure:

  • /karma.conf.js

      ==> /config/karma.conf.js 
  • / src /

      ==> /public/src/ 
  • /index.html

      ==> /public/index.html 

So. Right now, for everything to work, it would be wise that you have to:

  • run karma from the conf directory,
  • in the karma.conf.js file:

     basePath: '', 

    to

     basePath: '../', 
  • and in the file test / test-main.js (which is the requirejs.config file):

requirejs.config ({

 // Karma serves files from '/base' baseUrl: '/base/src', 

to

 requirejs.config({ // Karma serves files from '/base' baseUrl: '../base/src', 

but it seems that no matter what I do, I keep getting the same error:

 ERROR: 'There is no timestamp for /base/src/app.js!' Uncaught Error: Script error for: app http://requirejs.org/docs/errors.html#scripterror at /node_modules/requirejs/require.js:141 

or

  Uncaught Error: Script error for: jquery http://requirejs.org/docs/errors.html#scripterror at /node_modules/requirejs/require.js:141 Uncaught Error: Script error for: underscore http://requirejs.org/docs/errors.html#scripterror at /node_modules/requirejs/require.js:141 

^ TL; DR: check repo

+6
source share
1 answer

The answer was to add

 paths: { 'jquery': '../lib/jquery', 'underscore': '../lib/underscore' 'app' : '../public/src/app' <==== }, 

whereas in the original example, app.js code is added via:

 var tests = []; for (var file in window.__karma__.files) { if (/Spec\.js$/.test(file)) { tests.push(file); } } 

therefore, it would be superfluous to add it along the way.

 paths: { 'jquery': '../lib/jquery', 'underscore': '../lib/underscore', }, 
+3
source

All Articles