Skip to content

Commit

Permalink
EPMRPP-89644 || Implement attachments support
Browse files Browse the repository at this point in the history
  • Loading branch information
AliakseiLiasnitski committed Feb 28, 2024
1 parent 944e183 commit e999603
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/

import { RPReporter } from './reporter';
import { ReportingApi } from './reportingApi';
import { LOG_LEVELS, STATUSES } from './constants';

export { RPReporter };

export { RPReporter, ReportingApi, LOG_LEVELS, STATUSES };
export default RPReporter;
4 changes: 4 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
FinishTestItemObjType,
LogRQ,
Attachment,
RPTaskMeta,
ReportingApi,
} from './reporting';
import { ReportPortalConfig } from './configs';
import { Attribute } from './common';
Expand All @@ -32,5 +34,7 @@ export {
ReportPortalConfig,
Attachment,
Attribute,
RPTaskMeta,
ReportingApi,
LogRQ,
};
12 changes: 11 additions & 1 deletion src/models/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*
*/

import { Task, TaskMeta } from "vitest";

Check failure on line 17 in src/models/reporting.ts

View workflow job for this annotation

GitHub Actions / test

Task not found in 'vitest'

Check failure on line 17 in src/models/reporting.ts

View workflow job for this annotation

GitHub Actions / test

TaskMeta not found in 'vitest'

Check failure on line 17 in src/models/reporting.ts

View workflow job for this annotation

GitHub Actions / test

Replace `"vitest"` with `'vitest'`
import { Attribute, Issue } from './common';
import { TEST_ITEM_TYPES, LOG_LEVELS, LAUNCH_MODES } from '../constants';

Expand Down Expand Up @@ -61,3 +61,13 @@ export interface LogRQ {
time?: number;
file?: Attachment;
}

export interface RPTaskMeta extends TaskMeta {
test: {
logs: LogRQ[];
}

Check failure on line 68 in src/models/reporting.ts

View workflow job for this annotation

GitHub Actions / test

Insert `;`
}

export interface ReportingApi {
attachment: (context: Task, data: Attachment) => void;
}
10 changes: 9 additions & 1 deletion src/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
ReportPortalConfig,
StartLaunchObjType,
StartTestObjType,
RPTaskMeta,

Check failure on line 28 in src/reporter.ts

View workflow job for this annotation

GitHub Actions / test

'RPTaskMeta' is defined but never used
} from './models';
import {
getAgentInfo,
Expand All @@ -33,6 +34,7 @@ import {
getCodeRef,
getBasePath,
isErrorLog,
isRPTaskMeta,
} from './utils';
import {
LAUNCH_MODES,
Expand Down Expand Up @@ -165,13 +167,19 @@ export class RPReporter implements Reporter {
const packsReversed = [...packs];
packsReversed.reverse();

for (const [id, taskResult] of packsReversed) {
for (const [id, taskResult, meta] of packsReversed) {
const testItem = this.testItems.get(id);
const { id: testItemId, finishSend } = testItem || {};
if (!testItemId || finishSend || !FINISHED_STATES.includes(taskResult?.state)) {
continue;
}

if (isRPTaskMeta(meta)) {
meta.test.logs.forEach(logRq => {

Check failure on line 178 in src/reporter.ts

View workflow job for this annotation

GitHub Actions / test

Replace `logRq` with `(logRq)`
this.sendLog(testItemId, logRq);
})

Check failure on line 180 in src/reporter.ts

View workflow job for this annotation

GitHub Actions / test

Insert `;`
}

const finishTestItemObj = this.getFinishTestItemObj(taskResult);

if (taskResult?.errors?.length) {
Expand Down
25 changes: 25 additions & 0 deletions src/reportingApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Task } from "vitest";

Check failure on line 1 in src/reportingApi.ts

View workflow job for this annotation

GitHub Actions / test

Task not found in 'vitest'

Check failure on line 1 in src/reportingApi.ts

View workflow job for this annotation

GitHub Actions / test

Replace `"vitest"` with `'vitest'`
import * as Models from './models';
import { isRPTaskMeta } from './utils';

const injectRPTaskMeta = (task: Task) => {
if (isRPTaskMeta(task.meta)) {
return

Check failure on line 7 in src/reportingApi.ts

View workflow job for this annotation

GitHub Actions / test

Insert `;`
}

(task.meta as Models.RPTaskMeta) = {
...task.meta,
test: {
logs: [],
}
}
}

const attachment = (task: Task, data: Models.Attachment) => {
injectRPTaskMeta(task);
(task.meta as Models.RPTaskMeta).test.logs.push({ file: data, time: Date.now() });
}

export const ReportingApi: Models.ReportingApi = {
attachment
}
5 changes: 5 additions & 0 deletions src/types/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*
*/
import { Task } from "vitest";

declare namespace Interfaces {
interface Attribute {
Expand All @@ -38,4 +39,8 @@ declare namespace Interfaces {
interface ObjUniversal {
[name: string]: string;
}

interface ReportingApi {
attachment: (task: Task, data: Attachment) => void;
}
}
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
*/

import { normalize, sep } from 'node:path';
import { TaskMeta } from 'vitest';
// @ts-ignore
import { name as pjsonName, version as pjsonVersion } from '../package.json';
import { Attribute } from './models';
import { Attribute, RPTaskMeta } from './models';

export const isFalse = (value: string | boolean | undefined): boolean =>
[false, 'false'].includes(value);
Expand Down Expand Up @@ -63,3 +64,5 @@ export const getCodeRef = (basePath: string, itemTitle: string): string =>
export const isErrorLog = (message: string): boolean => {
return message.toLowerCase().includes('error');
};

export const isRPTaskMeta = (meta: TaskMeta | RPTaskMeta): meta is RPTaskMeta => 'test' in meta;

0 comments on commit e999603

Please sign in to comment.