Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smoke_plugin.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 'use strict';
  2. 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: [] };
  8. var runningTests = {};
  9. var integraPlugin = {
  10. beforeTest: function(test, callback) {
  11. test.startTime = Date.now();
  12. runningTests[test.name] = test;
  13. callback();
  14. },
  15. afterTest: function(test, callback) {
  16. smokeOutput.results.push({
  17. status: test.status,
  18. start: test.startTime,
  19. end: Date.now(),
  20. test_file: test.name,
  21. exit_code: 0,
  22. url: ''
  23. });
  24. delete runningTests[test.name];
  25. callback();
  26. },
  27. beforeExit: function(obj, callback) {
  28. fs.writeFile(outputFile, JSON.stringify(smokeOutput), function() {
  29. callback();
  30. });
  31. }
  32. };
  33. // In case of exception, make sure we write file
  34. process.on('uncaughtException', function(err) {
  35. // Mark all currently running tests as failed
  36. for (var testName in runningTests) {
  37. smokeOutput.results.push({
  38. status: 'fail',
  39. start: runningTests[testName].startTime,
  40. end: Date.now(),
  41. test_file: testName,
  42. exit_code: 0,
  43. url: ''
  44. });
  45. }
  46. // write file
  47. fs.writeFileSync(outputFile, JSON.stringify(smokeOutput));
  48. // Standard NodeJS uncaught exception handler
  49. console.error(err.stack);
  50. process.exit(1);
  51. });
  52. runner.plugin(integraPlugin);
  53. return integraPlugin;
  54. };