Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harpreetkhalsagtbit/55022792c1b6ab4367c4 to your computer and use it in GitHub Desktop.
Save harpreetkhalsagtbit/55022792c1b6ab4367c4 to your computer and use it in GitHub Desktop.
Automate Testing of a Meteor Application using TheIntern.io

Testing Meteor Application with TheIntern.io

Problem

  1. Where to place tests folder and npm packages in Meteor folder structure so that they won't run with meteor command.

  2. How to access Meteor global variable and Meteor Collections.

  3. How to run tests?

Solutions

  1. Where to place tests?

    Run tests from Meteor only

    Put node_module with intern already installed under tests folder. tests folder is immune to meteor, it won't get executed when you run your meteor project.

    Folder Structure should be like this:

     tests/
     	node_module/
     		intern
     	tests/
     		functional/
     			index.js
    

    Or

    Don't put npm in Meteor package. Make a separate folder structure outside the Meteor project folder as a separate project.

    TheIntern only needs a URL and you can run that URL from anywhere. Even you can test Facebook.com without having its code using it.

  2. Access Meteor global variable and Collections

    We have execute function in which we can run any JS code. Bingoooooo!!!!!! We can access Browsers window variable and Meteor as well.

  3. How to run tests.

    If you are running tests from Meteor only

     cd tests
    
     node node_modules/.bin/intern-runner config=intern
    

    Or

    In same way as normal TheIntern.io's test suites run.

How?

Sample code: Using execute method

For more details on execute function: click here

define(function (require) {
    var registerSuite = require('intern!object');
    var assert = require('intern/chai!assert');
    registerSuite({
        name: 'index',

        'greeting form': function () {
            var rem = this.remote;
            return this.remote
                .get(require.toUrl('localhost:3000'))
                .setFindTimeout(5000)
                .execute(function() {
		                console.log("browser window object", window)
                        return Products.find({}).fetch().length
                    })
                .then(function (text) {
                    console.log(text)
                    assert.strictEqual(text, 2,
                        'Yes I can access Meteor and its Collections');
                });
        }
    });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment