Package testing

You can also test packages directly in isolation. You can find an example package here.

1. Add sanjo:jasmine to your package

Add or replace the Package.onTest block in your package.js.

Package.onTest(function(api) {
  api.use('package-to-test');
  api.use('sanjo:[email protected]');
  api.use('velocity:[email protected]');
});

It's important that you specify the version explicitly. Otherwise Meteor uses an outdated version.
Also you need to use the package that you test in the onTest block.

2. Create tests

Create your first test. The file can be anywhere in your package. I recommend to put them in the tests folder for consistency with your app tests.

describe('sanjo:jasmine on client', function () {
  it('works', function () {
    expect(it).toBeDefined();
  })
})
describe('sanjo:jasmine on server', function () {
  it('works', function () {
    expect(it).toBeDefined();
  })
})
describe('sanjo:jasmine on client and server', function () {
  it('works', function () {
    expect(it).toBeDefined();
  })
})

And then add the tests files to the Package.onTest block in your package.js

Package.onTest(function(api) {
  api.use('package-to-test');
  api.use('sanjo:[email protected]');
  api.use('velocity:[email protected]');
  
  api.addFiles('tests/server/example-spec.js', 'server');
  api.addFiles('tests/client/example-spec.js', 'client');
  api.addFiles('tests/example-spec.js', ['client', 'server']);
});

The architecture that you define for your test files will determine if it is a server or client tests. A test can also be executed on the client and the server.

3. Execute tests

meteor test-packages --driver-package=sanjo:jasmine package-to-test

If your package is not located in an app you can test it with:

meteor test-packages --driver-package=sanjo:jasmine ./

If you want to debug your server code, just add --debug-port 5858 as argument to the command.

If you want to run your package tests besides your app, specify a free port by adding --port 5000.

You can find a list of all available command options here.