wdio-reportportal-reporter
Advanced tools
Comparing version 0.0.18 to 0.0.19
@@ -13,3 +13,5 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
const entities_1 = require("./entities"); | ||
const ReporterOptions_1 = require("./ReporterOptions"); | ||
const storage_1 = require("./storage"); | ||
const utils_1 = require("./utils"); | ||
@@ -19,7 +21,5 @@ class ReportPortalReporter extends events_1.EventEmitter { | ||
super(); | ||
this.parents = {}; | ||
this.startedTests = {}; | ||
this.storage = new storage_1.Storage(); | ||
this.baseReporter = baseReporter; | ||
this.logger = new utils_1.Logger(options.debug); | ||
this.config = config; | ||
this.options = Object.assign(new ReporterOptions_1.default(), options); | ||
@@ -56,43 +56,15 @@ // Test framework events | ||
} | ||
getParent(cid) { | ||
const parents = this.getParentIds(cid); | ||
if (!parents.length) { | ||
return null; | ||
} | ||
return parents[parents.length - 1]; | ||
} | ||
addParent(cid, parent) { | ||
const parents = this.getParentIds(cid); | ||
parents.push(parent); | ||
} | ||
clearParent(cid) { | ||
const parents = this.getParentIds(cid); | ||
parents.pop(); | ||
} | ||
suiteStart(suite) { | ||
const suiteStartObj = new SuiteStartObj(suite.title); | ||
if (suite.tags && suite.tags.length > 0) { | ||
// check is it at least cucumber v1 | ||
if (suite.tags[0].name) { | ||
suiteStartObj.tags = suite.tags.map((tag) => tag.name); | ||
} | ||
else { | ||
suiteStartObj.tags = suite.tags; | ||
} | ||
} | ||
if (suite.description) { | ||
suiteStartObj.description = suite.description; | ||
} | ||
const parent = this.getParent(suite.cid) || {}; | ||
const suiteStartObj = new entities_1.SuiteStartObj(suite.title); | ||
utils_1.addTagsToSuite(suite.tags, suiteStartObj); | ||
utils_1.addDescription(suite.description, suiteStartObj); | ||
const parent = this.storage.get(suite.cid) || { id: null }; | ||
const { tempId, promise } = this.client.startTestItem(suiteStartObj, this.tempLaunchId, parent.id); | ||
utils_1.promiseErrorHandler(promise); | ||
this.addParent(suite.cid, { type: constants_1.TYPE.SUITE, id: tempId, promise }); | ||
if (!this.startedTests[suite.cid]) { | ||
this.startedTests[suite.cid] = []; | ||
} | ||
this.storage.add(suite.cid, new entities_1.StorageEntity(constants_1.TYPE.SUITE, tempId, promise, suite)); | ||
} | ||
suiteEnd(suite) { | ||
const parent = this.getParent(suite.cid); | ||
const parent = this.storage.get(suite.cid); | ||
const finishSuiteObj = { status: constants_1.STATUS.PASSED }; | ||
if (this.startedTests[suite.cid].length === 0) { | ||
if (this.storage.getStartedTests(suite.cid).length === 0) { | ||
finishSuiteObj.status = constants_1.STATUS.FAILED; | ||
@@ -102,3 +74,3 @@ } | ||
utils_1.promiseErrorHandler(promise); | ||
this.clearParent(suite.cid); | ||
this.storage.clear(suite.cid); | ||
} | ||
@@ -109,22 +81,12 @@ testStart(test) { | ||
} | ||
const parent = this.getParent(test.cid); | ||
const parent = this.storage.get(test.cid); | ||
if (parent.type === constants_1.TYPE.STEP && this.options.enableRetriesWorkaround) { | ||
return; | ||
} | ||
const testStartObj = new TestStartObj(test.title); | ||
const browser = test.runner[test.cid].browserName; | ||
if (browser) { | ||
const param = { key: "browser", value: browser }; | ||
testStartObj.parameters = [param]; | ||
} | ||
if (this.options.parseTagsFromTestTitle) { | ||
const tags = utils_1.parseTags(test.title); | ||
if (tags.length > 0) { | ||
testStartObj.tags = tags; | ||
} | ||
} | ||
const testStartObj = new entities_1.TestStartObj(test.title); | ||
utils_1.addBrowserParam(test.runner[test.cid].browserName, testStartObj); | ||
testStartObj.addTagsToTest(this.options.parseTagsFromTestTitle); | ||
const { tempId, promise } = this.client.startTestItem(testStartObj, this.tempLaunchId, parent.id); | ||
utils_1.promiseErrorHandler(promise); | ||
this.addParent(test.cid, { type: constants_1.TYPE.STEP, id: tempId, promise }); | ||
this.startedTests[test.cid].push({ test, promise }); | ||
this.storage.add(test.cid, new entities_1.StorageEntity(constants_1.TYPE.STEP, tempId, promise, test)); | ||
return promise; | ||
@@ -139,17 +101,16 @@ } | ||
testPending(test) { | ||
const parent = this.getParent(test.cid); | ||
const parent = this.storage.get(test.cid); | ||
if (parent && parent.type === constants_1.TYPE.SUITE) { | ||
this.testStart(test); | ||
} | ||
this.testFinished(test, constants_1.STATUS.SKIPPED, new Issue("NOT_ISSUE")); | ||
this.testFinished(test, constants_1.STATUS.SKIPPED, new entities_1.Issue("NOT_ISSUE")); | ||
} | ||
testFinished(test, status, issue) { | ||
const parent = this.getParent(test.cid); | ||
const parent = this.storage.get(test.cid); | ||
if (parent && parent.type !== constants_1.TYPE.STEP) { | ||
return; | ||
} | ||
const finishTestObj = new TestEndObj(status, issue); | ||
const finishTestObj = new entities_1.TestEndObj(status, issue); | ||
if (status === constants_1.STATUS.FAILED) { | ||
let message = `Message: ${test.err.message}\n`; | ||
message += `Stacktrace: ${test.err.stack}\n`; | ||
const message = `${test.err.stack} `; | ||
finishTestObj.description = `${test.file}\n\`\`\`error\n${message}\n\`\`\``; | ||
@@ -163,4 +124,24 @@ this.client.sendLog(parent.id, { | ||
utils_1.promiseErrorHandler(promise); | ||
this.clearParent(test.cid); | ||
this.storage.clear(test.cid); | ||
} | ||
start(event, client) { | ||
this.isMultiremote = event.isMultiremote; | ||
this.client = client || new ReportPortalClient(this.options.rpConfig); | ||
const startLaunchObj = { | ||
description: this.options.rpConfig.description, | ||
mode: this.options.rpConfig.mode, | ||
tags: this.options.rpConfig.tags, | ||
}; | ||
const { tempId, promise } = this.client.startLaunch(startLaunchObj); | ||
utils_1.promiseErrorHandler(promise); | ||
this.tempLaunchId = tempId; | ||
} | ||
end() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { promise: finishLaunchPromise } = this.client.finishLaunch(this.tempLaunchId, {}); | ||
utils_1.promiseErrorHandler(finishLaunchPromise); | ||
yield finishLaunchPromise; | ||
this.baseReporter.epilogue.call(this.baseReporter); | ||
}); | ||
} | ||
runnerCommand(command) { | ||
@@ -170,3 +151,3 @@ if (!this.options.enableSeleniumCommandReporting || this.isMultiremote) { | ||
} | ||
const parent = this.getParent(command.cid); | ||
const parent = this.storage.get(command.cid); | ||
if (!parent) { | ||
@@ -184,17 +165,2 @@ return; | ||
} | ||
start(event, client) { | ||
this.isMultiremote = event.isMultiremote; | ||
this.client = client || new ReportPortalClient(this.options.rpConfig); | ||
const { tempId, promise } = this.client.startLaunch({ mode: this.options.rpConfig.mode }); | ||
utils_1.promiseErrorHandler(promise); | ||
this.tempLaunchId = tempId; | ||
} | ||
end() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { promise: finishLaunchPromise } = this.client.finishLaunch(this.tempLaunchId, {}); | ||
utils_1.promiseErrorHandler(finishLaunchPromise); | ||
yield finishLaunchPromise; | ||
this.baseReporter.epilogue.call(this.baseReporter); | ||
}); | ||
} | ||
runnerResult(command) { | ||
@@ -204,3 +170,3 @@ if (this.isMultiremote) { | ||
} | ||
const parent = this.getParent(command.cid); | ||
const parent = this.storage.get(command.cid); | ||
if (!parent) { | ||
@@ -232,3 +198,3 @@ return; | ||
const clear = (cid) => { | ||
delete this.startedTests[cid]; | ||
this.storage.clearStartedTests(cid); | ||
}; | ||
@@ -239,10 +205,10 @@ setTimeout(clear.bind(this), 5000, runner.cid); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const failedTest = this.startedTests[cid].slice().reverse().find(({ test: startedTest }) => { | ||
return startedTest.title === test.title; | ||
const testObj = this.storage.getStartedTests(cid).reverse().find((startedTest) => { | ||
return startedTest.wdioEntity.title === test.title; | ||
}); | ||
if (!failedTest) { | ||
if (!testObj) { | ||
this.logger.warn(`Can not send log to test ${test.title}`); | ||
return; | ||
} | ||
const rs = yield failedTest.promise; | ||
const rs = yield testObj.promise; | ||
const saveLogRQ = { | ||
@@ -261,10 +227,10 @@ item_id: rs.id, | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const failedTest = this.startedTests[cid].slice().reverse().find(({ test: startedTest }) => { | ||
return startedTest.title === test.title; | ||
const testObj = this.storage.getStartedTests(cid).reverse().find((startedTest) => { | ||
return startedTest.wdioEntity.title === test.title; | ||
}); | ||
if (!failedTest) { | ||
if (!testObj) { | ||
this.logger.warn(`Can not send file to test ${test.title}`); | ||
return; | ||
} | ||
const rs = yield failedTest.promise; | ||
const rs = yield testObj.promise; | ||
const saveLogRQ = { | ||
@@ -281,3 +247,3 @@ item_id: rs.id, | ||
sendLog({ cid, level, message }) { | ||
const parent = this.getParent(cid); | ||
const parent = this.storage.get(cid); | ||
if (!parent) { | ||
@@ -294,3 +260,3 @@ this.logger.warn(`Can not send log to test. There is no running tests`); | ||
sendFile({ cid, level, name, content, type = "image/png" }) { | ||
const parent = this.getParent(cid); | ||
const parent = this.storage.get(cid); | ||
if (!parent) { | ||
@@ -303,39 +269,4 @@ this.logger.warn(`Can not send file to test. There is no running tests`); | ||
} | ||
getParentIds(cid) { | ||
if (this.parents[cid]) { | ||
return this.parents[cid]; | ||
} | ||
this.parents[cid] = []; | ||
return this.parents[cid]; | ||
} | ||
} | ||
ReportPortalReporter.reporterName = "reportportal"; | ||
class SuiteStartObj { | ||
constructor(name) { | ||
this.name = ""; | ||
this.type = constants_1.TYPE.SUITE; | ||
this.name = name; | ||
} | ||
} | ||
class TestStartObj { | ||
constructor(name) { | ||
this.name = ""; | ||
this.type = constants_1.TYPE.STEP; | ||
this.name = name; | ||
} | ||
} | ||
class TestEndObj { | ||
constructor(status, issue) { | ||
this.status = status; | ||
if (issue) { | ||
this.issue = issue; | ||
} | ||
} | ||
} | ||
class Issue { | ||
// tslint:disable-next-line | ||
constructor(issue_type) { | ||
this.issue_type = issue_type; | ||
} | ||
} | ||
module.exports = ReportPortalReporter; |
@@ -13,5 +13,5 @@ "use strict"; | ||
this.seleniumCommandsLogLevel = constants_1.LEVEL.DEBUG; | ||
this.rpConfig = { mode: constants_1.MODE.DEFAULT }; | ||
this.rpConfig = { mode: constants_1.MODE.DEFAULT, tags: [], description: "" }; | ||
} | ||
} | ||
exports.default = ReporterOptions; |
@@ -101,5 +101,26 @@ "use strict"; | ||
}; | ||
exports.parseTags = (text) => text.match(TAGS_PATTERN) || []; | ||
exports.addTagsToSuite = (tags, suiteStartObj) => { | ||
if (tags && tags.length > 0) { | ||
if (tags[0].name) { | ||
suiteStartObj.tags = tags.map((tag) => tag.name); | ||
} | ||
else { | ||
suiteStartObj.tags = tags; | ||
} | ||
} | ||
}; | ||
exports.addBrowserParam = (browser, testStartObj) => { | ||
if (browser) { | ||
const param = { key: "browser", value: browser }; | ||
testStartObj.parameters = [param]; | ||
} | ||
}; | ||
exports.addDescription = (description, suiteStartObj) => { | ||
if (description) { | ||
suiteStartObj.description = description; | ||
} | ||
}; | ||
exports.parseTags = (text) => ("" + text).match(TAGS_PATTERN) || []; | ||
exports.sendToReporter = (event, msg = {}) => { | ||
process.send(Object.assign({ event }, msg)); | ||
}; |
@@ -13,3 +13,2 @@ import {LEVEL} from "../constants"; | ||
expect(reporter.baseReporter).toEqual(baseReporter); | ||
expect(reporter.config).toEqual(config); | ||
expect(reporter.options).toEqual(options); | ||
@@ -16,0 +15,0 @@ }); |
@@ -10,3 +10,3 @@ import ReporterOptions from "../ReporterOptions"; | ||
public startLaunch = jest.fn().mockReturnValue({ | ||
promise: new Promise((resolve) => resolve("ok")), | ||
promise: Promise.resolve("ok"), | ||
tempId: "startLaunch", | ||
@@ -16,3 +16,3 @@ }); | ||
public finishLaunch = jest.fn().mockReturnValue( { | ||
promise: new Promise((resolve) => resolve("ok")), | ||
promise: Promise.resolve("ok"), | ||
tempId: "finishLaunch", | ||
@@ -22,3 +22,3 @@ }); | ||
public startTestItem = jest.fn().mockReturnValue({ | ||
promise: new Promise((resolve) => resolve("ok")), | ||
promise: Promise.resolve("ok"), | ||
tempId: "startTestItem", | ||
@@ -28,3 +28,3 @@ }); | ||
public finishTestItem = jest.fn().mockReturnValue({ | ||
promise: new Promise((resolve) => resolve("ok")), | ||
promise: Promise.resolve("ok"), | ||
tempId: "finishTestItem", | ||
@@ -34,3 +34,3 @@ }); | ||
public sendLog = jest.fn().mockReturnValue({ | ||
promise: new Promise((resolve) => resolve("ok")), | ||
promise: Promise.resolve("ok"), | ||
tempId: "sendLog", | ||
@@ -37,0 +37,0 @@ }); |
@@ -16,8 +16,16 @@ import {LEVEL, MODE} from "../constants"; | ||
expect(reporter.client.startLaunch).toBeCalledTimes(1); | ||
expect(reporter.client.startLaunch).toBeCalledWith({mode: options.rpConfig.mode}); | ||
const launchObj = { | ||
description: options.rpConfig.description, | ||
mode: options.rpConfig.mode, | ||
tags: options.rpConfig.tags, | ||
}; | ||
expect(reporter.client.startLaunch).toBeCalledWith(launchObj); | ||
}); | ||
test("should startLaunch with debug", () => { | ||
test("should startLaunch with custom parameters", () => { | ||
const options = getOptions(); | ||
options.rpConfig.mode = MODE.DEBUG; | ||
options.rpConfig.tags = ["foo"]; | ||
options.rpConfig.description = "bar"; | ||
const reporter = new Reporter(new BaseReporter(), {}, options); | ||
@@ -30,3 +38,9 @@ const client = new RPClient(); | ||
expect(reporter.client.startLaunch).toBeCalledTimes(1); | ||
expect(reporter.client.startLaunch).toBeCalledWith({mode: options.rpConfig.mode}); | ||
const launchObj = { | ||
description: options.rpConfig.description, | ||
mode: options.rpConfig.mode, | ||
tags: options.rpConfig.tags, | ||
}; | ||
expect(reporter.client.startLaunch).toBeCalledWith(launchObj); | ||
}); | ||
@@ -42,3 +56,2 @@ }); | ||
expect(reporter.baseReporter).toEqual(baseReporter); | ||
expect(reporter.config).toEqual(config); | ||
expect(reporter.options).toEqual(options); | ||
@@ -45,0 +58,0 @@ }); |
@@ -23,17 +23,6 @@ import {TYPE} from "../constants"; | ||
reporter.tempLaunchId, | ||
undefined, | ||
null, | ||
); | ||
}); | ||
test("should not tags startSuite", () => { | ||
reporter.suiteStart(Object.assign(suiteStartEvent(), {tags: []})); | ||
expect(reporter.client.startTestItem).toBeCalledTimes(1); | ||
expect(reporter.client.startTestItem).toBeCalledWith( | ||
{description: "baz", name: "foo", type: TYPE.SUITE}, | ||
reporter.tempLaunchId, | ||
undefined, | ||
); | ||
}); | ||
test("should add tags startSuite", () => { | ||
@@ -46,17 +35,6 @@ reporter.suiteStart(Object.assign(suiteStartEvent(), {tags: [{name: "bar"}]})); | ||
reporter.tempLaunchId, | ||
undefined, | ||
null, | ||
); | ||
}); | ||
test("should add tags startSuite", () => { | ||
reporter.suiteStart(Object.assign(suiteStartEvent(), {tags: ["bar", "baz"]})); | ||
expect(reporter.client.startTestItem).toBeCalledTimes(1); | ||
expect(reporter.client.startTestItem).toBeCalledWith( | ||
{description: "baz", name: "foo", type: TYPE.SUITE, tags: ["bar", "baz"]}, | ||
reporter.tempLaunchId, | ||
undefined, | ||
); | ||
}); | ||
test("should omit description if empty", () => { | ||
@@ -69,3 +47,3 @@ reporter.suiteStart(Object.assign(suiteStartEvent(), {description: undefined})); | ||
reporter.tempLaunchId, | ||
undefined, | ||
null, | ||
); | ||
@@ -83,6 +61,6 @@ }); | ||
reporter.tempLaunchId, | ||
undefined, | ||
null, | ||
); | ||
const {id} = reporter.getParent(suiteStartEvent().cid); | ||
const {id} = reporter.storage.get(suiteStartEvent().cid); | ||
expect(reporter.client.startTestItem).toHaveBeenNthCalledWith( | ||
@@ -97,26 +75,1 @@ 2, | ||
}); | ||
// public suiteStart(suite) { | ||
// const suiteStartObj = new SuiteStartObj(suite.title); | ||
// if (suite.tags && suite.tags.length > 0) { | ||
// // check is it at least cucumber v1 | ||
// if (suite.tags[0].name) { | ||
// suiteStartObj.tags = suite.tags.map((tag) => tag.name); | ||
// } else { | ||
// suiteStartObj.tags = suite.tags; | ||
// } | ||
// } | ||
// | ||
// if (suite.description) { | ||
// suiteStartObj.description = suite.description; | ||
// } | ||
// const parent = this.getParent(suite.cid) || {}; | ||
// | ||
// const { tempId, promise } = this.client.startTestItem( | ||
// suiteStartObj, | ||
// this.tempLaunchId, | ||
// parent.id, | ||
// ); | ||
// promiseErrorHandler(promise); | ||
// this.addParent(suite.cid, { type: TYPE.SUITE, id: tempId, promise }); | ||
// } |
@@ -1,6 +0,17 @@ | ||
import { EventEmitter } from "events"; | ||
import {EventEmitter} from "events"; | ||
import * as ReportPortalClient from "reportportal-client"; | ||
import {EVENTS, LEVEL, STATUS, TYPE} from "./constants"; | ||
import {Issue, StorageEntity, SuiteStartObj, TestEndObj, TestStartObj} from "./entities"; | ||
import ReporterOptions from "./ReporterOptions"; | ||
import { isEmpty, limit, Logger, parseTags, promiseErrorHandler, sendToReporter } from "./utils"; | ||
import {Storage} from "./storage"; | ||
import { | ||
addBrowserParam, | ||
addDescription, | ||
addTagsToSuite, | ||
isEmpty, | ||
limit, | ||
Logger, | ||
promiseErrorHandler, | ||
sendToReporter, | ||
} from "./utils"; | ||
@@ -10,22 +21,20 @@ class ReportPortalReporter extends EventEmitter { | ||
public static sendLog(level, message) { | ||
public static sendLog(level: LEVEL, message: any) { | ||
sendToReporter(EVENTS.RP_LOG, { level, message }); | ||
} | ||
public static sendFile(level, name, content, type = "image/png") { | ||
public static sendFile(level: LEVEL, name: string, content: any, type = "image/png") { | ||
sendToReporter(EVENTS.RP_FILE, { level, name, content, type }); | ||
} | ||
public static sendLogToTest(test, level, message) { | ||
public static sendLogToTest(test: any, level: LEVEL, message: any) { | ||
sendToReporter(EVENTS.RP_TEST_LOG, { test, level, message }); | ||
} | ||
public static sendFileToTest(test, level, name, content, type = "image/png") { | ||
public static sendFileToTest(test: any, level: LEVEL, name: string, content: any, type = "image/png") { | ||
sendToReporter(EVENTS.RP_TEST_FILE, { test, level, name, content, type }); | ||
} | ||
public parents = {}; | ||
public storage = new Storage(); | ||
public logger: Logger; | ||
public startedTests = {}; | ||
public tempLaunchId: string; | ||
public config: object; | ||
public options: ReporterOptions; | ||
@@ -40,3 +49,2 @@ public client: ReportPortalClient; | ||
this.logger = new Logger(options.debug); | ||
this.config = config; | ||
this.options = Object.assign(new ReporterOptions(), options); | ||
@@ -65,36 +73,7 @@ | ||
public getParent(cid: string) { | ||
const parents = this.getParentIds(cid); | ||
if (!parents.length) { | ||
return null; | ||
} | ||
return parents[parents.length - 1]; | ||
} | ||
public addParent(cid: string, parent) { | ||
const parents = this.getParentIds(cid); | ||
parents.push(parent); | ||
} | ||
public clearParent(cid: string) { | ||
const parents = this.getParentIds(cid); | ||
parents.pop(); | ||
} | ||
public suiteStart(suite) { | ||
public suiteStart(suite: any) { | ||
const suiteStartObj = new SuiteStartObj(suite.title); | ||
if (suite.tags && suite.tags.length > 0) { | ||
// check is it at least cucumber v1 | ||
if (suite.tags[0].name) { | ||
suiteStartObj.tags = suite.tags.map((tag) => tag.name); | ||
} else { | ||
suiteStartObj.tags = suite.tags; | ||
} | ||
} | ||
if (suite.description) { | ||
suiteStartObj.description = suite.description; | ||
} | ||
const parent = this.getParent(suite.cid) || {}; | ||
addTagsToSuite(suite.tags, suiteStartObj); | ||
addDescription(suite.description, suiteStartObj); | ||
const parent = this.storage.get(suite.cid) || {id: null}; | ||
const { tempId, promise } = this.client.startTestItem( | ||
@@ -106,12 +85,10 @@ suiteStartObj, | ||
promiseErrorHandler(promise); | ||
this.addParent(suite.cid, { type: TYPE.SUITE, id: tempId, promise }); | ||
if (!this.startedTests[suite.cid]) { | ||
this.startedTests[suite.cid] = []; | ||
} | ||
this.storage.add(suite.cid, new StorageEntity(TYPE.SUITE, tempId, promise, suite)); | ||
} | ||
public suiteEnd(suite) { | ||
const parent = this.getParent(suite.cid); | ||
public suiteEnd(suite: any) { | ||
const parent = this.storage.get(suite.cid); | ||
const finishSuiteObj = {status: STATUS.PASSED}; | ||
if (this.startedTests[suite.cid].length === 0) { | ||
if (this.storage.getStartedTests(suite.cid).length === 0) { | ||
finishSuiteObj.status = STATUS.FAILED; | ||
@@ -121,10 +98,10 @@ } | ||
promiseErrorHandler(promise); | ||
this.clearParent(suite.cid); | ||
this.storage.clear(suite.cid); | ||
} | ||
public testStart(test) { | ||
public testStart(test: any) { | ||
if (!test.title) { | ||
return; | ||
} | ||
const parent = this.getParent(test.cid); | ||
const parent = this.storage.get(test.cid); | ||
if (parent.type === TYPE.STEP && this.options.enableRetriesWorkaround) { | ||
@@ -134,16 +111,5 @@ return; | ||
const testStartObj = new TestStartObj(test.title); | ||
addBrowserParam(test.runner[test.cid].browserName, testStartObj); | ||
testStartObj.addTagsToTest(this.options.parseTagsFromTestTitle); | ||
const browser = test.runner[test.cid].browserName; | ||
if (browser) { | ||
const param = { key: "browser", value: browser }; | ||
testStartObj.parameters = [param]; | ||
} | ||
if (this.options.parseTagsFromTestTitle) { | ||
const tags = parseTags(test.title); | ||
if (tags.length > 0) { | ||
testStartObj.tags = tags; | ||
} | ||
} | ||
const { tempId, promise } = this.client.startTestItem( | ||
@@ -156,17 +122,16 @@ testStartObj, | ||
this.addParent(test.cid, { type: TYPE.STEP, id: tempId, promise }); | ||
this.startedTests[test.cid].push({test, promise}); | ||
this.storage.add(test.cid, new StorageEntity(TYPE.STEP, tempId, promise, test)); | ||
return promise; | ||
} | ||
public testPass(test) { | ||
public testPass(test: any) { | ||
this.testFinished(test, STATUS.PASSED); | ||
} | ||
public testFail(test) { | ||
public testFail(test: any) { | ||
this.testFinished(test, STATUS.FAILED); | ||
} | ||
public testPending(test) { | ||
const parent = this.getParent(test.cid); | ||
public testPending(test: any) { | ||
const parent = this.storage.get(test.cid); | ||
if (parent && parent.type === TYPE.SUITE) { | ||
@@ -178,4 +143,4 @@ this.testStart(test); | ||
public testFinished(test, status, issue?) { | ||
const parent = this.getParent(test.cid); | ||
public testFinished(test: any, status: STATUS, issue?: Issue) { | ||
const parent = this.storage.get(test.cid); | ||
if (parent && parent.type !== TYPE.STEP) { | ||
@@ -187,4 +152,3 @@ return; | ||
if (status === STATUS.FAILED) { | ||
let message = `Message: ${test.err.message}\n`; | ||
message += `Stacktrace: ${test.err.stack}\n`; | ||
const message = `${test.err.stack} `; | ||
finishTestObj.description = `${test.file}\n\`\`\`error\n${message}\n\`\`\``; | ||
@@ -200,6 +164,26 @@ this.client.sendLog(parent.id, { | ||
this.clearParent(test.cid); | ||
this.storage.clear(test.cid); | ||
} | ||
public runnerCommand(command) { | ||
public start(event: any, client: ReportPortalClient) { | ||
this.isMultiremote = event.isMultiremote; | ||
this.client = client || new ReportPortalClient(this.options.rpConfig); | ||
const startLaunchObj = { | ||
description: this.options.rpConfig.description, | ||
mode: this.options.rpConfig.mode, | ||
tags: this.options.rpConfig.tags, | ||
}; | ||
const { tempId, promise } = this.client.startLaunch(startLaunchObj); | ||
promiseErrorHandler(promise); | ||
this.tempLaunchId = tempId; | ||
} | ||
public async end() { | ||
const { promise: finishLaunchPromise } = this.client.finishLaunch(this.tempLaunchId, {}); | ||
promiseErrorHandler(finishLaunchPromise); | ||
await finishLaunchPromise; | ||
this.baseReporter.epilogue.call(this.baseReporter); | ||
} | ||
public runnerCommand(command: any) { | ||
if (!this.options.enableSeleniumCommandReporting || this.isMultiremote) { | ||
@@ -209,3 +193,3 @@ return; | ||
const parent = this.getParent(command.cid); | ||
const parent = this.storage.get(command.cid); | ||
if (!parent) { | ||
@@ -224,18 +208,3 @@ return; | ||
public start(event, client) { | ||
this.isMultiremote = event.isMultiremote; | ||
this.client = client || new ReportPortalClient(this.options.rpConfig); | ||
const { tempId, promise } = this.client.startLaunch({ mode: this.options.rpConfig.mode }); | ||
promiseErrorHandler(promise); | ||
this.tempLaunchId = tempId; | ||
} | ||
public async end() { | ||
const { promise: finishLaunchPromise } = this.client.finishLaunch(this.tempLaunchId, {}); | ||
promiseErrorHandler(finishLaunchPromise); | ||
await finishLaunchPromise; | ||
this.baseReporter.epilogue.call(this.baseReporter); | ||
} | ||
public runnerResult(command) { | ||
public runnerResult(command: any) { | ||
if (this.isMultiremote) { | ||
@@ -245,3 +214,3 @@ return; | ||
const parent = this.getParent(command.cid); | ||
const parent = this.storage.get(command.cid); | ||
if (!parent) { | ||
@@ -275,5 +244,5 @@ return; | ||
public runnerEnd(runner) { | ||
const clear = (cid) => { | ||
delete this.startedTests[cid]; | ||
public runnerEnd(runner: any) { | ||
const clear = (cid: string) => { | ||
this.storage.clearStartedTests(cid); | ||
}; | ||
@@ -284,10 +253,11 @@ setTimeout(clear.bind(this), 5000, runner.cid); | ||
public async sendLogToTest({ cid, test, level, message }) { | ||
const failedTest = this.startedTests[cid].slice().reverse().find(({test: startedTest}) => { | ||
return startedTest.title === test.title; | ||
const testObj = this.storage.getStartedTests(cid).reverse().find((startedTest) => { | ||
return startedTest.wdioEntity.title === test.title; | ||
}); | ||
if (!failedTest) { | ||
if (!testObj) { | ||
this.logger.warn(`Can not send log to test ${test.title}`); | ||
return; | ||
} | ||
const rs = await failedTest.promise; | ||
const rs = await testObj.promise; | ||
@@ -307,10 +277,10 @@ const saveLogRQ = { | ||
public async sendFileToTest({ cid, test, level, name, content, type = "image/png" }) { | ||
const failedTest = this.startedTests[cid].slice().reverse().find(({test: startedTest}) => { | ||
return startedTest.title === test.title; | ||
const testObj = this.storage.getStartedTests(cid).reverse().find((startedTest) => { | ||
return startedTest.wdioEntity.title === test.title; | ||
}); | ||
if (!failedTest) { | ||
if (!testObj) { | ||
this.logger.warn(`Can not send file to test ${test.title}`); | ||
return; | ||
} | ||
const rs = await failedTest.promise; | ||
const rs = await testObj.promise; | ||
@@ -329,3 +299,3 @@ const saveLogRQ = { | ||
public sendLog({ cid, level, message }) { | ||
const parent = this.getParent(cid); | ||
const parent = this.storage.get(cid); | ||
if (!parent) { | ||
@@ -343,3 +313,3 @@ this.logger.warn(`Can not send log to test. There is no running tests`); | ||
public sendFile({ cid, level, name, content, type = "image/png" }) { | ||
const parent = this.getParent(cid); | ||
const parent = this.storage.get(cid); | ||
if (!parent) { | ||
@@ -354,55 +324,4 @@ this.logger.warn(`Can not send file to test. There is no running tests`); | ||
public getParentIds(cid) { | ||
if (this.parents[cid]) { | ||
return this.parents[cid]; | ||
} | ||
this.parents[cid] = []; | ||
return this.parents[cid]; | ||
} | ||
} | ||
class SuiteStartObj { | ||
public name = ""; | ||
public description?: string; | ||
public tags?: string[]; | ||
private readonly type = TYPE.SUITE; | ||
constructor(name: string) { | ||
this.name = name; | ||
} | ||
} | ||
class TestStartObj { | ||
public name = ""; | ||
public parameters?: any[]; | ||
public tags?: any[]; | ||
private readonly type = TYPE.STEP; | ||
constructor(name: string) { | ||
this.name = name; | ||
} | ||
} | ||
class TestEndObj { | ||
public status: STATUS; | ||
public issue?: Issue; | ||
public description?: string; | ||
constructor(status: STATUS, issue: Issue) { | ||
this.status = status; | ||
if (issue) { | ||
this.issue = issue; | ||
} | ||
} | ||
} | ||
class Issue { | ||
// tslint:disable-next-line | ||
public issue_type: string; | ||
// tslint:disable-next-line | ||
constructor(issue_type) { | ||
this.issue_type = issue_type; | ||
} | ||
} | ||
export = ReportPortalReporter; |
@@ -11,3 +11,3 @@ import {LEVEL, MODE} from "./constants"; | ||
public seleniumCommandsLogLevel = LEVEL.DEBUG; | ||
public rpConfig = {mode: MODE.DEFAULT}; | ||
public rpConfig = {mode: MODE.DEFAULT, tags: [], description: ""}; | ||
} |
@@ -110,6 +110,29 @@ const stringify = require("json-stringify-safe"); | ||
export const parseTags = (text: string): string[] => text.match(TAGS_PATTERN) || []; | ||
export const addTagsToSuite = (tags, suiteStartObj) => { | ||
if (tags && tags.length > 0) { | ||
if (tags[0].name) { | ||
suiteStartObj.tags = tags.map((tag) => tag.name); | ||
} else { | ||
suiteStartObj.tags = tags; | ||
} | ||
} | ||
}; | ||
export const addBrowserParam = (browser, testStartObj) => { | ||
if (browser) { | ||
const param = {key: "browser", value: browser}; | ||
testStartObj.parameters = [param]; | ||
} | ||
}; | ||
export const addDescription = (description, suiteStartObj) => { | ||
if (description) { | ||
suiteStartObj.description = description; | ||
} | ||
}; | ||
export const parseTags = (text: string): string[] => ("" + text).match(TAGS_PATTERN) || []; | ||
export const sendToReporter = (event: any, msg = {}) => { | ||
process.send({ event, ...msg }); | ||
}; |
{ | ||
"name": "wdio-reportportal-reporter", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"description": "A WebdriverIO plugin. Report results to Report Portal.", | ||
@@ -5,0 +5,0 @@ "main": "build/reporter.js", |
@@ -15,3 +15,3 @@ WDIO Report Portal Reporter | ||
"devDependencies": { | ||
"wdio-reportportal-reporter": "~0.0.16" | ||
"wdio-reportportal-reporter": "~0.0.19" | ||
} | ||
@@ -49,3 +49,5 @@ } | ||
parseTagsFromTestTitle: false, | ||
debug: false | ||
debug: false, | ||
description: "Launch description text", | ||
tags: ["tags", "for", "launch"], | ||
} | ||
@@ -52,0 +54,0 @@ }, |
Sorry, the diff of this file is not supported yet
65523
42
1547
105