Search code examples
node.jsmeteorecmascript-6mocha.js

meteortesting mocha --full-app is executing 0 tests


I have meteor app which is based on wekan https://github.com/wekan/wekan.

I have written some tests which are in the /test directory.

For my tests i use https://github.com/meteortesting/meteor-mocha

When i run meteor test --driver-package meteortesting:mocha the tests run but fail because my code is not fully loaded.

So i tried to use the --full-app parameter. Now the app code loads and runs somewhat complete, but 0 tests are executed.

What is wrong here?

How can i execute my tests with all the code?


Solution

  • I read this question quite often, so let me pick this apart, because there are multiple ways of doing things. Btw - if you have a new project, chances are high you're already avoiding eager loading.

    Eager loading

    This option was introduced in Meteor 1.3 and has been the default option ever since.

    When running meteor or meteor run in this mode, all files excepted of those in the folder /imports are loaded automatically. There are also a few other rules to it, all can be found on this page: https://guide.meteor.com/structure.html#load-order

    When running tests in this mode, different rules apply and in fact no files is loaded that do not match the following expressions:

    • meteor test only loads files matching *.test[s].*, or *.spec[s].*
    • meteor test --full-app only loads files matching *.app-test[s].* and *.app-spec[s].*

    Additional files can (as you're used to) be imported as usual. All this can be found on this page: https://guide.meteor.com/testing.html#test-modes

    Avoid eager loading

    Since Meteor 1.7, following a discussion of how to get rid of this special /imports directory (https://github.com/meteor/meteor-feature-requests/issues/135), a new way was introduced:

    When a section like the following exists on the package.json file of your project, Meteor will load only those files in the respective modes:

    "meteor": {
      "mainModule": {
        "client": "client/main.js",
        "server": "server/main.js"
      },
      "testModule": {
        "client": "client/tests.js",
        "server": "server/tests.js"
      }
    }
    

    In this mode, you can differ between tests and full-app tests by Meteor.isAppTest().

    If a section doesn't exist, eager loading is used instead for this section. We in our projects use eager loading for tests but prefer a non-eager way for the main application. Therefore we only define the mainModule section, but not the testModule section.

    Sadly, those details are not well presented in the Meteor Guide. They can be found in the release notes of Meteor 1.7: https://docs.meteor.com/changelog.html#changes-21

    Hope this helps and gives a better insight of how loading of files works.