1 var fs = require('fs');
3 /* Note: because this plugin uses process.on('uncaughtException'), only one
4 * of these can exist at any given time. This plugin and anything else that
5 * uses process.on('uncaughtException') will conflict. */
6 exports.attachToRunner = function(runner, outputFile) {
7 var smokeOutput = { results : [] };
11 beforeTest: function(test, callback) {
12 test.startTime = Date.now();
13 runningTests[test.name] = test;
16 afterTest: function(test, callback) {
17 smokeOutput.results.push({
19 start: test.startTime,
25 delete runningTests[test.name];
28 beforeExit: function(obj, callback) {
29 fs.writeFile(outputFile, JSON.stringify(smokeOutput), function() {
35 // In case of exception, make sure we write file
36 process.on('uncaughtException', function(err) {
37 // Mark all currently running tests as failed
38 for (var testName in runningTests) {
39 smokeOutput.results.push({
41 start: runningTests[testName].startTime,
50 fs.writeFileSync(outputFile, JSON.stringify(smokeOutput));
52 // Standard NodeJS uncaught exception handler
53 console.error(err.stack);
57 runner.plugin(integraPlugin);