UNPKG

jira-js-common

Version:

Common helper for writing report to ATM

105 lines (84 loc) 2.77 kB
var Suite = require('./src/suite'), Test = require('./src/test'), Step = require('./src/step'); function Atm() { this.suites = []; } Atm.prototype.getCurrentSuite = function() { return this.suites[0]; }; Atm.prototype.getCurrentTest = function() { return this.getCurrentSuite().currentTest; }; Atm.prototype.startSuite = function(suiteName, timestamp) { this.suites.unshift(new Suite(suiteName, timestamp)); }; Atm.prototype.endSuite = function(timestamp) { var suite = this.getCurrentSuite(); suite.end(timestamp); if(suite.hasTests()) { // writer.writeSuite(this.options.targetDir, suite); console.log('Suite ==============> ' + suite); } this.suites.shift(); }; Atm.prototype.startCase = function(testName, timestamp) { var test = new Test(testName, timestamp), suite = this.getCurrentSuite(); suite.currentTest = test; suite.currentStep = test; suite.addTest(test); }; Atm.prototype.endCase = function(status, err, timestamp) { this.getCurrentTest().end(status, err, timestamp); }; Atm.prototype.startStep = function(stepName, timestamp) { var step = new Step(stepName, timestamp), suite = this.getCurrentSuite(); if (!suite || !suite.currentStep) { console.warn('atm-js-commons: Unexpected startStep() of ' + stepName + '. There is no parent step'); return; } step.parent = suite.currentStep; step.parent.addStep(step); suite.currentStep = step; }; Atm.prototype.endStep = function(status, timestamp) { var suite = this.getCurrentSuite(); if (!suite || !(suite.currentStep instanceof Step)) { console.warn('atm-js-commons: Unexpected endStep(). There are no any steps running'); return; } suite.currentStep.end(status, timestamp); suite.currentStep = suite.currentStep.parent; }; Atm.prototype.setDescription = function(description, type) { this.getCurrentTest().setDescription(description, type); }; Atm.prototype.pendingCase = function(testName, timestamp) { this.startCase(testName, timestamp); this.endCase('pending', {message: 'Test ignored'}, timestamp); }; Atm.prototype.addLabel = function(name, value) { this.getCurrentTest().addLabel(name, value); }; Atm.prototype.SEVERITY = { BLOCKER: 'blocker', CRITICAL: 'critical', NORMAL: 'normal', MINOR: 'minor', TRIVIAL: 'trivial' }; Atm.prototype.severity = function(severity) { this.addLabel('severity', severity); }; Atm.prototype.epic = function(epic) { this.addLabel('epic', epic); }; Atm.prototype.feature = function(feature) { this.addLabel('feature', feature); }; Atm.prototype.story = function(story) { this.addLabel('story', story); }; module.exports = Atm;