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

前端 未结 2 1760
余生分开走
余生分开走 2021-01-17 00:08

I have simple test, that must work in webstorm using karma and requirejs.

The problem is that for some reason requirejs do not add \".js\" for modules i was loading

2条回答
  •  [愿得一人]
    2021-01-17 00:25

    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();
    });
    

提交回复
热议问题