Where should unit tests be placed in Meteor?

后端 未结 4 2026
悲哀的现实
悲哀的现实 2021-02-01 19:12

Is there a place where my tests can live without being run by Meteor?

I just started my first Meteor project, and began by writing unit tests with Mocha

相关标签:
4条回答
  • 2021-02-01 19:43

    Since This is question from 2012, and there is no single comprehensive answer here, I would like to attempt one here.

    This is a good starting point for starting to think about testing your meteor project.

    In a nutshell Step1: meteor add sanjo:jasmine Step2: meteor add velocity:html-reporter

    The moment you do this, and if your application is running ( or whenever you start your application back running) , on the right upper corner of browser- where you open your application is opened - you shall start seeing a blinking dot. That's it. You have now your testing framework in place.

    Now you can actually produce a directory structure with the help of this framework also. The moment you click on that blinking dot, you shall see a popup like below.

    This has convenience links for generating your test directory structure.

    Alternatively, you can do it manually as below. Next thing is to decide on directory structure. Meteor Documentation says enough about it. You need to have tests folder in your project root.

    Taking cue from here, you can go like this.

    <projectRoot>
    |---jasmine
          |---client
                 |--- integration
                          |---- my.first.integration.spec.js
          |---client
                 |--- unit
                          |---- my.first.unit.spec.js
    |---jasmine
          |---server
                 |--- integration
                          |---- my.first.integration.spec.js
          |---server
                 |--- unit
                          |---- my.first.unit.spec.js
    

    And Viola, start writing your jasmine tests. These posts can further help you.

    • Post1
    • Jasmine Documentation
    • This is another good tutorial
    0 讨论(0)
  • 2021-02-01 19:54

    Place your tests in the tests/ folder. Unlike Rails, which uses a folder named test for this purpose, Meteor uses the plural tests for this folder name.

    Assets stored in a folder named "tests" will be completely ignored by Meteor; these assets will not be loaded on the client or server.

    Ironically, I was tipped off by someone having the opposite issue who wants their tests loaded by the Meteor client.

    0 讨论(0)
  • 2021-02-01 19:57

    As of 0.6.0, an interesting approach is to exclusively use local smart packages for your app, which can be easily tested using Meteor's tinytest. You would have the bare minimum code residing outside of smart packages to bootstrap your app.

    EDIT: I've done this approach, and I don't even need bare minimum code residing outside of smart packages. The whole app is packages.

    0 讨论(0)
  • 2021-02-01 20:00

    Place your test files in tests folder and you should be fine. If your application is such that you have multiple files nested in server or client folder, you can replicate similar folder structure within your tests/client or tests/server directory. Not a rule but I think it helps for maintenance and I have had experience of spending hours debugging missing class error which was simply resolved by organising file structure in test folder.

    0 讨论(0)
提交回复
热议问题