wdio-reportportal-reporter
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -54,2 +54,31 @@ "use strict"; | ||
} | ||
static waitLaunchFinished(timeout = 5000) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const launchStatusReq = { | ||
time: ReportPortalReporter.client.helpers.now(), | ||
}; | ||
const url = [ReportPortalReporter.client.baseURL, `launch/${ReportPortalReporter.launchId}`].join("/"); | ||
const headers = { headers: ReportPortalReporter.client.headers }; | ||
const requestFn = ReportPortalReporter.client.helpers.getServerResult; | ||
const isLaunchFinished = () => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const result = yield requestFn(url, launchStatusReq, headers, "GET"); | ||
return !!result.end_time; | ||
} | ||
catch (e) { | ||
return false; | ||
} | ||
}); | ||
const sleep = (ms) => __awaiter(this, void 0, void 0, function* () { return new Promise((resolve) => setTimeout(resolve, ms)); }); | ||
const interval = timeout / 100; | ||
while (timeout > 0) { | ||
if (yield isLaunchFinished()) { | ||
return true; | ||
} | ||
yield sleep(interval); | ||
timeout -= interval; | ||
} | ||
return false; | ||
}); | ||
} | ||
suiteStart(suite) { | ||
@@ -60,3 +89,3 @@ const suiteStartObj = new entities_1.SuiteStartObj(suite.title); | ||
const parent = this.storage.get(suite.cid) || { id: null }; | ||
const { tempId, promise } = this.client.startTestItem(suiteStartObj, this.tempLaunchId, parent.id); | ||
const { tempId, promise } = ReportPortalReporter.client.startTestItem(suiteStartObj, this.tempLaunchId, parent.id); | ||
utils_1.promiseErrorHandler(promise); | ||
@@ -71,3 +100,3 @@ this.storage.add(suite.cid, new entities_1.StorageEntity(constants_1.TYPE.SUITE, tempId, promise, suite)); | ||
} | ||
const { promise } = this.client.finishTestItem(parent.id, finishSuiteObj); | ||
const { promise } = ReportPortalReporter.client.finishTestItem(parent.id, finishSuiteObj); | ||
utils_1.promiseErrorHandler(promise); | ||
@@ -87,3 +116,3 @@ this.storage.clear(suite.cid); | ||
testStartObj.addTagsToTest(this.options.parseTagsFromTestTitle); | ||
const { tempId, promise } = this.client.startTestItem(testStartObj, this.tempLaunchId, parent.id); | ||
const { tempId, promise } = ReportPortalReporter.client.startTestItem(testStartObj, this.tempLaunchId, parent.id); | ||
utils_1.promiseErrorHandler(promise); | ||
@@ -115,3 +144,3 @@ this.storage.add(test.cid, new entities_1.StorageEntity(constants_1.TYPE.STEP, tempId, promise, test)); | ||
finishTestObj.description = `${test.file}\n\`\`\`error\n${message}\n\`\`\``; | ||
this.client.sendLog(parent.id, { | ||
ReportPortalReporter.client.sendLog(parent.id, { | ||
level: constants_1.LEVEL.ERROR, | ||
@@ -121,3 +150,3 @@ message, | ||
} | ||
const { promise } = this.client.finishTestItem(parent.id, finishTestObj); | ||
const { promise } = ReportPortalReporter.client.finishTestItem(parent.id, finishTestObj); | ||
utils_1.promiseErrorHandler(promise); | ||
@@ -128,3 +157,3 @@ this.storage.clear(test.cid); | ||
this.isMultiremote = event.isMultiremote; | ||
this.client = client || new ReportPortalClient(this.options.rpConfig); | ||
ReportPortalReporter.client = client || new ReportPortalClient(this.options.rpConfig); | ||
const startLaunchObj = { | ||
@@ -135,9 +164,12 @@ description: this.options.rpConfig.description, | ||
}; | ||
const { tempId, promise } = this.client.startLaunch(startLaunchObj); | ||
const { tempId, promise } = ReportPortalReporter.client.startLaunch(startLaunchObj); | ||
utils_1.promiseErrorHandler(promise); | ||
this.tempLaunchId = tempId; | ||
promise.then((startLaunchRes) => { | ||
ReportPortalReporter.launchId = startLaunchRes.id; | ||
}); | ||
} | ||
end() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { promise: finishLaunchPromise } = this.client.finishLaunch(this.tempLaunchId, {}); | ||
const { promise: finishLaunchPromise } = ReportPortalReporter.client.finishLaunch(this.tempLaunchId, {}); | ||
utils_1.promiseErrorHandler(finishLaunchPromise); | ||
@@ -214,6 +246,6 @@ yield finishLaunchPromise; | ||
message, | ||
time: this.client.helpers.now(), | ||
time: this.now(), | ||
}; | ||
const url = [this.client.baseURL, "log"].join("/"); | ||
const promise = this.client.helpers.getServerResult(url, saveLogRQ, { headers: this.client.headers }, "POST"); | ||
const url = [ReportPortalReporter.client.baseURL, "log"].join("/"); | ||
const promise = ReportPortalReporter.client.helpers.getServerResult(url, saveLogRQ, { headers: ReportPortalReporter.client.headers }, "POST"); | ||
utils_1.promiseErrorHandler(promise); | ||
@@ -236,5 +268,5 @@ }); | ||
message: "", | ||
time: this.client.helpers.now(), | ||
time: this.now(), | ||
}; | ||
const promise = this.client.getRequestLogWithFile(saveLogRQ, { name, content, type }); | ||
const promise = ReportPortalReporter.client.getRequestLogWithFile(saveLogRQ, { name, content, type }); | ||
utils_1.promiseErrorHandler(promise); | ||
@@ -249,3 +281,3 @@ }); | ||
} | ||
const { promise } = this.client.sendLog(parent.id, { | ||
const { promise } = ReportPortalReporter.client.sendLog(parent.id, { | ||
level, | ||
@@ -262,7 +294,10 @@ message: String(message), | ||
} | ||
const { promise } = this.client.sendLog(parent.id, { level }, { name, content, type }); | ||
const { promise } = ReportPortalReporter.client.sendLog(parent.id, { level }, { name, content, type }); | ||
utils_1.promiseErrorHandler(promise); | ||
} | ||
now() { | ||
return ReportPortalReporter.client.helpers.now(); | ||
} | ||
} | ||
ReportPortalReporter.reporterName = "reportportal"; | ||
module.exports = ReportPortalReporter; |
@@ -8,9 +8,9 @@ import {BaseReporter, getOptions, RPClient} from "./reportportal-client.mock"; | ||
const reporter = new Reporter(new BaseReporter(), {}, getOptions()); | ||
reporter.client = new RPClient(); | ||
Reporter.client = new RPClient(); | ||
reporter.tempLaunchId = "foo"; | ||
reporter.end({}); | ||
expect(reporter.client.finishLaunch).toBeCalledTimes(1); | ||
expect(reporter.client.finishLaunch).toBeCalledWith(reporter.tempLaunchId, {}); | ||
expect(Reporter.client.finishLaunch).toBeCalledTimes(1); | ||
expect(Reporter.client.finishLaunch).toBeCalledWith(reporter.tempLaunchId, {}); | ||
}); | ||
}); |
@@ -15,3 +15,3 @@ import {LEVEL, MODE} from "../constants"; | ||
expect(reporter.tempLaunchId).toEqual("startLaunch"); | ||
expect(reporter.client.startLaunch).toBeCalledTimes(1); | ||
expect(Reporter.client.startLaunch).toBeCalledTimes(1); | ||
@@ -23,3 +23,3 @@ const launchObj = { | ||
}; | ||
expect(reporter.client.startLaunch).toBeCalledWith(launchObj); | ||
expect(Reporter.client.startLaunch).toBeCalledWith(launchObj); | ||
}); | ||
@@ -38,3 +38,3 @@ | ||
expect(reporter.tempLaunchId).toEqual("startLaunch"); | ||
expect(reporter.client.startLaunch).toBeCalledTimes(1); | ||
expect(Reporter.client.startLaunch).toBeCalledTimes(1); | ||
@@ -46,3 +46,3 @@ const launchObj = { | ||
}; | ||
expect(reporter.client.startLaunch).toBeCalledWith(launchObj); | ||
expect(Reporter.client.startLaunch).toBeCalledWith(launchObj); | ||
}); | ||
@@ -49,0 +49,0 @@ }); |
@@ -12,3 +12,3 @@ import {TYPE} from "../constants"; | ||
reporter = new Reporter(new BaseReporter(), {}, getOptions()); | ||
reporter.client = new RPClient(); | ||
Reporter.client = new RPClient(); | ||
reporter.tempLaunchId = "tempLaunchId"; | ||
@@ -20,4 +20,4 @@ }); | ||
expect(reporter.client.startTestItem).toBeCalledTimes(1); | ||
expect(reporter.client.startTestItem).toBeCalledWith( | ||
expect(Reporter.client.startTestItem).toBeCalledTimes(1); | ||
expect(Reporter.client.startTestItem).toBeCalledWith( | ||
{description: "baz", name: "foo", type: TYPE.SUITE}, | ||
@@ -32,4 +32,4 @@ reporter.tempLaunchId, | ||
expect(reporter.client.startTestItem).toBeCalledTimes(1); | ||
expect(reporter.client.startTestItem).toBeCalledWith( | ||
expect(Reporter.client.startTestItem).toBeCalledTimes(1); | ||
expect(Reporter.client.startTestItem).toBeCalledWith( | ||
{description: "baz", name: "foo", type: TYPE.SUITE, tags: ["bar"]}, | ||
@@ -44,4 +44,4 @@ reporter.tempLaunchId, | ||
expect(reporter.client.startTestItem).toBeCalledTimes(1); | ||
expect(reporter.client.startTestItem).toBeCalledWith( | ||
expect(Reporter.client.startTestItem).toBeCalledTimes(1); | ||
expect(Reporter.client.startTestItem).toBeCalledWith( | ||
{name: "foo", type: TYPE.SUITE}, | ||
@@ -57,4 +57,4 @@ reporter.tempLaunchId, | ||
expect(reporter.client.startTestItem).toBeCalledTimes(2); | ||
expect(reporter.client.startTestItem).toHaveBeenNthCalledWith( | ||
expect(Reporter.client.startTestItem).toBeCalledTimes(2); | ||
expect(Reporter.client.startTestItem).toHaveBeenNthCalledWith( | ||
1, | ||
@@ -67,3 +67,3 @@ {description: "baz", name: "foo", type: TYPE.SUITE}, | ||
const {id} = reporter.storage.get(suiteStartEvent().cid); | ||
expect(reporter.client.startTestItem).toHaveBeenNthCalledWith( | ||
expect(Reporter.client.startTestItem).toHaveBeenNthCalledWith( | ||
2, | ||
@@ -70,0 +70,0 @@ {description: "baz", name: "foo", type: TYPE.SUITE}, |
@@ -20,2 +20,4 @@ import {EventEmitter} from "events"; | ||
public static reporterName = "reportportal"; | ||
public static launchId; | ||
public static client: ReportPortalClient; | ||
@@ -37,2 +39,34 @@ public static sendLog(level: LEVEL, message: any) { | ||
} | ||
public static async waitLaunchFinished(timeout = 5000) { | ||
const launchStatusReq = { | ||
time: ReportPortalReporter.client.helpers.now(), | ||
}; | ||
const url = [ReportPortalReporter.client.baseURL, `launch/${ReportPortalReporter.launchId}`].join("/"); | ||
const headers = {headers: ReportPortalReporter.client.headers}; | ||
const requestFn = ReportPortalReporter.client.helpers.getServerResult; | ||
const isLaunchFinished = async () => { | ||
try { | ||
const result = await requestFn(url, launchStatusReq, headers, "GET"); | ||
return !!result.end_time; | ||
} catch (e) { | ||
return false; | ||
} | ||
}; | ||
const sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | ||
const interval = timeout / 100; | ||
while (timeout > 0) { | ||
if (await isLaunchFinished()) { | ||
return true; | ||
} | ||
await sleep(interval); | ||
timeout -= interval; | ||
} | ||
return false; | ||
} | ||
public client: ReportPortalClient; | ||
public storage = new Storage(); | ||
@@ -42,3 +76,2 @@ public logger: Logger; | ||
public options: ReporterOptions; | ||
public client: ReportPortalClient; | ||
public baseReporter: any; | ||
@@ -79,3 +112,3 @@ public isMultiremote: boolean; | ||
const parent = this.storage.get(suite.cid) || {id: null}; | ||
const { tempId, promise } = this.client.startTestItem( | ||
const { tempId, promise } = ReportPortalReporter.client.startTestItem( | ||
suiteStartObj, | ||
@@ -96,3 +129,3 @@ this.tempLaunchId, | ||
} | ||
const { promise } = this.client.finishTestItem(parent.id, finishSuiteObj); | ||
const { promise } = ReportPortalReporter.client.finishTestItem(parent.id, finishSuiteObj); | ||
promiseErrorHandler(promise); | ||
@@ -114,3 +147,3 @@ this.storage.clear(suite.cid); | ||
const { tempId, promise } = this.client.startTestItem( | ||
const { tempId, promise } = ReportPortalReporter.client.startTestItem( | ||
testStartObj, | ||
@@ -152,3 +185,3 @@ this.tempLaunchId, | ||
finishTestObj.description = `${test.file}\n\`\`\`error\n${message}\n\`\`\``; | ||
this.client.sendLog(parent.id, { | ||
ReportPortalReporter.client.sendLog(parent.id, { | ||
level: LEVEL.ERROR, | ||
@@ -159,3 +192,3 @@ message, | ||
const { promise } = this.client.finishTestItem(parent.id, finishTestObj); | ||
const { promise } = ReportPortalReporter.client.finishTestItem(parent.id, finishTestObj); | ||
promiseErrorHandler(promise); | ||
@@ -168,3 +201,3 @@ | ||
this.isMultiremote = event.isMultiremote; | ||
this.client = client || new ReportPortalClient(this.options.rpConfig); | ||
ReportPortalReporter.client = client || new ReportPortalClient(this.options.rpConfig); | ||
const startLaunchObj = { | ||
@@ -175,9 +208,12 @@ description: this.options.rpConfig.description, | ||
}; | ||
const { tempId, promise } = this.client.startLaunch(startLaunchObj); | ||
const { tempId, promise } = ReportPortalReporter.client.startLaunch(startLaunchObj); | ||
promiseErrorHandler(promise); | ||
this.tempLaunchId = tempId; | ||
promise.then((startLaunchRes) => { | ||
ReportPortalReporter.launchId = startLaunchRes.id; | ||
}); | ||
} | ||
public async end() { | ||
const { promise: finishLaunchPromise } = this.client.finishLaunch(this.tempLaunchId, {}); | ||
const { promise: finishLaunchPromise } = ReportPortalReporter.client.finishLaunch(this.tempLaunchId, {}); | ||
promiseErrorHandler(finishLaunchPromise); | ||
@@ -263,7 +299,7 @@ await finishLaunchPromise; | ||
message, | ||
time: this.client.helpers.now(), | ||
time: this.now(), | ||
}; | ||
const url = [this.client.baseURL, "log"].join("/"); | ||
const promise = this.client.helpers.getServerResult(url, saveLogRQ, { headers: this.client.headers }, "POST"); | ||
const url = [ReportPortalReporter.client.baseURL, "log"].join("/"); | ||
const promise = ReportPortalReporter.client.helpers.getServerResult(url, saveLogRQ, { headers: ReportPortalReporter.client.headers }, "POST"); | ||
promiseErrorHandler(promise); | ||
@@ -286,6 +322,6 @@ } | ||
message: "", | ||
time: this.client.helpers.now(), | ||
time: this.now(), | ||
}; | ||
const promise = this.client.getRequestLogWithFile(saveLogRQ, { name, content, type }); | ||
const promise = ReportPortalReporter.client.getRequestLogWithFile(saveLogRQ, { name, content, type }); | ||
promiseErrorHandler(promise); | ||
@@ -300,3 +336,3 @@ } | ||
} | ||
const { promise } = this.client.sendLog(parent.id, { | ||
const { promise } = ReportPortalReporter.client.sendLog(parent.id, { | ||
level, | ||
@@ -315,8 +351,12 @@ message: String(message), | ||
const { promise } = this.client.sendLog(parent.id, { level }, { name, content, type }); | ||
const { promise } = ReportPortalReporter.client.sendLog(parent.id, { level }, { name, content, type }); | ||
promiseErrorHandler(promise); | ||
} | ||
private now() { | ||
return ReportPortalReporter.client.helpers.now(); | ||
} | ||
} | ||
export = ReportPortalReporter; |
{ | ||
"name": "wdio-reportportal-reporter", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"description": "A WebdriverIO plugin. Report results to Report Portal.", | ||
@@ -41,16 +41,16 @@ "main": "build/reporter.js", | ||
"devDependencies": { | ||
"@types/jest": "^23.3.9", | ||
"@types/jest": "^23.3.12", | ||
"jest": "^23.6.0", | ||
"ts-jest": "^23.10.4", | ||
"ts-jest": "^23.10.5", | ||
"@types/chai": "4.1.7", | ||
"@types/cucumber": "^4.0.4", | ||
"@types/mocha": "5.2.5", | ||
"@types/webdriverio": "^4.13.0", | ||
"@types/webdriverio": "^4.13.1", | ||
"chai": "^4.1.2", | ||
"mocha": "^5.2.0", | ||
"npm-run-all": "~4.1.3", | ||
"rimraf": "^2.6.2", | ||
"npm-run-all": "~4.1.5", | ||
"rimraf": "^2.6.3", | ||
"wdio-cucumber-framework": "^2.2.8", | ||
"wdio-mocha-framework": "^0.6.3", | ||
"webdriverio": "^4.14.0", | ||
"webdriverio": "^4.14.2", | ||
"ts-node": "7.0.1", | ||
@@ -57,0 +57,0 @@ "tslint": "^5.11.0", |
@@ -15,3 +15,3 @@ WDIO Report Portal Reporter | ||
"devDependencies": { | ||
"wdio-reportportal-reporter": "~0.0.19" | ||
"wdio-reportportal-reporter": "~0.0.21" | ||
} | ||
@@ -42,3 +42,2 @@ } | ||
debug: false, | ||
debug: false, | ||
description: "Launch description text", | ||
@@ -45,0 +44,0 @@ tags: ["tags", "for", "launch"], |
@@ -39,3 +39,3 @@ const reporter = require('../../../build/reporter'); | ||
timeout: 20000, | ||
require: ['tests/fixtures/features/steps/passing-steps.js', 'tests/fixtures/features/steps/hooks.js'], | ||
require: ['test/fixtures/features/steps/passing-steps.js', 'test/fixtures/features/steps/hooks.js'], | ||
compiler: [ | ||
@@ -56,3 +56,7 @@ 'js:babel-register', | ||
onComplete: async function onComplete() { | ||
return new Promise(resolve => setTimeout(resolve, 5000)); | ||
const isLaunchFinished = await reporter.waitLaunchFinished(); | ||
if(!isLaunchFinished) { | ||
console.warn('Launch has not been finished'); | ||
} | ||
console.log('Launch finished'); | ||
}, | ||
@@ -59,0 +63,0 @@ |
68009
1604
104