@comeonautomation/reportportal-client
Advanced tools
Comparing version
const ua = require('universal-analytics'); | ||
const { PJSON_VERSION, PJSON_NAME, GOOGLE_ANALYTICS_INSTANCE } = require('./constants'); | ||
const { | ||
PJSON_VERSION, | ||
PJSON_NAME, | ||
GOOGLE_ANALYTICS_INSTANCE | ||
} = require('./constants'); | ||
@@ -15,3 +19,4 @@ class Analytics { | ||
trackEvent(event) { | ||
this.visitorInstance.event(event.category, event.action).send(); | ||
this.visitorInstance.event(event.category, event.action) | ||
.send(); | ||
} | ||
@@ -18,0 +23,0 @@ } |
@@ -7,2 +7,6 @@ const pjson = require('./../package.json'); | ||
module.exports = { PJSON_VERSION, PJSON_NAME, GOOGLE_ANALYTICS_INSTANCE }; | ||
module.exports = { | ||
PJSON_VERSION, | ||
PJSON_NAME, | ||
GOOGLE_ANALYTICS_INSTANCE | ||
}; |
@@ -1,2 +0,5 @@ | ||
const { PJSON_VERSION, PJSON_NAME } = require('./constants'); | ||
const { | ||
PJSON_VERSION, | ||
PJSON_NAME | ||
} = require('./constants'); | ||
@@ -3,0 +6,0 @@ const CLIENT_JAVASCRIPT = `Client name "${PJSON_NAME}", version "${PJSON_VERSION}"`; |
@@ -0,0 +0,0 @@ # Report Portal client-javascript example |
@@ -11,8 +11,9 @@ /* eslint-disable no-console */ | ||
rpClient.checkConnect().then((response) => { | ||
console.log('You have successfully connected to the server.'); | ||
console.log(`You are using an account: ${response.fullName}`); | ||
}, (error) => { | ||
console.log('Error connection to server'); | ||
console.dir(error); | ||
}); | ||
rpClient.checkConnect() | ||
.then((response) => { | ||
console.log('You have successfully connected to the server.'); | ||
console.log(`You are using an account: ${response.fullName}`); | ||
}, (error) => { | ||
console.log('Error connection to server'); | ||
console.dir(error); | ||
}); |
@@ -0,0 +0,0 @@ const fs = require('fs'); |
/* eslint-disable quotes,no-console,class-methods-use-this */ | ||
const UniqId = require("uniqid"); | ||
const helpers = require("./helpers"); | ||
const RestClient = require("./rest"); | ||
const Analytics = require("../analytics/analytics"); | ||
const { CLIENT_JAVASCRIPT_EVENTS } = require("./../analytics/events"); | ||
const UniqId = require('uniqid'); | ||
const helpers = require('./helpers'); | ||
const RestClient = require('./rest'); | ||
const Analytics = require('../analytics/analytics'); | ||
const { CLIENT_JAVASCRIPT_EVENTS } = require('./../analytics/events'); | ||
const MULTIPART_BOUNDARY = Math.floor(Math.random() * 10000000000).toString(); | ||
const MULTIPART_BOUNDARY = Math.floor(Math.random() * 10000000000) | ||
.toString(); | ||
@@ -29,6 +30,6 @@ class RPClient { | ||
this.map = {}; | ||
this.baseURL = [params.endpoint, params.project].join("/"); | ||
this.baseURL = [params.endpoint, params.project].join('/'); | ||
this.options = { | ||
headers: { | ||
"User-Agent": "NodeJS", | ||
'User-Agent': 'NodeJS', | ||
Authorization: `bearer ${params.token}` | ||
@@ -38,3 +39,3 @@ } | ||
this.headers = { | ||
"User-Agent": "NodeJS", | ||
'User-Agent': 'NodeJS', | ||
Authorization: `bearer ${params.token}` | ||
@@ -51,3 +52,3 @@ }; | ||
this.analytics.setPersistentParams(); | ||
this.launchUuid = ""; | ||
this.launchUuid = ''; | ||
} | ||
@@ -82,3 +83,3 @@ | ||
promiseStart: new Promise(startPromiseFunc), | ||
realId: "", | ||
realId: '', | ||
childrens: [], | ||
@@ -108,6 +109,6 @@ finishSend: false, | ||
checkConnect() { | ||
const url = [this.config.endpoint.replace("/v2", "/v1"), "user"].join( | ||
"/" | ||
const url = [this.config.endpoint.replace('/v2', '/v1'), 'user'].join( | ||
'/' | ||
); | ||
return RestClient.request("GET", url, {}, { headers: this.headers }); | ||
return RestClient.request('GET', url, {}, { headers: this.headers }); | ||
} | ||
@@ -157,3 +158,3 @@ | ||
{ | ||
name: this.config.launch || "Test launch name", | ||
name: this.config.launch || 'Test launch name', | ||
startTime: this.helpers.now() | ||
@@ -165,3 +166,3 @@ }, | ||
this.map[tempId] = this.getNewItemObj((resolve, reject) => { | ||
const url = "launch"; | ||
const url = 'launch'; | ||
this.logDebug(`Start launch ${tempId}`); | ||
@@ -235,39 +236,40 @@ this.restClient | ||
launchObj.childrens.map(itemId => this.map[itemId].promiseFinish) | ||
).then( | ||
() => { | ||
launchObj.promiseStart.then( | ||
() => { | ||
this.logDebug(`Finish launch ${launchTempId}`); | ||
const url = ["launch", launchObj.realId, "finish"].join( | ||
"/" | ||
); | ||
this.restClient | ||
.update(url, finishExecutionData, { | ||
headers: this.headers | ||
}) | ||
.then( | ||
response => { | ||
this.logDebug( | ||
`Success finish launch ${launchTempId}` | ||
); | ||
launchObj.resolveFinish(response); | ||
}, | ||
error => { | ||
this.logDebug( | ||
`Error finish launch ${launchTempId}` | ||
); | ||
console.dir(error); | ||
launchObj.rejectFinish(error); | ||
} | ||
) | ||
.then( | ||
() => { | ||
launchObj.promiseStart.then( | ||
() => { | ||
this.logDebug(`Finish launch ${launchTempId}`); | ||
const url = ['launch', launchObj.realId, 'finish'].join( | ||
'/' | ||
); | ||
}, | ||
error => { | ||
launchObj.rejectFinish(error); | ||
} | ||
); | ||
}, | ||
error => { | ||
launchObj.rejectFinish(error); | ||
} | ||
); | ||
this.restClient | ||
.update(url, finishExecutionData, { | ||
headers: this.headers | ||
}) | ||
.then( | ||
response => { | ||
this.logDebug( | ||
`Success finish launch ${launchTempId}` | ||
); | ||
launchObj.resolveFinish(response); | ||
}, | ||
error => { | ||
this.logDebug( | ||
`Error finish launch ${launchTempId}` | ||
); | ||
console.dir(error); | ||
launchObj.rejectFinish(error); | ||
} | ||
); | ||
}, | ||
error => { | ||
launchObj.rejectFinish(error); | ||
} | ||
); | ||
}, | ||
error => { | ||
launchObj.rejectFinish(error); | ||
} | ||
); | ||
@@ -280,3 +282,3 @@ return { | ||
/* | ||
/* | ||
* This method is used for force stop launches in ReportPortal. | ||
@@ -289,4 +291,4 @@ * | ||
if (this.isLaunchMergeRequired) { | ||
const statusUrl = ["launch", "status"].join("/"); | ||
const stopUrl = ["launch", "stop"].join("/"); | ||
const statusUrl = ['launch', 'status'].join('/'); | ||
const stopUrl = ['launch', 'stop'].join('/'); | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
@@ -299,3 +301,3 @@ | ||
for (let item in response) { | ||
response[item] === "IN_PROGRESS" && arr.push(item); | ||
response[item] === 'IN_PROGRESS' && arr.push(item); | ||
} | ||
@@ -307,3 +309,3 @@ const data = {}; | ||
endTime: this.helpers.now(), | ||
status: "STOPPED" | ||
status: 'STOPPED' | ||
}) | ||
@@ -317,3 +319,3 @@ ); | ||
) | ||
.then(async response => { | ||
.then(async (response) => { | ||
this.logDebug(`Launches successfully stopped!`); | ||
@@ -326,3 +328,3 @@ await this.deleteSkippedInterruptedTest() | ||
await this.deleteEmptyExecutionLaunch(); | ||
}) | ||
}); | ||
}); | ||
@@ -335,74 +337,72 @@ }); | ||
isLaunchWithFailedTests(launchTempId) { | ||
const launchObj = this.map[launchTempId]; | ||
isLaunchWithFailedTests(launchTempId) { | ||
const launchObj = this.map[launchTempId]; | ||
const launch_latest_url = '/launch/latest?filter.eq.uuid=' + launchObj.realId; | ||
const launch_latest_url = "/launch/latest?filter.eq.uuid="+launchObj.realId; | ||
return this.restClient | ||
.retrieve(launch_latest_url) | ||
.then(response => { | ||
this.logDebug('Launch ID'+response.content[0].id) | ||
const url = "/launch?filter.eq.id="+response.content[0].id+"&filter.eq.statistics%24executions%24failed=0"; | ||
return this.restClient | ||
.retrieve(url) | ||
.retrieve(launch_latest_url) | ||
.then(response => { | ||
this.logDebug (`Failed test elements: `+response.page.totalElements); | ||
if (response.page.totalElements == 0){ | ||
this.logDebug(`There is failed items`); | ||
return false; | ||
} | ||
return true; | ||
this.logDebug('Launch ID' + response.content[0].id); | ||
const url = '/launch?filter.eq.id=' + response.content[0].id + '&filter.eq.statistics%24executions%24failed=0'; | ||
return this.restClient | ||
.retrieve(url) | ||
.then(response => { | ||
this.logDebug(`Failed test elements: ` + response.page.totalElements); | ||
if (response.page.totalElements == 0) { | ||
this.logDebug(`There is failed items`); | ||
return false; | ||
} | ||
return true; | ||
}); | ||
}); | ||
}); | ||
//this.logDebug (`There is no failed`); | ||
} | ||
async deleteSkippedInterruptedTest() { | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
const hasSkipTestItems = []; | ||
//this.logDebug (`There is no failed`); | ||
for (let item in launchIds) { | ||
await this.restClient | ||
.retrieve("/item?filter.eq.launchId="+launchIds[item]+"&page.size=100") | ||
.then(async response => { | ||
this.logDebug (`Total elements in ${launchIds[item]}: `+response.page.totalElements); | ||
for (var i=0;i<response.page.totalElements;i++){ | ||
this.logDebug('Test ID: '+response.content[i].id+' '+response.content[i].name+' Skipped:'+response.content[i].statistics.executions.skipped) | ||
const item_id_url='/item/uuid/'+response.content[i].id | ||
if ( | ||
(response.content[i].statistics.executions | ||
.skipped === 1 | ||
&& response.content[i].hasChildren === false) | ||
|| (response.content[i].statistics.executions.total | ||
=== response.content[i].statistics.executions | ||
.skipped) | ||
|| (response.content[i].status === 'INTERRUPTED' | ||
&& response.content[i].hasChildren === false) | ||
){ | ||
this.restClient | ||
.retrieve(item_id_url) | ||
.then(response => { | ||
hasSkipTestItems.push(response.id) | ||
this.restClient | ||
.delete("/item?ids="+response.id) | ||
.then(response => { | ||
this.logDebug('Deleted Skipped & Interrupted tests successfully'); | ||
}); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
async deleteEmptyExecutionTest() { | ||
async deleteSkippedInterruptedTest() { | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
const hasSkipTestItems = []; | ||
for (let item in launchIds) { | ||
await this.restClient | ||
.retrieve('/item?filter.eq.launchId=' + launchIds[item] + '&page.size=100') | ||
.then(async (response) => { | ||
this.logDebug(`Total elements in ${launchIds[item]}: ` + response.page.totalElements); | ||
for (var i = 0; i < response.page.totalElements; i++) { | ||
this.logDebug('Test ID: ' + response.content[i].id + ' ' + response.content[i].name + ' Skipped:' + response.content[i].statistics.executions.skipped); | ||
const item_id_url = '/item/uuid/' + response.content[i].id; | ||
if ( | ||
(response.content[i].statistics.executions.skipped === 1 | ||
&& response.content[i].hasChildren === false) | ||
|| (response.content[i].statistics.executions.total | ||
=== response.content[i].statistics.executions | ||
.skipped) | ||
|| (response.content[i].status === 'INTERRUPTED' | ||
&& response.content[i].hasChildren === false) | ||
) { | ||
await this.restClient | ||
.retrieve(item_id_url) | ||
.then(async (response) => { | ||
hasSkipTestItems.push(response.id); | ||
await this.restClient | ||
.delete('/item?ids=' + response.id) | ||
.then((response) => { | ||
this.logDebug('Deleted Skipped & Interrupted tests successfully'); | ||
}); | ||
}); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
async deleteEmptyExecutionTest() { | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
for (let item in launchIds) { | ||
await this.restClient | ||
.retrieve( | ||
"/item?filter.eq.launchId=" + launchIds[item] + "&page.size=100", | ||
'/item?filter.eq.launchId=' + launchIds[item] + '&page.size=100', | ||
) | ||
@@ -412,8 +412,8 @@ .then(response => { | ||
const item_id_url = '/item/uuid/' + response.content[i].id; | ||
this.restClient | ||
this.restClient | ||
.retrieve(item_id_url) | ||
.then(response => { | ||
if (Object.values(response.statistics.executions).length === 0) { | ||
this.restClient | ||
.delete("/item?ids=" + response.id) | ||
this.restClient | ||
.delete('/item?ids=' + response.id) | ||
.then(() => { | ||
@@ -423,26 +423,26 @@ this.logDebug('Deleted test have empty executions'); | ||
} | ||
}) | ||
}); | ||
} | ||
}) | ||
}); | ||
} | ||
} | ||
async deleteEmptyExecutionLaunch() { | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
for (let item in launchIds) { | ||
await this.restClient | ||
.retrieve("/item?filter.eq.launchId=" + launchIds[item] + "&page.size=100",) | ||
.then(async (response) => { | ||
if (response.page.totalElements === 0) { | ||
await this.restClient | ||
.delete("/launch/" + launchIds[item]) | ||
.then(() => { | ||
this.logDebug('Deleted launch have empty executions'); | ||
}); | ||
} | ||
}) | ||
} | ||
} | ||
async deleteEmptyExecutionLaunch() { | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
for (let item in launchIds) { | ||
await this.restClient | ||
.retrieve('/item?filter.eq.launchId=' + launchIds[item] + '&page.size=100',) | ||
.then(async (response) => { | ||
if (response.page.totalElements === 0) { | ||
await this.restClient | ||
.delete('/launch/' + launchIds[item]) | ||
.then(() => { | ||
this.logDebug('Deleted launch have empty executions'); | ||
}); | ||
} | ||
}); | ||
} | ||
} | ||
/* | ||
@@ -459,5 +459,5 @@ * This method is used to create data object for merge request to ReportPortal. | ||
launches: launchIds, | ||
mergeType: "BASIC", | ||
mode: "DEFAULT", | ||
name: this.config.launch || "Test launch name", | ||
mergeType: 'BASIC', | ||
mode: 'DEFAULT', | ||
name: this.config.launch || 'Test launch name', | ||
attributes: this.config.attributes | ||
@@ -475,23 +475,21 @@ }; | ||
if (this.isLaunchMergeRequired) { | ||
const url = ["launch", "merge"].join("/"); | ||
const url = ['launch', 'merge'].join('/'); | ||
const launchIds = helpers.readLaunchesFromFile(); | ||
const activeLaunches = [] | ||
for (let items in launchIds) | ||
{ | ||
const activeLaunches = []; | ||
for (let items in launchIds) { | ||
await this.restClient | ||
.retrieve('/launch/status?ids='+launchIds[items]) | ||
.then(response => { | ||
if (response.hasOwnProperty(launchIds[items])) | ||
{ | ||
activeLaunches.push(launchIds[items]) | ||
} | ||
}) | ||
.retrieve('/launch/status?ids=' + launchIds[items]) | ||
.then(response => { | ||
if (response.hasOwnProperty(launchIds[items])) { | ||
activeLaunches.push(launchIds[items]); | ||
} | ||
}); | ||
} | ||
const data = this.getMergeLaunchesData(activeLaunches, mergeDescription); | ||
this.restClient | ||
.create(url, data, { headers: this.headers }) | ||
.then(() => { | ||
this.logDebug(`Launches successfully merged!`); | ||
}); | ||
.create(url, data, { headers: this.headers }) | ||
.then(() => { | ||
this.logDebug(`Launches successfully merged!`); | ||
}); | ||
@@ -503,4 +501,2 @@ } else { | ||
/* | ||
@@ -557,3 +553,3 @@ * This method is used for frameworks as Jasmine. There is problem when | ||
() => { | ||
const url = ["launch", launchObj.realId, "update"].join("/"); | ||
const url = ['launch', launchObj.realId, 'update'].join('/'); | ||
this.restClient | ||
@@ -646,3 +642,3 @@ .update(url, launchData, { headers: this.headers }) | ||
const realLaunchId = this.map[launchTempId].realId; | ||
let url = "item/"; | ||
let url = 'item/'; | ||
if (parentTempId) { | ||
@@ -732,3 +728,3 @@ const realParentId = this.map[parentTempId].realId; | ||
endTime: this.helpers.now(), | ||
status: "passed" | ||
status: 'passed' | ||
}, | ||
@@ -741,28 +737,29 @@ finishTestItemRQ | ||
itemObj.childrens.map(itemId => this.map[itemId].promiseFinish) | ||
).then( | ||
() => { | ||
this.cleanMap(itemObj.childrens); | ||
this.finishTestItemPromiseStart( | ||
itemObj, | ||
itemTempId, | ||
Object.assign(finishTestItemData, { | ||
launchUuid: this.launchUuid | ||
}) | ||
); | ||
}, | ||
() => { | ||
this.cleanMap(itemObj.childrens); | ||
this.logDebug( | ||
`Error finish children of test item ${itemTempId}` | ||
); | ||
this.logDebug(`Finish test item ${itemTempId}`); | ||
this.finishTestItemPromiseStart( | ||
itemObj, | ||
itemTempId, | ||
Object.assign(finishTestItemData, { | ||
launchUuid: this.launchUuid | ||
}) | ||
); | ||
} | ||
); | ||
) | ||
.then( | ||
() => { | ||
this.cleanMap(itemObj.childrens); | ||
this.finishTestItemPromiseStart( | ||
itemObj, | ||
itemTempId, | ||
Object.assign(finishTestItemData, { | ||
launchUuid: this.launchUuid | ||
}) | ||
); | ||
}, | ||
() => { | ||
this.cleanMap(itemObj.childrens); | ||
this.logDebug( | ||
`Error finish children of test item ${itemTempId}` | ||
); | ||
this.logDebug(`Finish test item ${itemTempId}`); | ||
this.finishTestItemPromiseStart( | ||
itemObj, | ||
itemTempId, | ||
Object.assign(finishTestItemData, { | ||
launchUuid: this.launchUuid | ||
}) | ||
); | ||
} | ||
); | ||
@@ -781,12 +778,13 @@ return { | ||
this.logDebug(`Save log ${tempId}`); | ||
requestPromiseFunc(itemObj.realId, this.launchUuid).then( | ||
response => { | ||
this.logDebug(`Successfully save log ${tempId}`); | ||
resolve(response); | ||
}, | ||
error => { | ||
this.logDebug(`Error finish log: ${error}`); | ||
reject(error); | ||
} | ||
); | ||
requestPromiseFunc(itemObj.realId, this.launchUuid) | ||
.then( | ||
response => { | ||
this.logDebug(`Successfully save log ${tempId}`); | ||
resolve(response); | ||
}, | ||
error => { | ||
this.logDebug(`Error finish log: ${error}`); | ||
reject(error); | ||
} | ||
); | ||
}, | ||
@@ -817,4 +815,4 @@ error => { | ||
time: this.helpers.now(), | ||
message: "", | ||
level: "" | ||
message: '', | ||
level: '' | ||
}, | ||
@@ -852,7 +850,10 @@ saveLogRQ | ||
const requestPromise = (itemUuid, launchUuid) => { | ||
const url = "log"; | ||
const url = 'log'; | ||
// eslint-disable-next-line max-len | ||
return this.restClient.create( | ||
url, | ||
Object.assign(saveLogRQ, { itemUuid, launchUuid }), | ||
Object.assign(saveLogRQ, { | ||
itemUuid, | ||
launchUuid | ||
}), | ||
{ headers: this.headers } | ||
@@ -896,3 +897,6 @@ ); | ||
this.getRequestLogWithFile( | ||
Object.assign(saveLogRQ, { itemUuid, launchUuid }), | ||
Object.assign(saveLogRQ, { | ||
itemUuid, | ||
launchUuid | ||
}), | ||
fileObj | ||
@@ -905,3 +909,3 @@ ); | ||
getRequestLogWithFile(saveLogRQ, fileObj) { | ||
const url = "log"; | ||
const url = 'log'; | ||
// eslint-disable-next-line no-param-reassign | ||
@@ -920,3 +924,3 @@ saveLogRQ.file = { name: fileObj.name }; | ||
Authorization: `bearer ${this.token}`, | ||
"Content-Type": `multipart/form-data; boundary=${MULTIPART_BOUNDARY}` | ||
'Content-Type': `multipart/form-data; boundary=${MULTIPART_BOUNDARY}` | ||
} | ||
@@ -927,3 +931,3 @@ } | ||
.catch(error => { | ||
this.logDebug("ERROR"); | ||
this.logDebug('ERROR'); | ||
this.logDebug(error); | ||
@@ -939,3 +943,3 @@ }); | ||
buildMultiPartStream(jsonPart, filePart, boundary) { | ||
const eol = "\r\n"; | ||
const eol = '\r\n'; | ||
const bx = `--${boundary}`; | ||
@@ -947,11 +951,11 @@ const buffers = [ | ||
bx + | ||
eol + | ||
'Content-Disposition: form-data; name="json_request_part"' + | ||
eol + | ||
"Content-Type: application/json" + | ||
eol + | ||
eol + | ||
eol + | ||
JSON.stringify(jsonPart) + | ||
eol | ||
eol + | ||
'Content-Disposition: form-data; name="json_request_part"' + | ||
eol + | ||
'Content-Type: application/json' + | ||
eol + | ||
eol + | ||
eol + | ||
JSON.stringify(jsonPart) + | ||
eol | ||
), | ||
@@ -962,13 +966,13 @@ // eslint-disable-next-line function-paren-newline | ||
bx + | ||
eol + | ||
'Content-Disposition: form-data; name="file"; filename="' + | ||
filePart.name + | ||
'"' + | ||
eol + | ||
"Content-Type: " + | ||
filePart.type + | ||
eol + | ||
eol | ||
eol + | ||
'Content-Disposition: form-data; name="file"; filename="' + | ||
filePart.name + | ||
'"' + | ||
eol + | ||
'Content-Type: ' + | ||
filePart.type + | ||
eol + | ||
eol | ||
), | ||
Buffer.from(filePart.content, "base64"), | ||
Buffer.from(filePart.content, 'base64'), | ||
Buffer.from(`${eol + bx}--${eol}`) | ||
@@ -982,3 +986,3 @@ ]; | ||
() => { | ||
const url = ["item", itemObj.realId].join("/"); | ||
const url = ['item', itemObj.realId].join('/'); | ||
this.logDebug(`Finish test item ${itemTempId}`); | ||
@@ -985,0 +989,0 @@ // eslint-disable-next-line max-len |
const axios = require('axios'); | ||
const axiosRetry = require('axios-retry'); | ||
axiosRetry(axios, { retryDelay: () => 100, retries: 10, retryCondition: axiosRetry.isRetryableError }); | ||
axiosRetry(axios, { | ||
retryDelay: () => 100, | ||
retries: 10, | ||
retryCondition: axiosRetry.isRetryableError | ||
}); | ||
@@ -6,0 +10,0 @@ class RestClient { |
@@ -0,0 +0,0 @@ Apache License |
{ | ||
"name": "@comeonautomation/reportportal-client", | ||
"version": "2.3.6", | ||
"version": "2.3.7", | ||
"description": "ReportPortal client for node.js", | ||
@@ -31,2 +31,3 @@ "contributors": [ | ||
"glob": "^7.1.4", | ||
"prettier": "^2.6.2", | ||
"uniqid": "^5.0.3", | ||
@@ -33,0 +34,0 @@ "universal-analytics": "^0.4.20" |
@@ -0,0 +0,0 @@ [](https://travis-ci.org/reportportal/client-javascript)[](https://codecov.io/gh/reportportal/client-javascript)[](https://badge.fury.io/js/reportportal-client) |
@@ -9,12 +9,16 @@ const RPClient = require('../lib/report-portal-client.js'); | ||
it('slice last 256 symbols', () => { | ||
expect(client.helpers.formatName(`a${'b'.repeat(256)}`)).toBe('b'.repeat(256)); | ||
expect(client.helpers.formatName(`a${'b'.repeat(256)}`)) | ||
.toBe('b'.repeat(256)); | ||
}); | ||
it('leave 256 symbol name as is', () => { | ||
expect(client.helpers.formatName('c'.repeat(256))).toBe('c'.repeat(256)); | ||
expect(client.helpers.formatName('c'.repeat(256))) | ||
.toBe('c'.repeat(256)); | ||
}); | ||
it('leave 3 symbol name as is', () => { | ||
expect(client.helpers.formatName('abc')).toBe('abc'); | ||
expect(client.helpers.formatName('abc')) | ||
.toBe('abc'); | ||
}); | ||
it('complete with dots 2 symbol name', () => { | ||
expect(client.helpers.formatName('ab')).toBe('ab.'); | ||
expect(client.helpers.formatName('ab')) | ||
.toBe('ab.'); | ||
}); | ||
@@ -25,3 +29,4 @@ }); | ||
it('returns milliseconds from unix time', () => { | ||
expect(new Date() - client.helpers.now()).toBeLessThan(100); // less than 100 miliseconds difference | ||
expect(new Date() - client.helpers.now()) | ||
.toBeLessThan(100); // less than 100 miliseconds difference | ||
}); | ||
@@ -45,14 +50,15 @@ }); | ||
expect(RestClient.request).toHaveBeenCalledWith( | ||
'POST', | ||
'http://localhost:80/api/v1', | ||
{ userId: 1 }, | ||
{ | ||
headers: { | ||
'X-Custom-Header': 'WOW', | ||
expect(RestClient.request) | ||
.toHaveBeenCalledWith( | ||
'POST', | ||
'http://localhost:80/api/v1', | ||
{ userId: 1 }, | ||
{ | ||
headers: { | ||
'X-Custom-Header': 'WOW', | ||
}, | ||
}, | ||
}, | ||
); | ||
); | ||
}); | ||
}); | ||
}); |
@@ -9,3 +9,4 @@ /* eslint-disable global-require,no-underscore-dangle */ | ||
const client = new RPClient({ token: 'test' }); | ||
expect(client.config.token).toBe('test'); | ||
expect(client.config.token) | ||
.toBe('test'); | ||
}); | ||
@@ -17,3 +18,4 @@ }); | ||
client = new RPClient({ token: 'nowTest' }); | ||
expect(new Date() - client.helpers.now()).toBeLessThan(100); // less than 100 miliseconds difference | ||
expect(new Date() - client.helpers.now()) | ||
.toBeLessThan(100); // less than 100 miliseconds difference | ||
}); | ||
@@ -24,5 +26,11 @@ }); | ||
it('calls getServerResult', () => { | ||
client = new RPClient({ token: 'startLaunchTest', endpoint: 'https://rp.us/api/v1', project: 'tst' }); | ||
client = new RPClient({ | ||
token: 'startLaunchTest', | ||
endpoint: 'https://rp.us/api/v1', | ||
project: 'tst' | ||
}); | ||
const myPromise = Promise.resolve({ id: 'testidlaunch' }); | ||
spyOn(client.restClient, 'create').and.returnValue(myPromise); | ||
spyOn(client.restClient, 'create') | ||
.and | ||
.returnValue(myPromise); | ||
const time = 12345734; | ||
@@ -32,6 +40,7 @@ client.startLaunch({ | ||
}); | ||
expect(client.restClient.create).toHaveBeenCalledWith('launch', { | ||
name: 'Test launch name', | ||
startTime: time, | ||
}, { headers: client.headers }); | ||
expect(client.restClient.create) | ||
.toHaveBeenCalledWith('launch', { | ||
name: 'Test launch name', | ||
startTime: time, | ||
}, { headers: client.headers }); | ||
}); | ||
@@ -62,6 +71,12 @@ }); | ||
const myPromise = Promise.resolve({ id: 'testidlaunch' }); | ||
spyOn(client.restClient, 'create').and.returnValue(myPromise); | ||
spyOn(client.restClient, 'create') | ||
.and | ||
.returnValue(myPromise); | ||
spyOn(helpers, 'readLaunchesFromFile').and.returnValue(fakeLaunchIds); | ||
spyOn(client, 'getMergeLaunchesData').and.returnValue(fakeMergeDataRQ); | ||
spyOn(helpers, 'readLaunchesFromFile') | ||
.and | ||
.returnValue(fakeLaunchIds); | ||
spyOn(client, 'getMergeLaunchesData') | ||
.and | ||
.returnValue(fakeMergeDataRQ); | ||
client.mergeLaunches(); | ||
@@ -83,5 +98,11 @@ | ||
it('sends put request to update description for launch', () => { | ||
client = new RPClient({ token: 'upLaunchDescTest', endpoint: 'https://rp.us/api/v1', project: 'tst' }); | ||
client = new RPClient({ | ||
token: 'upLaunchDescTest', | ||
endpoint: 'https://rp.us/api/v1', | ||
project: 'tst' | ||
}); | ||
const myPromise = Promise.resolve({ id: 'testidlaunch' }); | ||
spyOn(client.helpers, 'getServerResult').and.returnValue(myPromise); | ||
spyOn(client.helpers, 'getServerResult') | ||
.and | ||
.returnValue(myPromise); | ||
launchObj = client.startLaunch({}); | ||
@@ -93,7 +114,8 @@ client.finishLaunch(launchObj.tempId, {}); | ||
console.dir(client.helpers.getServerResult.calls.all()); | ||
expect(client.helpers.getServerResult.calls.length).toHaveBeenCalledWith( | ||
'https://rp.us/api/v1/tst/launch/id5/update', | ||
{ description: 'newone' }, | ||
{ headers: client.headers }, 'PUT', | ||
); | ||
expect(client.helpers.getServerResult.calls.length) | ||
.toHaveBeenCalledWith( | ||
'https://rp.us/api/v1/tst/launch/id5/update', | ||
{ description: 'newone' }, | ||
{ headers: client.headers }, 'PUT', | ||
); | ||
}); | ||
@@ -106,3 +128,7 @@ }); | ||
spyOn(rest, 'json'); | ||
const conf = { token: 'upLaunchDescTest', endpoint: 'https://rp.us/api/v1', project: 'tst' }; | ||
const conf = { | ||
token: 'upLaunchDescTest', | ||
endpoint: 'https://rp.us/api/v1', | ||
project: 'tst' | ||
}; | ||
const client = new RPClient(conf); | ||
@@ -112,3 +138,4 @@ | ||
expect(rest.json).toHaveBeenCalledWith('url', { param: 'value' }, 'options', 'method'); | ||
expect(rest.json) | ||
.toHaveBeenCalledWith('url', { param: 'value' }, 'options', 'method'); | ||
done(); // need as async code is checked | ||
@@ -119,3 +146,7 @@ }); | ||
it('sends put request to finish launch', () => { | ||
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' }); | ||
const client = new RPClient({ | ||
token: 'any', | ||
endpoint: 'https://rp.api', | ||
project: 'prj' | ||
}); | ||
spyOn(client, '_getResponsePromise'); | ||
@@ -125,6 +156,7 @@ | ||
expect(client._getResponsePromise).toHaveBeenCalledWith( | ||
'https://rp.api/prj/launch/id6/finish', | ||
{ some: 'data' }, { headers: client.headers }, 'PUT', | ||
); | ||
expect(client._getResponsePromise) | ||
.toHaveBeenCalledWith( | ||
'https://rp.api/prj/launch/id6/finish', | ||
{ some: 'data' }, { headers: client.headers }, 'PUT', | ||
); | ||
}); | ||
@@ -134,3 +166,7 @@ }); | ||
it('sends post request to item', () => { | ||
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' }); | ||
const client = new RPClient({ | ||
token: 'any', | ||
endpoint: 'https://rp.api', | ||
project: 'prj' | ||
}); | ||
spyOn(client, '_getResponsePromise'); | ||
@@ -140,6 +176,7 @@ | ||
expect(client._getResponsePromise).toHaveBeenCalledWith( | ||
'https://rp.api/prj/item/parentID5', | ||
{ some: 'data' }, { headers: client.headers }, 'POST', | ||
); | ||
expect(client._getResponsePromise) | ||
.toHaveBeenCalledWith( | ||
'https://rp.api/prj/item/parentID5', | ||
{ some: 'data' }, { headers: client.headers }, 'POST', | ||
); | ||
}); | ||
@@ -149,3 +186,7 @@ }); | ||
it('sends put request to item', () => { | ||
const client = new RPClient({ token: 'any', endpoint: 'https://rp.api', project: 'prj' }); | ||
const client = new RPClient({ | ||
token: 'any', | ||
endpoint: 'https://rp.api', | ||
project: 'prj' | ||
}); | ||
spyOn(client, '_getResponsePromise'); | ||
@@ -155,8 +196,9 @@ | ||
expect(client._getResponsePromise).toHaveBeenCalledWith( | ||
'https://rp.api/prj/item/finishedItemId', | ||
{ finish: 'it' }, { headers: client.headers }, 'PUT', | ||
); | ||
expect(client._getResponsePromise) | ||
.toHaveBeenCalledWith( | ||
'https://rp.api/prj/item/finishedItemId', | ||
{ finish: 'it' }, { headers: client.headers }, 'PUT', | ||
); | ||
}); | ||
}); | ||
}); |
@@ -22,8 +22,13 @@ const nock = require('nock'); | ||
+ '{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}'; | ||
const netErrConnectionResetError = { code: 'ECONNABORTED', message: 'connection reset' }; | ||
const netErrConnectionResetError = { | ||
code: 'ECONNABORTED', | ||
message: 'connection reset' | ||
}; | ||
describe('constructor', () => { | ||
it('creates object with correct properties', () => { | ||
expect(restClient.baseURL).toBe(options.baseURL); | ||
expect(restClient.headers).toEqual(options.headers); | ||
expect(restClient.baseURL) | ||
.toBe(options.baseURL); | ||
expect(restClient.headers) | ||
.toEqual(options.headers); | ||
}); | ||
@@ -34,5 +39,8 @@ }); | ||
it('compose path basing on base', () => { | ||
expect(restClient.buildPath('users')).toBe(`${options.baseURL}/users`); | ||
expect(restClient.buildPath('users/123')).toBe(`${options.baseURL}/users/123`); | ||
expect(restClient.buildPath()).toBe(`${options.baseURL}/`); | ||
expect(restClient.buildPath('users')) | ||
.toBe(`${options.baseURL}/users`); | ||
expect(restClient.buildPath('users/123')) | ||
.toBe(`${options.baseURL}/users/123`); | ||
expect(restClient.buildPath()) | ||
.toBe(`${options.baseURL}/`); | ||
}); | ||
@@ -53,8 +61,11 @@ }); | ||
restClient.retrieve('users', noOptions).then((result) => { | ||
expect(result).toEqual(listOfUsers); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.retrieve('users', noOptions) | ||
.then((result) => { | ||
expect(result) | ||
.toEqual(listOfUsers); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -67,9 +78,13 @@ | ||
restClient.retrieve('users', noOptions).catch((error) => { | ||
expect(error instanceof Error).toBeTruthy(); | ||
expect(error.message).toMatch(netErrConnectionResetError.message); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.retrieve('users', noOptions) | ||
.catch((error) => { | ||
expect(error instanceof Error) | ||
.toBeTruthy(); | ||
expect(error.message) | ||
.toMatch(netErrConnectionResetError.message); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -82,9 +97,13 @@ | ||
restClient.retrieve('users', noOptions).catch((error) => { | ||
expect(error instanceof Error).toBeTruthy(); | ||
expect(error.message).toMatch(unauthorizedErrorMessage); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.retrieve('users', noOptions) | ||
.catch((error) => { | ||
expect(error instanceof Error) | ||
.toBeTruthy(); | ||
expect(error.message) | ||
.toMatch(unauthorizedErrorMessage); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -102,8 +121,11 @@ }); | ||
restClient.create('users', newUser, noOptions).then((result) => { | ||
expect(result).toEqual(userCreated); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.create('users', newUser, noOptions) | ||
.then((result) => { | ||
expect(result) | ||
.toEqual(userCreated); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -118,9 +140,13 @@ | ||
restClient.create('users', newUser, noOptions).catch((error) => { | ||
expect(error instanceof Error).toBeTruthy(); | ||
expect(error.message).toMatch(netErrConnectionResetError.message); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.create('users', newUser, noOptions) | ||
.catch((error) => { | ||
expect(error instanceof Error) | ||
.toBeTruthy(); | ||
expect(error.message) | ||
.toMatch(netErrConnectionResetError.message); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -135,9 +161,13 @@ | ||
restClient.create('users', newUser, noOptions).catch((error) => { | ||
expect(error instanceof Error).toBeTruthy(); | ||
expect(error.message).toMatch(unauthorizedErrorMessage); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.create('users', newUser, noOptions) | ||
.catch((error) => { | ||
expect(error instanceof Error) | ||
.toBeTruthy(); | ||
expect(error.message) | ||
.toMatch(unauthorizedErrorMessage); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -155,8 +185,11 @@ }); | ||
restClient.update('users/1', newUserInfo, noOptions).then((result) => { | ||
expect(result).toEqual(userUpdated); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.update('users/1', newUserInfo, noOptions) | ||
.then((result) => { | ||
expect(result) | ||
.toEqual(userUpdated); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -172,9 +205,13 @@ | ||
restClient.update('users/1', newUserInfo, noOptions).catch((error) => { | ||
expect(error instanceof Error).toBeTruthy(); | ||
expect(error.message).toMatch(netErrConnectionResetError.message); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.update('users/1', newUserInfo, noOptions) | ||
.catch((error) => { | ||
expect(error instanceof Error) | ||
.toBeTruthy(); | ||
expect(error.message) | ||
.toMatch(netErrConnectionResetError.message); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -189,9 +226,13 @@ | ||
restClient.update('users/1', newUserInfo, noOptions).catch((error) => { | ||
expect(error instanceof Error).toBeTruthy(); | ||
expect(error.message).toMatch(unauthorizedErrorMessage); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.update('users/1', newUserInfo, noOptions) | ||
.catch((error) => { | ||
expect(error instanceof Error) | ||
.toBeTruthy(); | ||
expect(error.message) | ||
.toMatch(unauthorizedErrorMessage); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -209,8 +250,11 @@ }); | ||
restClient.delete('users/1', emptyBody, noOptions).then((result) => { | ||
expect(result).toEqual(userDeleted); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.delete('users/1', emptyBody, noOptions) | ||
.then((result) => { | ||
expect(result) | ||
.toEqual(userDeleted); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -225,9 +269,13 @@ | ||
restClient.delete('users/1', emptyBody, noOptions).catch((error) => { | ||
expect(error instanceof Error).toBeTruthy(); | ||
expect(error.message).toMatch(netErrConnectionResetError.message); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.delete('users/1', emptyBody, noOptions) | ||
.catch((error) => { | ||
expect(error instanceof Error) | ||
.toBeTruthy(); | ||
expect(error.message) | ||
.toMatch(netErrConnectionResetError.message); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
@@ -242,11 +290,15 @@ | ||
restClient.delete('users/1', emptyBody, noOptions).catch((error) => { | ||
expect(error instanceof Error).toBeTruthy(); | ||
expect(error.message).toMatch(unauthorizedErrorMessage); | ||
expect(scope.isDone()).toBeTruthy(); | ||
restClient.delete('users/1', emptyBody, noOptions) | ||
.catch((error) => { | ||
expect(error instanceof Error) | ||
.toBeTruthy(); | ||
expect(error.message) | ||
.toMatch(unauthorizedErrorMessage); | ||
expect(scope.isDone()) | ||
.toBeTruthy(); | ||
done(); | ||
}); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
153234
0.43%1923
7.01%6
20%+ Added
+ Added