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
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:
/karma.conf.js
==> /config/karma.conf.js
/src/
==> /public/src/
/index.html
==> /public/index.html
So. Right now in order to get everything working, it would make sense that you would have to:
in the karma.conf.js file change:
basePath: '',
to
basePath: '../',
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
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',
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With