Skip to content

Commit

Permalink
Add existing launchId support. Fix default values for launch mode and…
Browse files Browse the repository at this point in the history
… log level
  • Loading branch information
AmsterGet committed Feb 2, 2024
1 parent 6b705a4 commit c744762
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 54 deletions.
50 changes: 33 additions & 17 deletions README.md

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions src/__tests__/constructor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ import { Reporter } from '../reporter';
import { options } from './mocks/optionsMock';

describe('reporter constructor', () => {
let reporter: Reporter;
beforeEach(() => {
reporter = new Reporter(options);
});
const optionsWithDefaults = {
seleniumCommandsLogLevel: 'info',
...options,
};

it('should store configuration data', () => {
expect(reporter.options).toEqual(options);
it('should store configuration data with default values', () => {
const reporter = new Reporter(options);
expect(reporter.options).toEqual(optionsWithDefaults);
});

it('isSynchronised should be FALSE', () => {
const reporter = new Reporter(options);
expect(reporter.isSynchronised).toBeFalsy();
});

it('should override options defaults via user provided options', () => {
const reporterOptions = { ...options, seleniumCommandsLogLevel: 'debug' };
const reporter = new Reporter(reporterOptions);
expect(reporter.options).toEqual(reporterOptions);
});
});
72 changes: 49 additions & 23 deletions src/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import {
parseTags,
promiseErrorHandler,
} from '../utils';
import { LAUNCH_MODES } from '../constants';
import { LaunchObj } from '../models';
import { options } from './mocks/optionsMock';

describe('utils', () => {
Expand All @@ -41,15 +43,7 @@ describe('utils', () => {
});

describe('getClientConfig', () => {
const { apiKey, endpoint, launch, project, attributes, description } = options;
const baseRes = {
apiKey,
endpoint,
launch,
project,
attributes,
description,
};
const { logFile, ...baseRes } = options;

it('should return base config', () => {
expect(getClientConfig(options)).toEqual(baseRes);
Expand Down Expand Up @@ -133,27 +127,59 @@ describe('utils', () => {
});

describe('getStartLaunchObj', () => {
const { attributes: optionsAttributes, description, rerun, rerunOf } = options;
const startLaunchObject: LaunchObj = {
attributes: optionsAttributes,
description,
rerun,
rerunOf,
mode: LAUNCH_MODES.DEFAULT,
id: undefined,
};
const systemAttributes = getSystemAttributes(options);
const fullAttributes = options.attributes.concat(systemAttributes);

it('config with attributes', () => {
const { description, attributes, rerun, rerunOf, mode } = options;
const expectedRes = {
attributes: [...attributes, ...systemAttributes],
description,
rerun,
rerunOf,
mode,
it('should return start launch object with system attributes joined with provided', () => {
const expectedObject = {
...startLaunchObject,
attributes: fullAttributes,
};

expect(getStartLaunchObj(options)).toEqual(expectedObject);
});

it('should return start launch object only with system attributes in case of no attributes provided', () => {
const { attributes, ...optionsWithoutAttributes } = options;
const expectedObject = {
...startLaunchObject,
attributes: systemAttributes,
};

expect(getStartLaunchObj(options)).toEqual(expectedRes);
expect(getStartLaunchObj(optionsWithoutAttributes)).toEqual(expectedObject);
});

it('config without attributes', () => {
const newOptions = Object.assign(options, { attributes: undefined });
const { description, rerun, rerunOf, mode } = newOptions;
const expectedRes = { attributes: systemAttributes, description, rerun, rerunOf, mode };
it('should set launch id from options launchId property', () => {
const launchId = 'realLaunchId';
const optionsWithLaunchId = { ...options, launchId: launchId };
const expectedObject = {
...startLaunchObject,
attributes: fullAttributes,
id: launchId,
};

expect(getStartLaunchObj(optionsWithLaunchId)).toEqual(expectedObject);
});

it('should set launch id from environment variable if exists', () => {
process.env.RP_LAUNCH_ID = 'realLaunchId';
const expectedObject = {
...startLaunchObject,
attributes: fullAttributes,
id: 'realLaunchId',
};

expect(getStartLaunchObj(options)).toEqual(expectedRes);
expect(getStartLaunchObj(options)).toEqual(expectedObject);
delete process.env.RP_LAUNCH_ID;
});
});

Expand Down
1 change: 1 addition & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export { CUCUMBER_TYPE, TYPES } from './testItemTypes';
export { RP_STATUSES } from './statuses';
export { LOG_LEVELS } from './logLevels';
export { FILE_TYPES } from './fileTypes';
export { LAUNCH_MODES } from './launchModes';
export { BROWSER_PARAM } from './parameters';
21 changes: 21 additions & 0 deletions src/constants/launchModes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2024 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.
*
*/

export enum LAUNCH_MODES {
DEFAULT = 'DEFAULT',
DEBUG = 'DEBUG',
}
13 changes: 9 additions & 4 deletions src/models/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 EPAM Systems
* Copyright 2024 EPAM Systems
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,9 @@
*
*/

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

type launchMode = LAUNCH_MODES.DEFAULT | LAUNCH_MODES.DEBUG;

export interface ClientConfig {
apiKey: string;
Expand All @@ -25,9 +27,11 @@ export interface ClientConfig {
description?: string;
attributes?: Attribute[];
headers?: BaseObj;
mode?: 'DEFAULT' | 'DEBUG';
mode?: launchMode;
debug?: boolean;
isLaunchMergeRequired?: boolean;
launchUuidPrint?: boolean;
launchUuidPrintOutput?: string;
token?: string;
}

Expand All @@ -37,14 +41,15 @@ export interface Config extends ClientConfig {
rerunOf?: string;
seleniumCommandsLogLevel?: LOG_LEVELS;
reportSeleniumCommands?: boolean;
launchId?: string;
}

export interface LaunchObj {
name?: string;
startTime?: Date | number;
description?: string;
attributes?: Attribute[];
mode?: 'DEFAULT' | 'DEBUG';
mode?: launchMode;
rerun?: boolean;
rerunOf?: string;
id?: string;
Expand Down
5 changes: 4 additions & 1 deletion src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ export class Reporter extends WDIOReporter {

const agentInfo = getAgentInfo();
const clientConfig = getClientConfig(options);
this.options = options;
this.options = {
seleniumCommandsLogLevel: 'info',
...options,
};
this.syncReporting = false;
this.client = new RPClient(clientConfig, agentInfo);
this.storage = new Storage();
Expand Down
12 changes: 9 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Reporters } from '@wdio/types';
import { Tag } from '@wdio/reporter/build/types';
// @ts-ignore
import { name as pjsonName, version as pjsonVersion } from '../package.json';
import { LAUNCH_MODES } from './constants/launchModes';
import { Attribute, ClientConfig, LaunchObj, Suite } from './models';

export const promiseErrorHandler = (promise: Promise<any>): void => {
Expand All @@ -44,6 +45,8 @@ export const getClientConfig = (options: Partial<Reporters.Options>): ClientConf
headers,
restClientConfig,
isLaunchMergeRequired,
launchUuidPrint,
launchUuidPrintOutput,
} = options;

let apiKey = options.apiKey;
Expand All @@ -68,7 +71,9 @@ export const getClientConfig = (options: Partial<Reporters.Options>): ClientConf
...(debug && { debug }),
...(headers && { headers }),
...(restClientConfig && { restClientConfig }),
...(isLaunchMergeRequired && { isLaunchMergeRequired }),
launchUuidPrint,
launchUuidPrintOutput,
isLaunchMergeRequired,
};
};

Expand Down Expand Up @@ -104,14 +109,15 @@ export const getStartLaunchObj = (
launchObj: LaunchObj = {},
): LaunchObj => {
const systemAttributes = getSystemAttributes(config);
const { description, attributes, rerun, rerunOf, mode } = config;
const { description, attributes, rerun, rerunOf, mode, launchId } = config;

return {
description,
attributes: [...(attributes || []), ...systemAttributes],
rerun,
rerunOf,
mode,
mode: mode || LAUNCH_MODES.DEFAULT,
id: process.env.RP_LAUNCH_ID || launchId,
...launchObj,
};
};
Expand Down

0 comments on commit c744762

Please sign in to comment.