Skip to content

Commit

Permalink
chore: enable target and extension (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
ASaiAnudeep authored Oct 20, 2024
1 parent 5df0703 commit 0f46f6d
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 66 deletions.
6 changes: 6 additions & 0 deletions src/commands/publish.command.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ class PublishCommand {
throw new Error('targets must be an array');
}
for (const target of config.targets) {
if (target.enable === false || target.enable === 'false') {
continue;
}
if (!target.name) {
throw new Error(`'config.targets[*].name' is missing`);
}
Expand Down Expand Up @@ -219,6 +222,9 @@ class PublishCommand {
await beats.run(config, result);
if (config.targets) {
for (const target of config.targets) {
if (target.enable === false || target.enable === 'false') {
continue;
}
target.extensions = target.extensions || [];
target.extensions = config.extensions.concat(target.extensions);
await target_manager.run(target, result);
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/base.extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ class BaseExtension {

/**
*
* @param {import('..').Target} target
* @param {import('..').Extension} extension
* @param {import('..').ITarget} target
* @param {import('..').IExtension} extension
* @param {import('..').TestResult} result
* @param {any} payload
* @param {any} root_payload
Expand Down
6 changes: 6 additions & 0 deletions src/extensions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ const { FailureAnalysisExtension } = require('./failure-analysis.extension');

async function run(options) {
const { target, result, hook } = options;
/**
* @type {import("..").IExtension[]}
*/
const extensions = target.extensions || [];
for (let i = 0; i < extensions.length; i++) {
const extension = extensions[i];
if (extension.enable === false || extension.enable === 'false') {
continue;
}
const extension_runner = getExtensionRunner(extension, options);
const extension_options = Object.assign({}, extension_runner.default_options, extension);
if (extension_options.hook === hook) {
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { getTeamsMetaDataText, getSlackMetaDataText, getChatMetaDataText } = requ

/**
* @param {object} param0
* @param {import('..').Target} param0.target
* @param {import('..').ITarget} param0.target
* @param {import('..').MetadataExtension} param0.extension
*/
async function run({ target, extension, result, payload, root_payload }) {
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/extension.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*
* @param {object} param0 - the payload object
* @param {object} param0.payload - the payload object
* @param {import("..").Extension} param0.extension - the extension to add
* @param {import("..").IExtension} param0.extension - the extension to add
* @param {string} param0.text - the text to include
* @return {void}
* @return {void}
*/
function addSlackExtension({ payload, extension, text }) {
if (extension.inputs.separator) {
Expand Down Expand Up @@ -44,9 +44,9 @@ function addSlackExtension({ payload, extension, text }) {
*
* @param {object} param0 - the payload object
* @param {object} param0.payload - the payload object
* @param {import("..").Extension} param0.extension - the extension to add
* @param {import("..").IExtension} param0.extension - the extension to add
* @param {string} param0.text - the text to include
* @return {void}
* @return {void}
*/
function addTeamsExtension({ payload, extension, text }) {
if (extension.inputs.title) {
Expand Down Expand Up @@ -79,9 +79,9 @@ function addTeamsExtension({ payload, extension, text }) {
*
* @param {object} param0 - the payload object
* @param {object} param0.payload - the payload object
* @param {import("..").Extension} param0.extension - the extension to add
* @param {import("..").IExtension} param0.extension - the extension to add
* @param {string} param0.text - the text to include
* @return {void}
* @return {void}
*/
function addChatExtension({ payload, extension, text }) {
let updated_text = text;
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/metadata.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function getMetaDataText(params) {
*
* @param {object} param0 - the payload object
* @param {Object} param0.elements - The elements to generate metadata text from
* @param {import('..').Target} param0.target - The result object
* @param {import('..').Extension} param0.extension - The result object
* @param {import('..').ITarget} param0.target - The result object
* @param {import('..').IExtension} param0.extension - The result object
* @param {Object} param0.result - The result object
* @param {string} param0.default_condition - The default condition object
* @return {string} The generated metadata text
Expand Down Expand Up @@ -50,8 +50,8 @@ async function getSlackMetaDataText({ elements, target, extension, result, defau
*
* @param {object} param0 - the payload object
* @param {Object} param0.elements - The elements to generate metadata text from
* @param {import('..').Target} param0.target - The result object
* @param {import('..').Extension} param0.extension - The result object
* @param {import('..').ITarget} param0.target - The result object
* @param {import('..').IExtension} param0.extension - The result object
* @param {Object} param0.result - The result object
* @param {string} param0.default_condition - The default condition object
* @return {string} The generated metadata text
Expand Down Expand Up @@ -82,8 +82,8 @@ async function getTeamsMetaDataText({ elements, target, extension, result, defau
*
* @param {object} param0 - the payload object
* @param {Object} param0.elements - The elements to generate metadata text from
* @param {import('..').Target} param0.target - The result object
* @param {import('..').Extension} param0.extension - The result object
* @param {import('..').ITarget} param0.target - The result object
* @param {import('..').IExtension} param0.extension - The result object
* @param {Object} param0.result - The result object
* @param {string} param0.default_condition - The default condition object
* @return {string} The generated metadata text
Expand Down
58 changes: 32 additions & 26 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@ import { Schedule, User } from 'rosters';
import { ParseOptions } from 'test-results-parser';
import TestResult from 'test-results-parser/src/models/TestResult';

export interface ITarget {
name: TargetName;
enable?: string | boolean;
condition?: Condition;
inputs?: SlackInputs | TeamsInputs | ChatInputs | CustomTargetInputs | InfluxDBTargetInputs;
extensions?: IExtension[];
}

export interface IExtension {
name: ExtensionName;
enable?: string | boolean;
condition?: Condition;
hook?: Hook;
inputs?: ReportPortalAnalysisInputs | ReportPortalHistoryInputs | HyperlinkInputs | MentionInputs | QuickChartTestSummaryInputs | PercyAnalysisInputs | CustomExtensionInputs | MetadataInputs | CIInfoInputs | AIFailureSummaryInputs;
}

export type ExtensionName = 'report-portal-analysis' | 'hyperlinks' | 'mentions' | 'report-portal-history' | 'quick-chart-test-summary' | 'metadata' | 'ci-info' | 'custom' | 'ai-failure-summary';
export type Hook = 'start' | 'end' | 'after-summary';
export type TargetName = 'slack' | 'teams' | 'chat' | 'custom' | 'delay';
export type PublishReportType = 'test-summary' | 'test-summary-slim' | 'failure-details';

export interface ConditionFunctionContext {
target: Target;
extension?: Extension,
target: ITarget;
extension?: IExtension,
result: TestResult;
}
export type ConditionFunction = (ctx: ConditionFunctionContext) => boolean | Promise<boolean>;
Expand Down Expand Up @@ -67,12 +83,7 @@ export interface AIFailureSummaryInputs extends ExtensionInputs {
failure_summary: string;
}

export interface Extension {
name: ExtensionName;
condition?: Condition;
hook?: Hook;
inputs?: ReportPortalAnalysisInputs | ReportPortalHistoryInputs | HyperlinkInputs | MentionInputs | QuickChartTestSummaryInputs | PercyAnalysisInputs | CustomExtensionInputs | MetadataInputs | CIInfoInputs | AIFailureSummaryInputs;
}


export interface PercyAnalysisInputs extends ExtensionInputs {
url?: string;
Expand All @@ -90,14 +101,14 @@ export interface PercyAnalysisOutputs {
project?: object;
}

export interface PercyAnalysisExtension extends Extension {
export interface PercyAnalysisExtension extends IExtension {
inputs?: PercyAnalysisInputs;
outputs?: PercyAnalysisOutputs;
}

export interface CustomExtensionFunctionContext {
target: Target;
extension: Extension,
target: ITarget;
extension: IExtension,
result: TestResult;
payload: any;
root_payload: any;
Expand All @@ -109,13 +120,13 @@ export interface CustomExtensionInputs extends ExtensionInputs {
load: string | CustomExtensionFunction;
}

export interface CustomExtension extends Extension {
export interface CustomExtension extends IExtension {
inputs?: CustomExtensionInputs;
outputs?: any;
}

export interface LinkUrlFunctionContext {
target: Target;
target: ITarget;
extension: HyperlinksExtension,
result: TestResult;
}
Expand All @@ -132,7 +143,7 @@ export interface HyperlinkInputs extends ExtensionInputs {
links: Link[];
}

export interface HyperlinksExtension extends Extension {
export interface HyperlinksExtension extends IExtension {
inputs?: HyperlinkInputs;
}

Expand All @@ -148,7 +159,7 @@ export interface MetadataInputs extends ExtensionInputs {
data?: Metadata[];
}

export interface MetadataExtension extends Extension {
export interface MetadataExtension extends IExtension {
inputs?: MetadataInputs;
}

Expand Down Expand Up @@ -202,7 +213,7 @@ export interface InfluxDBTargetInputs {
}

export interface CustomTargetFunctionContext {
target: Target;
target: ITarget;
result: TestResult;
}

Expand All @@ -212,12 +223,7 @@ export interface CustomTargetInputs {
load: string | CustomTargetFunction;
}

export interface Target {
name: TargetName;
condition?: Condition;
inputs?: SlackInputs | TeamsInputs | ChatInputs | CustomTargetInputs | InfluxDBTargetInputs;
extensions?: Extension[];
}


export interface CustomResultOptions {
type: string;
Expand All @@ -232,17 +238,17 @@ export interface PublishReport {
show_failure_analysis?: boolean;
show_smart_analysis?: boolean;
show_error_clusters?: boolean;
targets?: Target[];
extensions?: Extension[];
targets?: ITarget[];
extensions?: IExtension[];
results?: ParseOptions[] | PerformanceParseOptions[] | CustomResultOptions[];
}

export interface PublishConfig {
api_key?: string;
project?: string;
run?: string;
targets?: Target[];
extensions?: Extension[];
targets?: ITarget[];
extensions?: IExtension[];
results?: ParseOptions[] | PerformanceParseOptions[] | CustomResultOptions[];
}

Expand Down
6 changes: 3 additions & 3 deletions src/platforms/base.platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BasePlatform {

/**
*
* @param {import('..').Target} target
* @param {import('..').ITarget} target
* @param {import('test-results-parser').ITestSuite} suite
*/
getSuiteSummaryText(target, suite) {
Expand Down Expand Up @@ -74,7 +74,7 @@ class BasePlatform {

/**
*
* @param {import('..').Target} target
* @param {import('..').ITarget} target
* @param {import('test-results-parser').ITestSuite} suite
*/
#getSuiteDurationText(target, suite) {
Expand All @@ -84,7 +84,7 @@ class BasePlatform {

/**
*
* @param {import('..').Target} target
* @param {import('..').ITarget} target
* @param {import('test-results-parser').ITestSuite} suite
*/
getSuiteDuration(target, suite) {
Expand Down
6 changes: 3 additions & 3 deletions src/targets/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const path = require('path');
const { STATUS } = require('../helpers/constants');

/**
*
* @param {object} param0
* @param {import('../index').Target} param0.target
*
* @param {object} param0
* @param {import('../index').ITarget} param0.target
*/
async function run({result, target}) {
if (typeof target.inputs.load === 'string') {
Expand Down
Loading

0 comments on commit 0f46f6d

Please sign in to comment.