Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Karma Require.js -- changing directory structure is killing everything

I've been trying to set up karma to work with Require.js now for a few days (and then later use require with angular) and it's been amazingly frustrating. Here's what my 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 karma example githubs' code and my code are the 3 changes to the file directory structure:

  1. /karma.conf.js

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

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

        ==> /public/index.html
    

So. Right now in order to get everything working, it would make sense that you would have to:

  1. run karma from within the conf directory,
  2. in the karma.conf.js file change:

    basePath: '',
    

    to

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

requirejs.config({

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

to

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

but it appears that no matter what I do I continue to get 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

^tldr: check the repo

like image 397
Andrew Luhring Avatar asked Mar 23 '14 09:03

Andrew Luhring


1 Answers

The answer was to add

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

  },

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

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

so it would be redundent to add it to the paths.

paths: {
    'jquery': '../lib/jquery',
    'underscore': '../lib/underscore',
},
like image 52
Andrew Luhring Avatar answered Nov 06 '22 04:11

Andrew Luhring