Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
125
gaia/tests/jsmarionette/mocha/mocha-json-proxy/consumer.js
Executable file
125
gaia/tests/jsmarionette/mocha/mocha-json-proxy/consumer.js
Executable file
|
|
@ -0,0 +1,125 @@
|
|||
'use strict';
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
var MESSAGE_PREFIX = 'mocha-proxy';
|
||||
|
||||
// runnable events which need a runnable wrapper
|
||||
var RUNNABLE_EVENTS = [
|
||||
'pending',
|
||||
'pass',
|
||||
'fail',
|
||||
'test',
|
||||
'test end',
|
||||
'suite',
|
||||
'suite end'
|
||||
];
|
||||
|
||||
function Runnable(event) {
|
||||
for (var key in event) {
|
||||
this[key] = event[key];
|
||||
}
|
||||
}
|
||||
|
||||
Runnable.prototype = {
|
||||
slow: function() {
|
||||
return this._slow;
|
||||
},
|
||||
|
||||
fullTitle: function() {
|
||||
var title = '';
|
||||
if (this.parent) {
|
||||
title = this.parent.fullTitle();
|
||||
if (title) {
|
||||
title += ' ';
|
||||
}
|
||||
}
|
||||
title += this.title;
|
||||
return title;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Consumer for a mocha runner process using the mocha-json-proxy reporter.
|
||||
*
|
||||
*
|
||||
* var consumer = new Consumer(
|
||||
* forkedMochaProcess // should use _mocha NOT mocha (which spawns another
|
||||
* process)
|
||||
* );
|
||||
*
|
||||
* // consumer is also an event emitter which emits standard mocha events.
|
||||
* consumer.on('start', function() {
|
||||
* });
|
||||
*
|
||||
* consumer.on('pass', function() {
|
||||
* });
|
||||
*
|
||||
* @param {ChildProcess} child to listen to messages on.
|
||||
*/
|
||||
function Consumer(child) {
|
||||
EventEmitter.call(this);
|
||||
|
||||
this._suiteStack = [];
|
||||
this._objects = {};
|
||||
|
||||
child.on('message', function(content) {
|
||||
if (Array.isArray(content) && content[0] === MESSAGE_PREFIX) {
|
||||
this.transformEvent(content[1]);
|
||||
}
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
Consumer.prototype = {
|
||||
__proto__: EventEmitter.prototype,
|
||||
|
||||
referenceObject: function(event, object) {
|
||||
// objects without the _id property don't need to be a single reference.
|
||||
if (!object || !object._id) {
|
||||
return object;
|
||||
}
|
||||
// find the original reference or create it.
|
||||
var ref = this._objects[object._id];
|
||||
|
||||
if (!ref) {
|
||||
// convert the object into an instanceof Runnable if its event is a suite
|
||||
// or test.
|
||||
if (RUNNABLE_EVENTS.indexOf(event) !== -1) {
|
||||
object = new Runnable(object);
|
||||
}
|
||||
// when no reference is found this is the correct object.
|
||||
ref = this._objects[object._id] = object;
|
||||
} else {
|
||||
// otherwise we need to update the reference
|
||||
Object.keys(object).forEach(function(key) {
|
||||
var value = object[key];
|
||||
ref[key] = value;
|
||||
});
|
||||
}
|
||||
|
||||
// Re-create the parent based on the referenced ID.
|
||||
if (ref._parentId) {
|
||||
ref.parent = this.referenceObject('suite', { _id: ref._parentId });
|
||||
delete ref._parentId;
|
||||
}
|
||||
|
||||
return ref;
|
||||
},
|
||||
|
||||
transformEvent: function(event) {
|
||||
var name = event[0];
|
||||
var runnable = event[1] = this.referenceObject(name, event[1]);
|
||||
|
||||
if (name === 'suite') {
|
||||
this._suiteStack.push(runnable);
|
||||
// add the root .suite
|
||||
if (!this.suite) {
|
||||
this.suite = runnable;
|
||||
}
|
||||
}
|
||||
|
||||
this.emit.apply(this, event);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = Consumer;
|
||||
15
gaia/tests/jsmarionette/mocha/mocha-json-proxy/package.json
Executable file
15
gaia/tests/jsmarionette/mocha/mocha-json-proxy/package.json
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "mocha-json-proxy",
|
||||
"version": "0.0.7",
|
||||
"author": "James Lal [:lightsofapollo]",
|
||||
"description": "Mocha JSON proxy reporter",
|
||||
"main": "consumer",
|
||||
|
||||
"dependencies": {
|
||||
"debug": "*"
|
||||
},
|
||||
|
||||
"peerDependencies": {
|
||||
"mocha": "^2"
|
||||
}
|
||||
}
|
||||
146
gaia/tests/jsmarionette/mocha/mocha-json-proxy/reporter.js
Executable file
146
gaia/tests/jsmarionette/mocha/mocha-json-proxy/reporter.js
Executable file
|
|
@ -0,0 +1,146 @@
|
|||
'use strict';
|
||||
var Base = require('mocha').reporters.Base;
|
||||
|
||||
// list of taboo properties to never clone
|
||||
var TABOO = ['err'];
|
||||
|
||||
var EVENTS = [
|
||||
'pending',
|
||||
'pass',
|
||||
'fail',
|
||||
'test',
|
||||
'test end',
|
||||
'suite',
|
||||
'suite end',
|
||||
'start',
|
||||
'end'
|
||||
];
|
||||
|
||||
var ALLOWED_OBJECTS = ['err'];
|
||||
|
||||
function write(event, content) {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
|
||||
if (!process.env[Reporter.FORK_ENV]) {
|
||||
process.stdout.write(JSON.stringify(args) + '\n');
|
||||
return;
|
||||
}
|
||||
|
||||
process.send(['mocha-proxy', args]);
|
||||
}
|
||||
|
||||
function cloneValue(value) {
|
||||
switch (typeof value) {
|
||||
case 'object':
|
||||
return cloneTestObject(value);
|
||||
case 'function':
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function cloneTestObject(object) {
|
||||
var keys = Object.keys(object),
|
||||
result = {};
|
||||
|
||||
for (var i = 0, len = keys.length; i < len; i++) {
|
||||
var key = keys[i];
|
||||
var value = object[key];
|
||||
|
||||
// don't clone taboo properties
|
||||
if (TABOO.indexOf(key) !== -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// In order to optimize transmission, don't clone the parent. Annotate its
|
||||
// ID so the consumer can correctly re-create the relationship.
|
||||
if (key === 'parent') {
|
||||
result._parentId = value._id;
|
||||
continue;
|
||||
}
|
||||
|
||||
// don't copy objects recursively
|
||||
if (typeof value === 'object' && ALLOWED_OBJECTS.indexOf(key) === -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result[key] = cloneValue(value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function cloneError(err) {
|
||||
var result = {
|
||||
name: err.name || '',
|
||||
stack: err.stack,
|
||||
type: err.type || 'Error',
|
||||
constructorName: err.constructorName || 'Error',
|
||||
expected: err.expected || null,
|
||||
actual: err.actual || null
|
||||
};
|
||||
|
||||
if (err && 'uncaught' in err) {
|
||||
result.uncaught = err.uncaught;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function defaultHandler(type, runner, payload) {
|
||||
return write(type, cloneValue(payload));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Static object responsible for converting each event type.
|
||||
*/
|
||||
var EventHandler = {
|
||||
fail: function(event, runner, payload, err) {
|
||||
var jsonPayload = cloneValue(payload);
|
||||
// remove .err so it does not override the real error.
|
||||
if (jsonPayload.err) {
|
||||
delete jsonPayload.err;
|
||||
}
|
||||
|
||||
write(event, jsonPayload, cloneError(err));
|
||||
}
|
||||
};
|
||||
|
||||
function Reporter(runner) {
|
||||
var objects = [];
|
||||
var ids = 1;
|
||||
|
||||
Base.call(this, runner);
|
||||
|
||||
EVENTS.forEach(function(event) {
|
||||
var handler = EventHandler[event] || defaultHandler;
|
||||
handler = handler.bind(this, event, runner);
|
||||
runner.on(event, function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
var runnable = args[0];
|
||||
|
||||
// when we find an object create a unique ID for it.
|
||||
if (typeof runnable === 'object' && runnable !== null) {
|
||||
var idx = objects.indexOf(runnable);
|
||||
if (idx === -1) {
|
||||
runnable._id = ids++;
|
||||
objects.push(runnable);
|
||||
} else {
|
||||
// assign a unique objects[idx]._id to the runnable.
|
||||
runnable._id = objects[idx]._id;
|
||||
}
|
||||
}
|
||||
handler.apply(this, args);
|
||||
}.bind(this));
|
||||
}, this);
|
||||
}
|
||||
|
||||
Reporter.write = write;
|
||||
|
||||
Reporter.prototype = Object.create(Base.prototype);
|
||||
|
||||
Reporter.FORK_ENV = 'MOCHA_PROXY_SEND_ONLY';
|
||||
|
||||
module.exports = Reporter;
|
||||
23
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/acceptance/consumer.js
Executable file
23
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/acceptance/consumer.js
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
/* global forkFixture */
|
||||
'use strict';
|
||||
var Consumer = require('../../consumer');
|
||||
var Mocha = require('mocha');
|
||||
|
||||
suite('reporter', function() {
|
||||
function testReporter(reporterType) {
|
||||
suite(reporterType, function() {
|
||||
['pass', 'fail', 'pending'].forEach(function(testType) {
|
||||
test(test, function(done) {
|
||||
var child = forkFixture(testType);
|
||||
var runner = new Consumer(child);
|
||||
/* jshint nonew: false */
|
||||
new Mocha.reporters[reporterType](runner);
|
||||
/* jshint nonew: true */
|
||||
runner.once('end', done);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
['Dot', 'Spec'].forEach(testReporter);
|
||||
});
|
||||
46
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/acceptance/reporter.js
Executable file
46
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/acceptance/reporter.js
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
/* global assert, forkFixture */
|
||||
'use strict';
|
||||
suite('reporter', function() {
|
||||
var msgs = [];
|
||||
var child;
|
||||
|
||||
setup(function(done) {
|
||||
this.timeout('10s');
|
||||
child = forkFixture('pass');
|
||||
child.on('message', function(content) {
|
||||
if (Array.isArray(content) && content[0] === 'mocha-proxy') {
|
||||
var msg = content[1];
|
||||
msgs.push(msg[0]);
|
||||
if (msg[0] === 'end') {
|
||||
return done();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('got messages', function() {
|
||||
var expectedMsgs = [
|
||||
'start',
|
||||
'suite',
|
||||
'suite',
|
||||
'test',
|
||||
'pass',
|
||||
'test end',
|
||||
'test',
|
||||
'pass',
|
||||
'test end',
|
||||
'suite end',
|
||||
'suite',
|
||||
'test',
|
||||
'pass',
|
||||
'test end',
|
||||
'suite end',
|
||||
'suite end',
|
||||
'end'
|
||||
];
|
||||
|
||||
assert.deepEqual(msgs, expectedMsgs);
|
||||
});
|
||||
|
||||
});
|
||||
150
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/consumer.js
Executable file
150
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/consumer.js
Executable file
|
|
@ -0,0 +1,150 @@
|
|||
/* global forkFixture */
|
||||
'use strict';
|
||||
var assert = require('assert');
|
||||
|
||||
suite('consumer', function() {
|
||||
var child;
|
||||
var Consumer = require('../consumer');
|
||||
var subject;
|
||||
|
||||
var EVENTS = [
|
||||
'start',
|
||||
'pass',
|
||||
'test',
|
||||
'test end',
|
||||
'suite',
|
||||
'suite end',
|
||||
'end'
|
||||
];
|
||||
|
||||
var emitted;
|
||||
|
||||
setup(function(done) {
|
||||
emitted = {};
|
||||
child = forkFixture('pass');
|
||||
subject = new Consumer(child);
|
||||
|
||||
EVENTS.forEach(function(event) {
|
||||
emitted = {};
|
||||
subject.on(event, function() {
|
||||
if (!emitted[event]) {
|
||||
emitted[event] = [];
|
||||
}
|
||||
|
||||
emitted[event].push(Array.prototype.slice.call(arguments));
|
||||
});
|
||||
});
|
||||
|
||||
subject.once('end', done);
|
||||
});
|
||||
|
||||
function emitsRunnable(event) {
|
||||
if (typeof event === 'string') {
|
||||
return emitted[event].forEach(emitsRunnable);
|
||||
}
|
||||
|
||||
assert.ok(typeof event[0].slow === 'function', 'has .slow');
|
||||
assert.equal(event[0].slow(), event[0]._slow);
|
||||
|
||||
assert.ok(typeof event[0].fullTitle === 'function', 'has .fullTitle()');
|
||||
|
||||
if (event[0].parent && event[0].parent.fullTitle()) {
|
||||
assert.equal(
|
||||
event[0].fullTitle(),
|
||||
event[0].parent.fullTitle() + ' ' + event[0].title
|
||||
);
|
||||
} else {
|
||||
assert.equal(
|
||||
event[0].fullTitle(),
|
||||
event[0].title
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
test('.suite', function() {
|
||||
assert.ok(subject.suite);
|
||||
assert.ok(subject.suite.root);
|
||||
});
|
||||
|
||||
suite('suite', function() {
|
||||
test('is runnable', function() {
|
||||
emitsRunnable('suite');
|
||||
});
|
||||
|
||||
test('child suite should have reference to parent', function() {
|
||||
var parent = emitted.suite[0][0];
|
||||
var child1 = emitted.suite[1][0];
|
||||
var child2 = emitted.suite[2][0];
|
||||
|
||||
assert.ok(!parent.parent, 'root suite has no parent');
|
||||
assert.strictEqual(
|
||||
child1.parent,
|
||||
parent,
|
||||
'first child references parent'
|
||||
);
|
||||
assert.strictEqual(
|
||||
child2.parent,
|
||||
parent,
|
||||
'second child references parent'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test('suite end', function() {
|
||||
emitsRunnable('suite end');
|
||||
});
|
||||
|
||||
test('test', function() {
|
||||
emitsRunnable('test');
|
||||
});
|
||||
|
||||
test('pass', function() {
|
||||
emitsRunnable('pass');
|
||||
});
|
||||
|
||||
test('test end', function() {
|
||||
emitsRunnable('test end');
|
||||
});
|
||||
|
||||
suite('objects with ._ids are the same', function() {
|
||||
var tests;
|
||||
var suites;
|
||||
|
||||
function group(events, target) {
|
||||
events.forEach(function(event) {
|
||||
emitted[event].forEach(function(items) {
|
||||
items.forEach(function(item) {
|
||||
if (!target[item.title]) {
|
||||
target[item.title] = [];
|
||||
}
|
||||
|
||||
target[item.title].push(item);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
setup(function() {
|
||||
tests = {};
|
||||
suites = {};
|
||||
|
||||
group(['test', 'pass', 'test end'], tests);
|
||||
group(['suite', 'suite end'], suites);
|
||||
});
|
||||
|
||||
test('tests async', function() {
|
||||
var test = tests.async[0];
|
||||
tests.async.forEach(function(item) {
|
||||
assert.strictEqual(test, item);
|
||||
});
|
||||
});
|
||||
|
||||
test('suite', function() {
|
||||
var suite = suites.pass[0];
|
||||
suites.pass.forEach(function(item) {
|
||||
assert.strictEqual(suite, item);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
17
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/fixtures/fail.js
vendored
Executable file
17
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/fixtures/fail.js
vendored
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
suite('fail', function() {
|
||||
test('sync', function() {
|
||||
throw new Error('sync');
|
||||
});
|
||||
|
||||
test('async', function(done) {
|
||||
done(new Error('async'));
|
||||
});
|
||||
|
||||
test('uncaught', function() {
|
||||
process.nextTick(function() {
|
||||
throw new Error('woot');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
8
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/fixtures/pass.js
vendored
Executable file
8
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/fixtures/pass.js
vendored
Executable file
|
|
@ -0,0 +1,8 @@
|
|||
'use strict';
|
||||
suite('pass', function() {
|
||||
test('sync', function() {});
|
||||
test('async', function(done) { process.nextTick(done); });
|
||||
});
|
||||
suite('pass 2', function() {
|
||||
test('sync 2', function() {});
|
||||
});
|
||||
4
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/fixtures/pending.js
vendored
Executable file
4
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/fixtures/pending.js
vendored
Executable file
|
|
@ -0,0 +1,4 @@
|
|||
'use strict';
|
||||
suite('pending', function() {
|
||||
test('mepending');
|
||||
});
|
||||
9
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/fixtures/suites.js
vendored
Executable file
9
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/fixtures/suites.js
vendored
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
'use strict';
|
||||
suite('a', function() {
|
||||
suite('b', function() {
|
||||
suite('c', function() {
|
||||
test('done', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
63
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/helper.js
Executable file
63
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/helper.js
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
'use strict';
|
||||
var exec = require('child_process').exec,
|
||||
fork = require('child_process').fork,
|
||||
EE = require('events').EventEmitter,
|
||||
debug = require('debug')('mocha-json-proxy:test');
|
||||
|
||||
|
||||
function forkFixture(test) {
|
||||
var reporterPath = __dirname + '/../reporter.js';
|
||||
var exec = __dirname + '/../../../../.bin/_mocha';
|
||||
var cmd = [
|
||||
'--reporter', reporterPath,
|
||||
'--ui', 'tdd',
|
||||
__dirname + '/fixtures/' + test
|
||||
];
|
||||
|
||||
var env = {};
|
||||
for (var key in process.env) {
|
||||
env[key] = process.env[key];
|
||||
}
|
||||
|
||||
var runnerOpts = {
|
||||
env: env
|
||||
};
|
||||
|
||||
// turn on the option to send messages directly between processes.
|
||||
runnerOpts.env[require(reporterPath).FORK_ENV] = true;
|
||||
|
||||
return fork(exec, cmd, runnerOpts);
|
||||
}
|
||||
|
||||
function runFixture(test, callback) {
|
||||
var cmd =
|
||||
__dirname + '/../../../../.bin/mocha' +
|
||||
' --ui tdd --reporter ' + __dirname + '/../reporter ' +
|
||||
__dirname + '/fixtures/' + test;
|
||||
|
||||
var emitter = new EE();
|
||||
exec(cmd, function(err, stdout, stderr) {
|
||||
debug('stdout', stdout);
|
||||
if (stderr) {
|
||||
console.error('ERR>>', stderr);
|
||||
}
|
||||
|
||||
callback(null, emitter);
|
||||
|
||||
var out = stdout.trim().split('\n');
|
||||
out.forEach(function(line) {
|
||||
var json;
|
||||
try {
|
||||
json = JSON.parse(line);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
emitter.emit.apply(emitter, json);
|
||||
});
|
||||
emitter.emit('helper end');
|
||||
});
|
||||
}
|
||||
|
||||
global.assert = require('chai').assert;
|
||||
global.runFixture = runFixture;
|
||||
global.forkFixture = forkFixture;
|
||||
232
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/reporter.js
Executable file
232
gaia/tests/jsmarionette/mocha/mocha-json-proxy/test/reporter.js
Executable file
|
|
@ -0,0 +1,232 @@
|
|||
/* global runFixture */
|
||||
'use strict';
|
||||
var assert = require('assert');
|
||||
|
||||
suite('reporter', function() {
|
||||
|
||||
function event(input, callback) {
|
||||
var file, type;
|
||||
|
||||
if (typeof input === 'string') {
|
||||
file = type = input;
|
||||
}
|
||||
|
||||
if (typeof input === 'object') {
|
||||
file = input[0];
|
||||
type = input[1];
|
||||
}
|
||||
|
||||
|
||||
return test('event: ' + type, function(done) {
|
||||
runFixture(file, function(err, emit) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
callback(emit, done);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function isTest(input, obj) {
|
||||
assert.ok(input.fn.indexOf('function') !== -1, 'has function');
|
||||
assert.ok(input.title);
|
||||
assert.equal(input.type, 'test');
|
||||
assert.ok(input._slow);
|
||||
assert.ok(input._id, 'has _id');
|
||||
|
||||
if (obj) {
|
||||
for (var key in obj) {
|
||||
assert.equal(input[key], obj[key], key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function aggregateAll(events, emitter) {
|
||||
var result = {};
|
||||
|
||||
function add(event, data, err) {
|
||||
if (err)
|
||||
data.eventErr = err;
|
||||
|
||||
if (!result[data.title]) {
|
||||
result[data.title] = [];
|
||||
}
|
||||
|
||||
result[data.title].push(data);
|
||||
}
|
||||
|
||||
events.forEach(function(event) {
|
||||
emitter.on(event, add.bind(null, event));
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function aggregate(event, emitter) {
|
||||
var result = {};
|
||||
emitter.on(event, function(data, err) {
|
||||
// copy the err property if available.
|
||||
if (err)
|
||||
data.sentErr = err;
|
||||
|
||||
result[data.title] = data;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
function isError(err, msg) {
|
||||
if (msg)
|
||||
assert.ok(err.msg.matches(msg), 'matches msg');
|
||||
|
||||
assert.ok(err.stack, 'err.stack');
|
||||
}
|
||||
|
||||
function testIdsMatch(list) {
|
||||
// usually a test event.
|
||||
var firstEvent = list[list.length - 1];
|
||||
|
||||
// verify the id is valid
|
||||
assert.ok(firstEvent._id, 'has an _id');
|
||||
|
||||
var id = firstEvent._id;
|
||||
|
||||
// verify each id matches the other ids.
|
||||
list.forEach(function(item) {
|
||||
assert.equal(item._id, id);
|
||||
});
|
||||
}
|
||||
|
||||
['test', 'test end'].forEach(function(eventName) {
|
||||
event(['fail', eventName], function(emit, done) {
|
||||
var testEnd = aggregate(eventName, emit);
|
||||
|
||||
emit.on('helper end', function() {
|
||||
assert.ok(!testEnd.sync.err, 'err is not set');
|
||||
assert.ok(!testEnd.async.err, 'err is not set');
|
||||
|
||||
isTest(testEnd.sync);
|
||||
isTest(testEnd.async);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('fail', function() {
|
||||
event('fail', function(emit, done) {
|
||||
var fails = aggregate('fail', emit);
|
||||
|
||||
emit.on('helper end', function() {
|
||||
isTest(fails.sync, { state: 'failed' });
|
||||
isTest(fails.async, { state: 'failed' });
|
||||
|
||||
assert.ok(fails.sync.sentErr, 'sync has err');
|
||||
assert.ok(fails.async.sentErr, 'async has err');
|
||||
|
||||
isError(fails.sync.sentErr);
|
||||
isError(fails.async.sentErr);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
event(['fail', 'ids'], function(emit, done) {
|
||||
var results =
|
||||
aggregateAll(['test', 'test end', 'fail'], emit);
|
||||
|
||||
emit.once('helper end', function() {
|
||||
testIdsMatch(results.sync);
|
||||
testIdsMatch(results.async);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
suite('pass', function() {
|
||||
event('pass', function(emit, done) {
|
||||
var passed = aggregate('pass', emit);
|
||||
|
||||
emit.on('helper end', function() {
|
||||
assert.ok(passed.sync, 'sync test');
|
||||
assert.ok(passed.async, 'async test');
|
||||
|
||||
isTest(passed.sync, { state: 'passed' });
|
||||
isTest(passed.async, { state: 'passed' });
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
event(['pass', 'ids'], function(emit, done) {
|
||||
var results =
|
||||
aggregateAll(['test', 'test end', 'pass'], emit);
|
||||
|
||||
emit.once('helper end', function() {
|
||||
testIdsMatch(results.sync);
|
||||
testIdsMatch(results.async);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('pending', function() {
|
||||
event('pending', function(emit, done) {
|
||||
emit.once('pending', function(data) {
|
||||
assert.equal(data.title, 'mepending', 'title');
|
||||
assert.ok(data.pending, 'pending');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
event(['pending', 'ids'], function(emit, done) {
|
||||
var results =
|
||||
aggregateAll(['test end', 'pending'], emit);
|
||||
|
||||
emit.once('helper end', function() {
|
||||
testIdsMatch(results.mepending);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/* TODO(gaye): Re-enable these...
|
||||
event('start', function(emit, done) {
|
||||
emit.once('start', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
event('end', function(emit, done) {
|
||||
emit.once('end', function(data) {
|
||||
done();
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
event(['suites', 'suite (end)'], function(emit, done) {
|
||||
var events = [];
|
||||
var expected = [
|
||||
['start', '', 1],
|
||||
['start', 'a', 2],
|
||||
['start', 'b', 3],
|
||||
['start', 'c', 4],
|
||||
['end', 'c', 4],
|
||||
['end', 'b', 3],
|
||||
['end', 'a', 2],
|
||||
['end', '', 1]
|
||||
];
|
||||
|
||||
function add(type, data) {
|
||||
events.push([type, data.title, data._id]);
|
||||
}
|
||||
|
||||
emit.on('suite', add.bind(null, 'start'));
|
||||
emit.on('suite end', add.bind(null, 'end'));
|
||||
|
||||
emit.once('helper end', function() {
|
||||
assert.deepEqual(events, expected);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
Reference in a new issue