1.6.x does not require test modules #530

Closed
jonbuffington opened this Issue Apr 2, 2013 · 8 comments

Comments

Projects
None yet
5 participants

In brunch 1.5.x, each test module would be required in the generated test.js file allowing the test cases to be executed when loaded in a browser. In 1.6.x, brunch does not require test modules. Is this an omission or a change in generating concatenated unit tests scripts?

  files:
    javascripts:
      joinTo:
        'scripts/app.js': /^app/
        'scripts/vendor.js': /^vendor/
        'test/scripts/test.js': /^test(\/|\\)(?!vendor)/
        'test/scripts/test-vendor.js': /^test(\/|\\)(?=vendor)/
Owner

paulmillr commented Apr 2, 2013

This change should be re-introduced, but with more explicitness. I agree this is useful.

User should be able to specify output path like paths: test: 'test/scripts/test.js' (and this will be the default).

It was removed because the whole test feature was removed.

Yes, it was very good feature. Maybe just not wrap test files to commonjs wrapper, and use common coffee-script wrapper? or add option like nowrapper: /^test/.
Now I need redefine modules.wrapper in order to run tests.

  modules:
    wrapper: (path, data) ->
      if path.match(/\.(coffee|hbs)$/)
        if !path.match(/^test/) && data.match(/(module\.)?exports/)
          # commonjs wrapper
          path = path.replace(/^app\//, '').replace(/\.(coffee|hbs)$/, '')
          data = """
          require.define({"#{path}": function(exports, require, module) {
            #{data}
          }});
          """
        else
          # classic coffee-script wrapper
          data = """
          (function() {
            #{data}
          }).call(this);
          """
      data + '\n\n'

Are there another way to run tests in brunch 1.6.x?

Owner

paulmillr commented Apr 4, 2013

nah, no way

Contributor

cesutherland commented May 29, 2013

I am bumping into this as well. Should we manually require each of our test files for now?

Owner

paulmillr commented May 29, 2013

1.7 will have require.list which will list all modules.

closing this

paulmillr closed this May 29, 2013

Contributor

cesutherland commented Sep 6, 2013

Example for requiring test scripts in brunch 1.7:

    if (require.list) {
      _.each(require.list(), function (item) {
        if (/^test/.test(item)) {
          require(item);
        }
      });
    }
Owner

paulmillr commented Sep 6, 2013

More functional approach:

require.list().filter(function(_) {return /^test/.test(_);}).forEach(require)

reubano commented Apr 30, 2014

This worked for me on 1.7.13

brunch-config.coffee

  files:
    javascripts:
      joinTo:
        'javascripts/app.js': /^app/
        'javascripts/vendor.js': /^bower_components/
        'test/javascripts/test.js': /^test(\/|\\)(?!vendor)/
        'test/javascripts/test-vendor.js': /^test(\/|\\)(?=vendor)/

    stylesheets:
      joinTo: 
        'stylesheets/app.css': /^(?!test)/
        'test/stylesheets/test.css': /^test/

add this to index.html

  <script>
  $(function() {
        window.require.list()
          .filter(function(_) {return /-test$/.test(_);})
          .forEach(require);

    if (window.mochaPhantomJS) { mochaPhantomJS.run(); }
    else { mocha.run(); }
  });
  </script>

I also had to symlink the required bower devDependencies ln -s /path/to/project/bower_components/sinon/lib/sinon.js /path/to/project/test/vendor/scripts, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment