karma-requirejs icon indicating copy to clipboard operation
karma-requirejs copied to clipboard

split out require-config for reuse in tests

Open CraigCav opened this issue 11 years ago • 4 comments

Rather than copy-pasting the requirejs.config paths and shims into the require.config for running tests, we can just load the applications requirejs configuration from test-main.js.

This PR was inspired by @jugglinMike's blog post on Effective Unit Testing with AMD.

CraigCav avatar Feb 11 '14 21:02 CraigCav

Does that work with the paths defined in require-config? It seems to me that if require-config.js defines a baseUrl (js) with paths and test-main.js defines a different baseUrl (base/js) the paths defined in require-config.js can't be used in the tests, as they will be served at base/js but the paths point to modules located at js.

uuilee avatar Mar 11 '14 14:03 uuilee

@uuilee Check out that article Craig referenced :)

jugglinmike avatar Mar 11 '14 15:03 jugglinmike

@jugglinmike, thanks fot the reference. For some reason I can't get my tests to work using:

require.config({
  baseUrl: '/base/js',
  deps: ['/base/js/src/config.js'],
  callback: function() {
    'use strict';
    require(tests, window.__karma__.start);
  }
});

instead i had to do the following:

require(['/base/js/src/config.js'], function() {
  'use strict';
  require.config({
    baseUrl: '/base/js',
    callback: function() {
      require(tests, window.__karma__.start);
    }
  });
});

In the former, it seemed that the baseUrl did not get properly overriden to /base/js.

uuilee avatar Mar 17 '14 12:03 uuilee

This really should be merged, as it simplifies the setup.

RubenCordeiro avatar Jul 23 '14 21:07 RubenCordeiro