to says tokenize karma new users

By karma config you have to register every file your want to use in your tests. You can do that by adding patterns to your files array in your config.

A file pattern looks like this:

files: [ { pattern: ‘test/unit/*.js’, watched: true, //watching file modifications for test autorun included: true, //included as <script src=”…”> in the runner html file served: true //used by tests (the test server should serve it) } ]

You can use short pattern syntax:

files: [ ‘test/unit/*.js’ ]

This means exactly the same as the previous pattern.

If you don’t want to use your file in your test included as <script src=”file.js”></script>, then you have use included: false and load the file from within your tests via AJAX. Be aware that you should use relative urls for that, because the domain of the test server can always change…


The pattern order is important too, it uses reverse overriding:

files: [ {pattern: ‘*.js’, included: true} {pattern: ‘*.js’, included: false} ]

In this case every js file will be included, so the first pattern overrides the second.

For example by html files:

karma config:

files: [ {pattern: ‘bootstrap.js’, included: true} {pattern: ‘x.html’, included: false} ]

bootstrap.js:

var xhr = new XMLHttpRequest(); xhr.open(‘get’, ‘/base/x.html’, false); xhr.send(); console.log(xhr.status, xhr.responseText); //200, ‘<html content>’

The URI always has a /base prefix because Karma stores its own index.html and js files on the top level, so it needs a subfolder. If you want to find out what URIs are served, you can use this code:


var servedUris = Object.keys(window.__karma__.files);

I wrote some basic fs stuff to support sync read by Yadda: https://github.com/acuminous/yadda/blob/master/lib/shims/karma-fs.js You might be able to move it to a different project extend it, and use fs instead of AJAX in browser. At least that’s how I would do it with Browserify.

Similar Posts:

Leave a comment