Meteor test very long build times


#1

So, I run meteor test --driver-package practicalmeteor:mocha and it takes maybe a minute to a minute and a half to run a test. It there an obvious gotcha here that I’m missing?


#2

Today i tried wallaby js.
It’s expensive but i was immediatly hooked and had to bought it, what a time saver !


#3

Yea, that’s a little pricey, but worth it if it eliminates the headaches that come with Meteor testing. Which platform are you using it on?


#4

I’m using it on webstorm, which i like too.


#5

Can you share any pointers setting up Wallaby with Meteor?

I’m really keen to try it, but I’m not sure how to setup the wallaby config.


#6

I’m using a config file by Arunoda/Mantra, slightly modified :

module.exports = function (wallaby) {
  // There is a weird error with the mui and mantra.
  // See: https://goo.gl/cLH8ib
  // Using require here seems to be the error.
  // Renaming it into `load` just fixed the issue.
  var load = require;

  return {
    files: [
      { pattern: 'client/**/tests/*.js', ignore: true },
      { pattern: 'server/**/tests/*.js', ignore: true },
      'client/imports/modules/**/components/*.js',
      'client/imports/modules/**/actions/*.js',
      'client/imports/modules/**/containers/*.js',
      'client/imports/modules/**/libs/*.js',
      'client/imports/**/*.jsx'
    ],
    tests: [
      'client/**/tests/*.js'
    ],
    compilers: {
      '**/*.js*': wallaby.compilers.babel({
        babel: load('babel-core'),
        presets: ['es2015', 'react', 'stage-2']
      })
    },
    env: {
      type: 'node'
    },
    testFramework: 'mocha',
    setup: function() {
      global.React = require('react');
    }
  };
};

#7

Awesome!

I had to learn about those babel presets and how to install them. Also, it seems I had to install babel-core.

I’m testing this with the 1.3 version of the Meteor-React Todo app tutorial. I modified your config a bit more, just to load different files

  return {
  return {
    files: [
      'imports/**.js'
    ],
    tests: [
      '**/*.tests.js'
    ],
    ...

Now that wallaby appears to be running, I’m getting my first error, it’s not finding modules:

Error: Cannot find module 'meteor/meteor'
at imports/api/tasks.tests.js:1:0

That line in imports/api/tasks.tests.js is:

import { Meteor } from 'meteor/meteor';

Not sure how to get wallaby to load that module.


#8

Running wallaby.js now with IntelliJ Idea. Wow, this is unbelievable. Everyone should try this…


#9

@mhurwi I’ve hit the same issue, did you have any luck resolving it?


#10

@tomRedox and @mhurwi, that error is because you cannot just import the Meteor framework that way. But it is possible to stub out Meteor parts, which is a good testing strategy anyway. Don’t test parts that are not your to test.

See more about this in a post I’ve written here yesterday.

In the opening post I explain how to use proxyquire with sinon to stub out the Meteor framework, and in followup comment I explain how to use testdouble to do the very same thing.


#11

@smeijerm thanks for the response, I saw your post, it looks really useful.

I completely agree re mocking (and potentially DI too), but actually in my case the module I couldn’t load was meteor/practicalmeteor:chai that I needed in order to set up the assertions in the unit test! The actual SUT was a vanilla JS class. Looking at your code I see your using Chai straight from npm which is a much better approach.

That does beg a question though, for external modules like Lodash, moment, accounting and the like I probably wouldn’t bother stubbing those out, I’m happy to accept them as well tested black boxes (i.e. they aren’t things I feel the need to test). If I use the npm versions that should be fine, but for Meteor packages it looks like I’d need to stub them which is a nuisance.


#12

The trick is indeed to use npm packages whenever possible.

If you really want to use the meteor lodash package (although I cannot come up with a reason why), you should be able to replace the meteor lodash package by an npm lodash module while running the tests.

Be sure to use npm install --save-dev lodash in that case to prevent a double presence in your production code.

And be sure to npm install the same version as your meteor package. Because you won’t be testing the same functionality otherwise.


Meteor 1.3 testing - with "meteor/meteor:x" package imports
#13

Whilst it works with WebStorm I’m wondering if it will work with Meteor as it’s not listed at all: https://wallabyjs.com/docs/intro/get-started-jetbrains.html


#14

Should have googled more. I’ve found this recent addition so it seems with the config it works:

https://gist.github.com/Floriferous/982f64b897fc114422464217abbce713