Skip to content

Commit

Permalink
Merge pull request #35 from reportportal/develop
Browse files Browse the repository at this point in the history
Release 5.0.3
  • Loading branch information
AmsterGet authored Oct 5, 2022
2 parents 5275ae7 + e6627b4 commit 6dd50ba
Show file tree
Hide file tree
Showing 13 changed files with 1,881 additions and 1,526 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Added
- Support reportSeleniumCommands and seleniumCommandsLogLevel for Cucumber and Jasmine reporting via `reportSeleniumCommands`, `seleniumCommandsLogLevel` flags
- _isLaunchMergeRequired_ config option support. Provided guide on merging launches manually [provided](README.md#manual-merge-launches)

## [5.0.2] - 2022-05-31
### Added
Expand Down
130 changes: 94 additions & 36 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.0.2
5.0.3-SNAPSHOT
2,922 changes: 1,446 additions & 1,476 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
},
"dependencies": {
"@reportportal/client-javascript": "^5.0.6",
"@wdio/reporter": "^7.13.2"
"@wdio/reporter": "^7.25.1",
"json-stringify-safe": "^5.0.1"
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/node": "^16.10.1",
"@types/json-stringify-safe": "^5.0.0",
"@typescript-eslint/eslint-plugin": "^4.31.2",
"@typescript-eslint/parser": "^4.31.2",
"@wdio/types": "^7.13.2",
Expand All @@ -34,7 +36,7 @@
"rimraf": "^3.0.2",
"ts-jest": "^27.0.5",
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
"typescript": "^4.8.4"
},
"repository": {
"type": "git",
Expand Down
52 changes: 51 additions & 1 deletion src/__tests__/onAfterCommand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ import { Reporter } from '../reporter';
import { options } from './mocks/optionsMock';
import { RPClientMock } from './mocks/RPClientMock';
import { testId, testName } from './mocks/data';
import { getClientConfig } from '../utils';
import { getClientConfig, limit } from '../utils';

describe('onAfterCommand', () => {
const reporter = new Reporter(options);
reporter['client'] = new RPClientMock(getClientConfig(options));
reporter['storage'].addTest({ id: testId, name: testName });

afterEach(() => {
jest.clearAllMocks();
});

it('screenshot command. client.send should be called with corresponding params', () => {
reporter['options'].attachPicturesToLogs = true;
const command = {
Expand All @@ -47,4 +51,50 @@ describe('onAfterCommand', () => {
{ content: 'iVBORw0K', name: 'screenshot', type: 'image/png' },
);
});

it('reportSeleniumLogs command. client.send should be called with corresponding params', () => {
reporter['options'].reportSeleniumCommands = true;
reporter['options'].seleniumCommandsLogLevel = 'debug';

const command = {
method: 'POST',
endpoint: '/session/:sessionId/url',
body: {},
result: { value: 'complete' },
sessionId: 'd315f4dddf5199a74eac978476bad9d0',
cid: '0-0',
};

reporter.onAfterCommand(command);

const method = `${command.method} ${command.endpoint}`;
const data = JSON.stringify(limit(command.result));
const { seleniumCommandsLogLevel } = reporter['options'];

expect(reporter['client'].sendLog).toBeCalledWith(
testId,
{
level: seleniumCommandsLogLevel,
message: `${method} ${data}`,
},
undefined,
);
});

it('reportSeleniumLogs command. client.send should not be called when reporter.options.reportSeleniumCommands = false', () => {
reporter['options'].reportSeleniumCommands = false;

const command = {
method: 'POST',
endpoint: '/session/:sessionId/url',
body: {},
result: { value: 'complete' },
sessionId: 'd315f4dddf5199a74eac978476bad9d0',
cid: '0-0',
};

reporter.onAfterCommand(command);

expect(reporter['client'].sendLog).not.toBeCalled();
});
});
106 changes: 106 additions & 0 deletions src/__tests__/onBeforeCommand.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright 2022 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import { Reporter } from '../reporter';
import { getClientConfig } from '../utils';
import { testId, testName } from './mocks/data';
import { options } from './mocks/optionsMock';
import { RPClientMock } from './mocks/RPClientMock';

describe('onBeforeCommand', () => {
const reporter = new Reporter(options);
reporter['client'] = new RPClientMock(getClientConfig(options));
reporter['storage'].addTest({ id: testId, name: testName });

afterEach(() => {
jest.clearAllMocks();
});

it('reportSeleniumLogs command. client.send should be called with corresponding params if command.body is not empty', () => {
reporter['options'].reportSeleniumCommands = true;
reporter['options'].seleniumCommandsLogLevel = 'debug';

const command = {
method: 'POST',
endpoint: '/session/:sessionId/url',
body: { url: 'https://google.com' },
result: { value: 'complete' },
sessionId: 'd315f4dddf5199a74eac978476bad9d0',
cid: '0-0',
};

reporter.onBeforeCommand(command);

const method = `${command.method} ${command.endpoint}`;
const data = JSON.stringify(command.body);
const { seleniumCommandsLogLevel } = reporter['options'];

expect(reporter['client'].sendLog).toBeCalledWith(
testId,
{
level: seleniumCommandsLogLevel,
message: `${method} ${data}`,
},
undefined,
);
});
it('reportSeleniumLogs command. client.send should be called with corresponding params if command.body is empty', () => {
reporter['options'].reportSeleniumCommands = true;
reporter['options'].seleniumCommandsLogLevel = 'debug';

const command = {
method: 'POST',
endpoint: '/session/:sessionId/url',
body: {},
result: { value: 'complete' },
sessionId: 'd315f4dddf5199a74eac978476bad9d0',
cid: '0-0',
};

reporter.onBeforeCommand(command);

const method = `${command.method} ${command.endpoint}`;
const { seleniumCommandsLogLevel } = reporter['options'];

expect(reporter['client'].sendLog).toBeCalledWith(
testId,
{
level: seleniumCommandsLogLevel,
message: `${method}`,
},
undefined,
);
});

it('reportSeleniumLogs command. client.send should not be called', () => {
reporter['options'].reportSeleniumCommands = false;
reporter['options'].seleniumCommandsLogLevel = 'debug';

const command = {
method: 'POST',
endpoint: '/session/:sessionId/url',
body: {},
result: { value: 'complete' },
sessionId: 'd315f4dddf5199a74eac978476bad9d0',
cid: '0-0',
};

reporter.onBeforeCommand(command);

expect(reporter['client'].sendLog).not.toBeCalled();
});
});
4 changes: 3 additions & 1 deletion src/__tests__/onRunnerStart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ import { RPClientMock } from './mocks/RPClientMock';
import { LaunchObj } from '../models';
import { getStartLaunchObj } from '../utils';
import { getClientConfig } from '../utils';
import { RunnerStats } from '@wdio/reporter';

describe('onRunnerStart', () => {
const reporter: Reporter = new Reporter(options);
const runnerStats: Partial<RunnerStats> = { isMultiremote: false };
reporter['client'] = new RPClientMock(getClientConfig(options));

it('client.startLaunch should be called with corresponding params', () => {
const launchDataRQ: LaunchObj = getStartLaunchObj(options);

reporter.onRunnerStart();
reporter.onRunnerStart(runnerStats);

expect(reporter['client'].startLaunch).toBeCalledTimes(1);
expect(reporter['client'].startLaunch).toBeCalledWith(launchDataRQ);
Expand Down
64 changes: 63 additions & 1 deletion src/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getCodeRef,
getStartLaunchObj,
getSystemAttributes,
limit,
parseTags,
promiseErrorHandler,
} from '../utils';
Expand Down Expand Up @@ -65,7 +66,6 @@ describe('utils', () => {
restClientConfig: {
agent: { keepAlive: true },
},
cucumberNestedSteps: true,
};
const extendedOptions = {
...options,
Expand Down Expand Up @@ -174,4 +174,66 @@ describe('utils', () => {
expect(parseTags([''])).toEqual([]);
});
});
describe('limit', () => {
const baseUser = {
name: 'UserName',
surname: 'UserSurname',
fullName: 'UserName UserSurname',
age: 21,
id: 2,
tel: '12345',
eMail: '[email protected]',
address: 'Some address',
password: '*****',
role: 'Some role',
};

const baseValues = new Array(10).fill('some value');

it('should not changed value if argument is null', () => {
expect(limit(null)).toBeNull();
});

it('should not changed value if argument is undefined', () => {
expect(limit(undefined)).toBeUndefined();
});

it('should not changed value if argument is 0', () => {
expect(limit(0)).toBe(0);
});

it('should not changed value if argument is ""', () => {
expect(limit('')).toBe('');
});

it('should works correctly if string`s length less than 1000', () => {
expect(limit('Value witch length less then 1000')).toBe('Value witch length less then 1000');
});

it('should works correctly with object that has 10 or less properties', () => {
expect(limit(baseUser)).toEqual(baseUser);
});

it('should works correctly with object that has more than 10', () => {
const user = {
...baseUser,
hobbies: 'Some hobbies',
};

const expectedObject = { ...baseUser, _: `1 more keys: [\"hobbies\"]` };

expect(limit(user)).toEqual(expectedObject);
});

it('should works correctly with arrays witch length 10 or less', () => {
expect(limit(baseValues)).toEqual(baseValues);
});

it('should works correctly with arrays witch length more than 10', () => {
const valuesArray = [...baseValues, 'some value'];
const expectedArray = [...baseValues, '(1 more items)'];

expect(limit(valuesArray)).toEqual(expectedArray);
});
});
});
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export {
Attribute,
BaseObj,
Config,
ClientConfig,
FinishTestItem,
LaunchFinishObj,
LaunchObj,
Expand Down
9 changes: 7 additions & 2 deletions src/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import { FILE_TYPES, LOG_LEVELS, TYPES } from '../constants';

export interface Config {
export interface ClientConfig {
token: string;
endpoint: string;
launch: string;
Expand All @@ -27,10 +27,15 @@ export interface Config {
headers?: BaseObj;
mode?: 'DEFAULT' | 'DEBUG';
debug?: boolean;
skippedIssue?: boolean;
isLaunchMergeRequired?: boolean;
}

export interface Config extends ClientConfig {
skippedIssue?: boolean;
rerun?: boolean;
rerunOf?: string;
seleniumCommandsLogLevel?: LOG_LEVELS;
reportSeleniumCommands?: boolean;
}

export interface LaunchObj {
Expand Down
Loading

0 comments on commit 6dd50ba

Please sign in to comment.