Skip to content

Commit

Permalink
EPMRPP-89644 || Add setup file to add ReportingApi to the global vari…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
AliakseiLiasnitski committed Feb 28, 2024
1 parent 0ffa5fd commit 74b43f6
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@
"description": "Agent to integrate Vitest with ReportPortal.",
"main": "build/index.js",
"types": "build/index.d.ts",
"type": "module",
"exports": {
".": {
"import": "./build/index.js",
"require": "./build/index.js"
},
"./setup": {
"import": "./build/setup.js",
"require": "./build/setup.js"
}
},
"scripts": {
"build": "npm run clean && tsc",
"clean": "rimraf ./build",
Expand Down
2 changes: 2 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
Attachment,
RPTaskMeta,
ReportingApi,
GlobalReportingApi,
} from './reporting';
import { ReportPortalConfig } from './configs';
import { Attribute } from './common';
Expand All @@ -36,5 +37,6 @@ export {
Attribute,
RPTaskMeta,
ReportingApi,
GlobalReportingApi,
LogRQ,
};
4 changes: 4 additions & 0 deletions src/models/reporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,7 @@ export interface RPTaskMeta extends TaskMeta {
export interface ReportingApi {
attachment: (context: Task, data: Attachment) => void;
}

export interface GlobalReportingApi {
attachment: (data: Attachment) => void;
}
4 changes: 4 additions & 0 deletions src/reportingApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ const attachment = (task: Task, data: Models.Attachment) => {
export const ReportingApi: Models.ReportingApi = {
attachment
}

export const bindReportingApi = (task: Task): Models.GlobalReportingApi => ({
attachment: (data: Models.Attachment) => attachment(task, data)
})
12 changes: 12 additions & 0 deletions src/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { afterEach, beforeEach } from "vitest";
import { bindReportingApi } from "./reportingApi";

beforeEach(async (ctx) => {
// @ts-ignore
global.ReportingApi = bindReportingApi(ctx.task);
});

afterEach(() => {
// @ts-ignore
global.ReportingApi = undefined;
});
20 changes: 20 additions & 0 deletions src/types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*
*/

declare global {
export const ReportingApi: GlobalReportingApi;
}
4 changes: 4 additions & 0 deletions src/types/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ declare namespace Interfaces {
interface ReportingApi {
attachment: (task: Task, data: Attachment) => void;
}

interface GlobalReportingApi {
attachment: (data: Attachment) => void;
}
}

0 comments on commit 74b43f6

Please sign in to comment.