Requirejs do not add “.js” for modules using karma

喜你入骨 提交于 2019-12-01 14:24:52

Here is an interesting read on how RequireJs handles this:

http://requirejs.org/docs/api.html#jsfiles

Reading that makes it seem like an issue with RequireJS, but there seems to be some debate on whether or not that is true. Regardless, this gist seems to solve the issue.

var tests = Object.keys(window.__karma__.files).filter(function (file) {
  return /\.spec\.js$/.test(file);
}).map(function(file){
  return file.replace(/^\/base\/src\/js\/|\.js$/g,'');
});

require.config({
  baseUrl: '/base/src/js'
});

require(tests, function(){
  window.__karma__.start();
});

It looks like trouble in require.js

The problem is in next: 1. When in deps appear absolute path - requirejs stop add ".js" for any require call 2. When in deps appear file with extension, for some reason requirejs again stop add ".js" for modules

Other Solution here - to replace bathUrl and add it to requirejs conf do not help.

For me solution is next:

var tests = Object.keys(window.__karma__.files).filter(function (file) {
    return (/\-jasmine\.js$/).test(file);
}).map(function (file) {
    return file.replace(/^\/|\.js$/g, '');
});

and

baseUrl: '',

for requirejs.conf

and i have no idea why requirejs still add "/base" for all url that are requested, but now all works fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!