Question

I have a simple app, based partly on the ToDo-List example, which uses Backbone on the client side. I've installed RTD and managed to add the necessary stubs for templates at least, so now I'm stuck with the error ReferenceError: Can't find variable: Backbone

I've found this GitHub issue: Problems with _ - underscore - identifier, which is probably the same problem as I have it just with underscore instead of backbone.

The described solution to this was:

[...] The karma started phantom will require to have any dependancies in the karma.conf.js inside the files array.

Now I could add the backbone.js file from my packages folder to the files array, but few lines lower the whole .meteor/local folder is excluded:

exclude : [
    '**/3rd/**/*.js',
    '**/istanbul-middleware-port/**/*',
    'karma.conf.js',
    'app/.meteor/local',
    'app/server/fixture.js',
    'app/server/fixture.coffee',
    'app/packages/**/*'
],

And I don't want to test Backbone, I just use it in my application, exactly the same way, as it is used for the ToDo-List example.

What is the correct step by step solution to test (Meteor) applications with such packages (could be also jQuery, underscore or AngularJS which is referenced on the client)

Although I've had to do TDD for most of my university projects, our tests were usually only a bad joke and totally useless, so this is pretty much the first time for me, that I want to write useful tests.

Was it helpful?

Solution

We put our required 3rd-party libs in a 'unit/stubs' folder. Any mocks/stubs from our internal app go there as well. Load order can get tricky so we name the explicitly name the files to load in the order we want, like this: a1-jquery.min.js, a2-bootstrap-mocks.js.

We're still using a very early version of RTD but here's the relevant karma conf:

// list of files / patterns to load in the browser
files = [
    JASMINE,
    JASMINE_ADAPTER,

    // stubs come first so they can be available when all the units need them
    'test/rtd/lib/*-stubs.js',
    'test/unit/stubs/*.js',

    // simulate loading order of meteor folder structure
    'app/lib/**/*.js',
    'app/server/lib/**/*.js',
    'app/client/lib/**/*.js',

    // now all the dependencies have been sorted, the app code can be loaded
    'app/**/*.js',


    'test/unit/**/*.js'
];


// list of files to exclude
exclude = [
    'app/lib/3rd/**/*.js',
    '**/istanbul-middleware-port/**/*',
    'karma.conf.js',
    'app/.meteor/local'
];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top