marionette-js-runner
This project is the sum of a number of other smaller more focused projects:
See MDN
for more details about the intent of the project and where it's going.
Installing / Invoking tests
add marionette-js-runner and marionette-js-client to your project
npm install --save-dev marionette-client marionette-js-runner
Invoke a marionette-mocha test
./node_modules/.bin/marionette-mocha path/to/test.js
See ./node_modules/.bin/marionette-mocha --help
for more docs on what it can do.
Like mocha there is support for an "opts" file which will be
loaded with the specific configuration for your project.
The file must be called "marionette-mocha.opts" and live in one of the
following locations:
- test/
- tests/
- root of your project
Each location will be loaded if found. Any option that can be
passed into marionette-mocha
(see --help) can be placed in this file.
Exposed APIs for writing marionette tests
marionette
(suite/describe like a api)
The marionette function is a wrapper around mocha's suite/describe blocks.
They expose an additional field (a filter) which is an object which describes under which
conditions a test may execute.
The filter is matched vs metadata from the particular host (like firefox / b2g-desktop ) the test is running on.
Example host metadata
marionette('I always run', function() {
});
marionette('firefox only', { host: 'firefox' }, function() {
test('only executed when host is firefox');
});
marionette('b2g desktop or firefox', { host: ['firefox', 'b2g-desktop'] }, function() {
});
marionette.client
(marionette client interface)
Creating a client is easy. Each test will run in a completely clean state ( with its own profile ).
The default client has no profile options and is sync.
marionette('github.com', function() {
var github = 'http://github.com';
var client = marionette.client();
setup(function() {
client.goUrl(github);
});
test('logging into github', function() {
});
})
Clients can be configured to have custom profiles. For instance, let's say you want to test a packaged app with specialized settings...
marionette('my custom app', function() {
var client = marionette.client({
profile: {
prefs: {
'devtools.inspector.markupPreview': true
},
settings: {
"lockscreen.locked": false
},
apps: {
'domain-name-of-my-amazing-app.com': '/path/to/app'
}
}
});
})
Clients have different "driver" types which determine how they connect with the marionette server.
Typically you don't need to think about this, but it is important to note that the default driver is synchronous
which means each marionette operation blocks (you can't really run servers in the same process).
marionette('be async man', function() {
var client = marionette.client({
driver: require('marionette-client').Drivers.Tcp
});
var http = require('http');
test('talk to the server in this process', function(done) {
client.goUrl('http://localhost:port', function(err) {
if (err) return done(err);
done();
});
});
})
Multiple clients can also be created.
marionette('I like sending emails to myself', function() {
var clientA = marionette.client();
var clientB = marionette.client();
});
marionette.plugin
(plugin exposure/setup api)
One of the features of the client is extending its functionality without modifying the base code.
For example if you wanted to extend the client to
launch apps this can be done by exposing a new plugin.
marionette.plugin('apps', require('marionette-apps'));
marionette('my local test', function() {
var client = marionette.client();
var origin = 'app://calendar.gaiamobile.org';
marionette.plugin('myplugin', function(client) {
return {
doStuff: function() {}
};
});
setup(function() {
client.apps.launch(origin);
client.apps.switchToApp(origin);
});
test('that calendar works', function() {
});
test('myplugin', function() {
client.myplugin.doStuff();
});
})