1

I started using bower within my web application now and as I am using wallabyjs for testing I added

{ pattern: 'bower_components/**/*.*', instrument: false, load: false }

to my wallabyjs configuration. Everything is working fine that way. But as I've read in the webpack documentation this is not really the recommended way:

The more efficient approach that we would recommend is to specify an absolute path in your wallaby configuration for webpack for your external modules (not your source files) instead

I've tried to achieve something similar for my scenario (with requirejs) but failed. My current questions:

  • What is the best way to handle the bower_components folder using requirejs/ wallabyjs?

  • It seems that it is mandatory that the folder bower_components is a solution folder. As soon as I say "Exclude from project" within Visual Studio my tests fail again.

timtos
  • 2,225
  • 2
  • 27
  • 39

1 Answers1

1

In case of require.js, you just need to let wallaby.js know where its internal web server should serve the files from. This way you may remove them from your files list and don't have to include to the solution.

You may do this by adding a middleware function, that can map the web server paths to local folders:

 module.exports = function () {
   return {
     files: [
       ...
     ],

     tests: [
       ...
     ],

     // telling wallaby to serve bower_components project folder
     // ‘as is’ from the wallaby.js web server
     middleware: (app, express) => {
       app.use('/bower_components',
               express.static(
                  require('path').join(__dirname, 'bower_components')));
     }
   };
 };

You may need to change the mapping depending on how your app requests bower_components.

Artem Govorov
  • 903
  • 6
  • 10
  • 1
    No, functions can only be defined in JS. Moving the JSON config file to JS is pretty straightforward though: just create a JS file with the same name, add `module.exports = function () { return ...;}` to it and paste your current JSON instead of the `...`. – Artem Govorov Mar 23 '16 at 01:41