diff --git a/package.json b/package.json index e1ac6c4..3c8ef17 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/models/index.ts b/src/models/index.ts index f5d4968..516d5aa 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -23,6 +23,7 @@ import { Attachment, RPTaskMeta, ReportingApi, + GlobalReportingApi, } from './reporting'; import { ReportPortalConfig } from './configs'; import { Attribute } from './common'; @@ -36,5 +37,6 @@ export { Attribute, RPTaskMeta, ReportingApi, + GlobalReportingApi, LogRQ, }; diff --git a/src/models/reporting.ts b/src/models/reporting.ts index 63b8fee..b73e77a 100644 --- a/src/models/reporting.ts +++ b/src/models/reporting.ts @@ -72,3 +72,7 @@ export interface RPTaskMeta extends TaskMeta { export interface ReportingApi { attachment: (context: Task, data: Attachment, description?: string) => void; } + +export interface GlobalReportingApi { + attachment: (data: Attachment) => void; +} diff --git a/src/reportingApi.ts b/src/reportingApi.ts index 4e1281f..cd6d92a 100644 --- a/src/reportingApi.ts +++ b/src/reportingApi.ts @@ -27,4 +27,8 @@ const attachment = (task: Task, data: Models.Attachment, description?: string) = export const ReportingApi: Models.ReportingApi = { attachment, -}; +} + +export const bindReportingApi = (task: Task): Models.GlobalReportingApi => ({ + attachment: (data: Models.Attachment) => attachment(task, data) +}) diff --git a/src/setup.ts b/src/setup.ts new file mode 100644 index 0000000..d80afb0 --- /dev/null +++ b/src/setup.ts @@ -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; +}); diff --git a/src/types/global.d.ts b/src/types/global.d.ts new file mode 100644 index 0000000..fd485bb --- /dev/null +++ b/src/types/global.d.ts @@ -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; +} diff --git a/src/types/interfaces.d.ts b/src/types/interfaces.d.ts index 36bfc30..fa55e34 100644 --- a/src/types/interfaces.d.ts +++ b/src/types/interfaces.d.ts @@ -44,4 +44,8 @@ declare namespace Interfaces { interface ReportingApi { attachment: (task: Task, data: Attachment, description?: string) => void; } + + interface GlobalReportingApi { + attachment: (data: Attachment) => void; + } }