node.jstestingmeteormeteor-velocity

How to structure meteor app for testing


I'm reading through the online book Meteor Testing and am a bit concerned about how it says you should structure your app. It says to create an object in the global namespace called "App" and append submodules as needed, like this:

App = {
    Services: {
        func1: [some function]
        func2: [some function]
        ...
    },
    Collections: {
        func1: [some function]
        func2: [some function]
        ...
    }
    ...
}

My concerns are:

  1. Will this negatively impact the security of my application?
  2. Where and when should I defined functions within the app namespace? Adding all of them in one place would quickly get overwhelming.
  3. Should I do this for all of the functions I want to unit test? If not, how do I access functions that I have defined within the scope of a template's javascript file?

If any of you could point me to additional resources on testing in meteor, I'd love to take a look at what other people suggest. Thanks.


Solution

  • You could sprinkle the definitions of all your functions among different files, but obviously load order would be important. I'd recommend creating a Meteor package for your project that would define all these functions and other globals needed, and then api.export('App') or api.export('App', 'client') (depending on your needs).