@reportportal/client-javascript 5.0.5 → 5.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/rest.js CHANGED
@@ -8,90 +8,91 @@ const DEFAULT_MAX_CONNECTION_TIME_MS = 30000;
8
8
  axiosRetry(axios, { retryDelay: () => 100, retries: 10, retryCondition: axiosRetry.isRetryableError });
9
9
 
10
10
  class RestClient {
11
- constructor(options) {
12
- this.baseURL = options.baseURL;
13
- this.headers = options.headers;
14
- this.restClientConfig = options.restClientConfig;
15
- }
16
-
17
- buildPath(path) {
18
- return [this.baseURL, path].join('/');
19
- }
20
-
21
- buildPathToSyncAPI(path) {
22
- return [this.baseURL.replace('/v2', '/v1'), path].join('/');
23
- }
24
-
25
- static request(method, url, data, options = {}) {
26
- return axios(Object.assign({
27
- method,
28
- url,
29
- data,
30
- timeout: DEFAULT_MAX_CONNECTION_TIME_MS,
31
- }, options))
32
- .then(response => response.data)
33
- .catch((error) => {
34
- const errorMessage = error.message;
35
- const responseData = error.response && error.response.data;
36
- throw new Error(`${errorMessage}${
37
- responseData
11
+ constructor(options) {
12
+ this.baseURL = options.baseURL;
13
+ this.headers = options.headers;
14
+ this.restClientConfig = options.restClientConfig;
15
+ }
16
+
17
+ buildPath(path) {
18
+ return [this.baseURL, path].join('/');
19
+ }
20
+
21
+ buildPathToSyncAPI(path) {
22
+ return [this.baseURL.replace('/v2', '/v1'), path].join('/');
23
+ }
24
+
25
+ static request(method, url, data, options = {}) {
26
+ return axios({
27
+ method,
28
+ url,
29
+ data,
30
+ timeout: DEFAULT_MAX_CONNECTION_TIME_MS,
31
+ ...options,
32
+ })
33
+ .then((response) => response.data)
34
+ .catch((error) => {
35
+ const errorMessage = error.message;
36
+ const responseData = error.response && error.response.data;
37
+ throw new Error(`${errorMessage}${
38
+ responseData
38
39
  && typeof responseData === 'object'
39
- ? `: ${JSON.stringify(responseData)}`
40
- : ''}`);
41
- });
42
- }
43
-
44
- getRestConfig() {
45
- if (!this.restClientConfig) return {};
46
-
47
- const config = Object.keys(this.restClientConfig).reduce((acc, key) => {
48
- if (key !== 'agent') {
49
- acc[key] = this.restClientConfig[key];
50
- }
51
- return acc;
52
- }, {});
53
-
54
- if ('agent' in this.restClientConfig) {
55
- const { protocol } = new URL(this.baseURL);
56
- const isHttps = /https:?/;
57
- const isHttpsRequest = isHttps.test(protocol);
58
- config[isHttpsRequest ? 'httpsAgent' : 'httpAgent'] = isHttpsRequest
59
- ? new https.Agent(this.restClientConfig.agent)
60
- : new http.Agent(this.restClientConfig.agent);
61
- }
62
-
63
- return config;
40
+ ? `: ${JSON.stringify(responseData)}`
41
+ : ''}`);
42
+ });
43
+ }
44
+
45
+ getRestConfig() {
46
+ if (!this.restClientConfig) return {};
47
+
48
+ const config = Object.keys(this.restClientConfig).reduce((acc, key) => {
49
+ if (key !== 'agent') {
50
+ acc[key] = this.restClientConfig[key];
51
+ }
52
+ return acc;
53
+ }, {});
54
+
55
+ if ('agent' in this.restClientConfig) {
56
+ const { protocol } = new URL(this.baseURL);
57
+ const isHttps = /https:?/;
58
+ const isHttpsRequest = isHttps.test(protocol);
59
+ config[isHttpsRequest ? 'httpsAgent' : 'httpAgent'] = isHttpsRequest
60
+ ? new https.Agent(this.restClientConfig.agent)
61
+ : new http.Agent(this.restClientConfig.agent);
64
62
  }
65
63
 
66
- create(path, data, options = { headers: this.headers }) {
67
- return RestClient.request('POST', this.buildPath(path), data, Object.assign({}, options, this.getRestConfig()));
68
- }
69
-
70
- retrieve(path, options = { headers: this.headers }) {
71
- return RestClient.request('GET', this.buildPath(path), {}, Object.assign({}, options, this.getRestConfig()));
72
- }
73
-
74
- update(path, data, options = { headers: this.headers }) {
75
- return RestClient.request('PUT', this.buildPath(path), data, Object.assign({}, options, this.getRestConfig()));
76
- }
77
-
78
- delete(path, data, options = { headers: this.headers }) {
79
- return RestClient.request(
80
- 'DELETE',
81
- this.buildPath(path),
82
- data,
83
- Object.assign({}, options, this.getRestConfig()),
84
- );
85
- }
86
-
87
- retrieveSyncAPI(path, options = { headers: this.headers }) {
88
- return RestClient.request(
89
- 'GET',
90
- this.buildPathToSyncAPI(path),
91
- {},
92
- Object.assign({}, options, this.getRestConfig()),
93
- );
94
- }
64
+ return config;
65
+ }
66
+
67
+ create(path, data, options = { headers: this.headers }) {
68
+ return RestClient.request('POST', this.buildPath(path), data, { ...options, ...this.getRestConfig() });
69
+ }
70
+
71
+ retrieve(path, options = { headers: this.headers }) {
72
+ return RestClient.request('GET', this.buildPath(path), {}, { ...options, ...this.getRestConfig() });
73
+ }
74
+
75
+ update(path, data, options = { headers: this.headers }) {
76
+ return RestClient.request('PUT', this.buildPath(path), data, { ...options, ...this.getRestConfig() });
77
+ }
78
+
79
+ delete(path, data, options = { headers: this.headers }) {
80
+ return RestClient.request(
81
+ 'DELETE',
82
+ this.buildPath(path),
83
+ data,
84
+ { ...options, ...this.getRestConfig() },
85
+ );
86
+ }
87
+
88
+ retrieveSyncAPI(path, options = { headers: this.headers }) {
89
+ return RestClient.request(
90
+ 'GET',
91
+ this.buildPathToSyncAPI(path),
92
+ {},
93
+ { ...options, ...this.getRestConfig() },
94
+ );
95
+ }
95
96
  }
96
97
 
97
98
  module.exports = RestClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reportportal/client-javascript",
3
- "version": "5.0.5",
3
+ "version": "5.0.6",
4
4
  "description": "ReportPortal client for node.js",
5
5
  "author": "ReportPortal.io",
6
6
  "contributors": [
@@ -21,33 +21,38 @@
21
21
  "directories": {
22
22
  "lib": "./lib"
23
23
  },
24
+ "files": [
25
+ "/lib",
26
+ "/analytics",
27
+ "/VERSION"
28
+ ],
24
29
  "main": "./lib/report-portal-client",
25
30
  "engines": {
26
- "node": ">= 8.0.x"
31
+ "node": ">= 10.0.0"
27
32
  },
28
33
  "dependencies": {
29
- "axios": "^0.21.1",
30
- "axios-retry": "^3.1.2",
31
- "glob": "^7.1.4",
32
- "uniqid": "^5.0.3",
34
+ "axios": "^0.24.0",
35
+ "axios-retry": "^3.2.4",
36
+ "glob": "^7.2.0",
37
+ "uniqid": "^5.4.0",
33
38
  "universal-analytics": "^0.4.20"
34
39
  },
35
40
  "license": "Apache-2.0",
36
41
  "scripts": {
37
42
  "lint": "eslint . --quiet",
43
+ "format": "npm run lint -- --fix",
38
44
  "test": "nyc ./node_modules/jasmine/bin/jasmine.js",
39
45
  "test:coverage": "nyc report --reporter=lcov --reporter=text-summary"
40
46
  },
41
47
  "devDependencies": {
42
- "codecov": "3.7.1",
43
- "eslint": "5.16.0",
44
- "eslint-config-airbnb-base": "^13.1.0",
45
- "eslint-plugin-import": "^2.17.0",
46
- "eslint-plugin-node": "^8.0.1",
48
+ "eslint": "^7.32.0",
49
+ "eslint-config-airbnb-base": "^15.0.0",
50
+ "eslint-plugin-import": "^2.25.4",
51
+ "eslint-plugin-node": "^11.1.0",
47
52
  "jasmine": "^3.5.0",
48
53
  "lodash": "^4.17.11",
49
54
  "nock": "^10.0.6",
50
- "nyc": "^14.1.1"
55
+ "nyc": "^15.1.0"
51
56
  },
52
57
  "bugs": {
53
58
  "url": "https://github.com/reportportal/client-javascript/issues"
package/.eslintrc DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "extends": "airbnb-base",
3
- "globals": {
4
- "expectAsync": true
5
- },
6
- "env": {
7
- "node": true,
8
- "es6": true,
9
- "jasmine": true
10
- },
11
- "rules": {
12
- "indent": ["error", 4],
13
- "max-len": ["error", 120],
14
- "valid-jsdoc": ["error", { "requireReturn": false }],
15
- "consistent-return": 0
16
- }
17
- }
package/.istanbul.yml DELETED
@@ -1,3 +0,0 @@
1
- instrumentation:
2
- excludes:
3
- - "spec/libSpec.js"
@@ -1,46 +0,0 @@
1
- const Analytics = require('../analytics/analytics');
2
- const { getAgentEventLabel } = require('../analytics/events');
3
-
4
- const agentParams = {
5
- name: 'AgentName',
6
- version: 'AgentVersion',
7
- };
8
-
9
- describe('Analytics', () => {
10
- describe('class Analytics', () => {
11
- let analytics;
12
-
13
- beforeEach(() => {
14
- analytics = new Analytics(agentParams);
15
- });
16
-
17
- it('should be properly initialized', () => {
18
- expect(analytics.agentParams).toEqual(agentParams);
19
- expect(analytics.visitorInstance).toBeDefined();
20
- });
21
-
22
- it('trackEvent should called the method event with correct parameters', () => {
23
- spyOn(analytics.visitorInstance, 'event').and.returnValue({
24
- send: () => {},
25
- });
26
-
27
- analytics.trackEvent({
28
- category: 'category',
29
- action: 'action',
30
- label: 'label',
31
- });
32
-
33
- expect(analytics.visitorInstance.event).toHaveBeenCalledWith('category', 'action', 'label');
34
- });
35
- });
36
-
37
- describe('events', () => {
38
- it('getAgentEventLabel return correct label', () => {
39
- const expectedLabel = 'Agent name "AgentName", version "AgentVersion"';
40
-
41
- const label = getAgentEventLabel(agentParams);
42
-
43
- expect(label).toEqual(expectedLabel);
44
- });
45
- });
46
- });
@@ -1,142 +0,0 @@
1
- const os = require('os');
2
- const fs = require('fs');
3
- const glob = require('glob');
4
- const RPClient = require('../lib/report-portal-client.js');
5
- const RestClient = require('../lib/rest');
6
- const pjson = require('./../package.json');
7
-
8
- describe('Helpers', () => {
9
- const client = new RPClient({ token: 'token' });
10
-
11
- describe('formatName', () => {
12
- it('slice last 256 symbols', () => {
13
- expect(client.helpers.formatName(`a${'b'.repeat(256)}`)).toBe('b'.repeat(256));
14
- });
15
- it('leave 256 symbol name as is', () => {
16
- expect(client.helpers.formatName('c'.repeat(256))).toBe('c'.repeat(256));
17
- });
18
- it('leave 3 symbol name as is', () => {
19
- expect(client.helpers.formatName('abc')).toBe('abc');
20
- });
21
- it('complete with dots 2 symbol name', () => {
22
- expect(client.helpers.formatName('ab')).toBe('ab.');
23
- });
24
- });
25
-
26
- describe('now', () => {
27
- it('returns milliseconds from unix time', () => {
28
- expect(new Date() - client.helpers.now()).toBeLessThan(100); // less than 100 miliseconds difference
29
- });
30
- });
31
-
32
- describe('getServerResults', () => {
33
- it('calls RestClient#request', () => {
34
- spyOn(RestClient, 'request');
35
-
36
- client.helpers.getServerResult(
37
- 'http://localhost:80/api/v1',
38
- { userId: 1 },
39
- {
40
- headers: {
41
- 'X-Custom-Header': 'WOW',
42
- },
43
- },
44
- 'POST',
45
- );
46
-
47
- expect(RestClient.request).toHaveBeenCalledWith(
48
- 'POST',
49
- 'http://localhost:80/api/v1',
50
- { userId: 1 },
51
- {
52
- headers: {
53
- 'X-Custom-Header': 'WOW',
54
- },
55
- },
56
- );
57
- });
58
- });
59
-
60
- describe('readLaunchesFromFile', () => {
61
- it('should return the right ids', () => {
62
- spyOn(glob, 'sync').and.returnValue(['rplaunch-fileOne.tmp', 'rplaunch-fileTwo.tmp']);
63
-
64
- const ids = client.helpers.readLaunchesFromFile();
65
-
66
- expect(ids).toEqual(['fileOne', 'fileTwo']);
67
- });
68
- });
69
-
70
- describe('saveLaunchIdToFile', () => {
71
- it('should call fs.open method with right parameters', () => {
72
- spyOn(fs, 'open');
73
-
74
- client.helpers.saveLaunchIdToFile('fileOne');
75
-
76
- expect(fs.open).toHaveBeenCalledWith('rplaunch-fileOne.tmp', 'w', jasmine.any(Function));
77
- });
78
- });
79
-
80
- describe('getSystemAttribute', () => {
81
- it('should return correct system attributes', () => {
82
- spyOn(os, 'type').and.returnValue('osType');
83
- spyOn(os, 'arch').and.returnValue('osArchitecture');
84
- spyOn(os, 'totalmem').and.returnValue('1');
85
- const nodeVersion = process.version;
86
- const expectedAttr = [{
87
- key: 'client',
88
- value: `${pjson.name}|${pjson.version}`,
89
- system: true,
90
- }, {
91
- key: 'os',
92
- value: 'osType|osArchitecture',
93
- system: true,
94
- }, {
95
- key: 'RAMSize',
96
- value: '1',
97
- system: true,
98
- }, {
99
- key: 'nodeJS',
100
- value: nodeVersion,
101
- system: true,
102
- }];
103
-
104
- const attr = client.helpers.getSystemAttribute();
105
-
106
- expect(attr).toEqual(expectedAttr);
107
- });
108
- });
109
-
110
- describe('generateTestCaseId', () => {
111
- it('should return undefined if there is no codeRef', () => {
112
- const testCaseId = client.helpers.generateTestCaseId();
113
-
114
- expect(testCaseId).toEqual(undefined);
115
- });
116
-
117
- it('should return codeRef if there is no params', () => {
118
- const testCaseId = client.helpers.generateTestCaseId('codeRef');
119
-
120
- expect(testCaseId).toEqual('codeRef');
121
- });
122
-
123
- it('should return codeRef with parameters if there are all parameters', () => {
124
- const parameters = [
125
- {
126
- key: 'key',
127
- value: 'value',
128
- },
129
- { value: 'valueTwo' },
130
- { key: 'keyTwo' },
131
- {
132
- key: 'keyThree',
133
- value: 'valueThree',
134
- },
135
- ];
136
-
137
- const testCaseId = client.helpers.generateTestCaseId('codeRef', parameters);
138
-
139
- expect(testCaseId).toEqual('codeRef[value,valueTwo,valueThree]');
140
- });
141
- });
142
- });
@@ -1,75 +0,0 @@
1
- const PublicReportingAPI = require('../lib/publicReportingAPI');
2
- const { EVENTS } = require('../lib/constants/events');
3
-
4
- describe('PublicReportingAPI', () => {
5
- it('setDescription should trigger process.emit with correct parameters', () => {
6
- spyOn(process, 'emit');
7
-
8
- PublicReportingAPI.setDescription('text', 'suite');
9
-
10
- expect(process.emit).toHaveBeenCalledWith(EVENTS.SET_DESCRIPTION, {
11
- text: 'text',
12
- suite: 'suite',
13
- });
14
- });
15
-
16
- it('addAttributes should trigger process.emit with correct parameters', () => {
17
- spyOn(process, 'emit');
18
-
19
- PublicReportingAPI.addAttributes([{ value: 'value' }], 'suite');
20
-
21
- expect(process.emit).toHaveBeenCalledWith(EVENTS.ADD_ATTRIBUTES, {
22
- attributes: [{ value: 'value' }],
23
- suite: 'suite',
24
- });
25
- });
26
-
27
- it('addLog should trigger process.emit with correct parameters', () => {
28
- spyOn(process, 'emit');
29
-
30
- PublicReportingAPI.addLog({ level: 'INFO', message: 'message' }, 'suite');
31
-
32
- expect(process.emit).toHaveBeenCalledWith(EVENTS.ADD_LOG, {
33
- log: { level: 'INFO', message: 'message' },
34
- suite: 'suite',
35
- });
36
- });
37
-
38
- it('addLaunchLog should trigger process.emit with correct parameters', () => {
39
- spyOn(process, 'emit');
40
-
41
- PublicReportingAPI.addLaunchLog({ level: 'INFO', message: 'message' });
42
-
43
- expect(process.emit).toHaveBeenCalledWith(EVENTS.ADD_LAUNCH_LOG, { level: 'INFO', message: 'message' });
44
- });
45
-
46
- it('setTestCaseId should trigger process.emit with correct parameters', () => {
47
- spyOn(process, 'emit');
48
-
49
- PublicReportingAPI.setTestCaseId('testCaseId', 'suite');
50
-
51
- expect(process.emit).toHaveBeenCalledWith(EVENTS.SET_TEST_CASE_ID, {
52
- testCaseId: 'testCaseId',
53
- suite: 'suite',
54
- });
55
- });
56
-
57
- it('setLaunchStatus should trigger process.emit with correct parameters', () => {
58
- spyOn(process, 'emit');
59
-
60
- PublicReportingAPI.setLaunchStatus('passed');
61
-
62
- expect(process.emit).toHaveBeenCalledWith(EVENTS.SET_LAUNCH_STATUS, 'passed');
63
- });
64
-
65
- it('setStatus should trigger process.emit with correct parameters', () => {
66
- spyOn(process, 'emit');
67
-
68
- PublicReportingAPI.setStatus('passed', 'suite');
69
-
70
- expect(process.emit).toHaveBeenCalledWith(EVENTS.SET_STATUS, {
71
- status: 'passed',
72
- suite: 'suite',
73
- });
74
- });
75
- });