@moroo/wdio-slack-reporter
Version:
Reporter from WebdriverIO using Incoming webhook and Web API to send results to Slack.
1 lines • 7.04 kB
Source Map (JSON)
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/**\n * Copyright (c) moroo\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { SuiteStats } from '@wdio/reporter';\n\nimport type { SLACK_REQUEST_TYPE, EVENTS } from './constants.js';\nimport type {\n ChatPostMessageArguments,\n FilesCompleteUploadExternalResponse,\n FilesUploadArguments,\n WebAPICallResult,\n WebClientOptions,\n} from '@slack/web-api';\nimport type {\n IncomingWebhookDefaultArguments,\n IncomingWebhookResult,\n IncomingWebhookSendArguments,\n} from '@slack/webhook';\nimport type { RunnerStats, TestStats } from '@wdio/reporter';\nimport type { Reporters } from '@wdio/types';\n\nexport class TimeoutError extends Error {\n public code: string;\n\n constructor(message: string) {\n super(message);\n this.name = 'TimeoutError';\n this.code = 'ETIMEDOUT';\n }\n}\n\n// ============================\n// 3. 클라이언트 관련 타입\n// ============================\n\nexport type FilesUploadV2Response = WebAPICallResult & {\n files: FilesCompleteUploadExternalResponse[];\n};\nexport interface SlackWebClientOptions extends WebClientOptions {\n token: string;\n}\n\nexport interface SlackIncomingWebhookOptions\n extends IncomingWebhookDefaultArguments {\n webhook: string;\n}\n\nexport type TestResultType = 'passed' | 'failed' | 'pending' | 'skipped';\n\nexport interface StateCount {\n passed: number;\n failed: number;\n skipped: number;\n}\n\nexport class CucumberStats extends SuiteStats {\n state: TestStats['state'] = 'pending';\n}\n\nexport interface EmojiSymbols {\n passed?: string;\n failed?: string;\n skipped?: string;\n pending?: string;\n start?: string;\n finished?: string;\n watch?: string;\n}\n\nexport interface SlackWebApiOptions extends SlackWebClientOptions {\n type: 'web-api';\n channel: string;\n /**\n * @deprecated This property is deprecated. Please use the inherited 'token' property instead. Will be removed in the next major version.\n */\n slackBotToken?: string;\n uploadScreenshotOfFailedCase?: boolean;\n notifyDetailResultThread?: boolean;\n filterForDetailResults?: TestResultType[];\n createScreenshotPayload?: (\n testStats: TestStats,\n screenshotBuffer: string | Buffer\n ) => FilesUploadArguments;\n createResultDetailPayload?: (\n runnerStats: RunnerStats,\n stateCounts: StateCount\n ) => ChatPostMessageArguments;\n}\n\nexport interface SlackWebhookOptions extends SlackIncomingWebhookOptions {\n type: 'webhook';\n /**\n * @deprecated This property is deprecated. Please use the inherited 'username' property instead. Will be removed in the next major version.\n */\n slackName?: string;\n /**\n * @deprecated This property is deprecated. Please use the inherited 'icon_url' property instead. Will be removed in the next major version.\n */\n slackIconUrl?: string;\n}\n\nexport type SlackOptions = SlackWebApiOptions | SlackWebhookOptions;\n\nexport interface SlackReporterOptions extends Reporters.Options {\n slackOptions?: SlackOptions;\n emojiSymbols?: EmojiSymbols;\n title?: string;\n resultsUrl?: string;\n notifyFailedCase?: boolean;\n notifyTestStartMessage?: boolean;\n notifyTestFinishMessage?: boolean;\n useScenarioBasedStateCounts?: boolean;\n createStartPayload?: (\n runnerStats: RunnerStats\n ) => ChatPostMessageArguments | IncomingWebhookSendArguments;\n createFailedTestPayload?: (\n testStats: TestStats\n ) => ChatPostMessageArguments | IncomingWebhookSendArguments;\n createResultPayload?: (\n runnerStats: RunnerStats,\n stateCounts: StateCount\n ) => ChatPostMessageArguments | IncomingWebhookSendArguments;\n}\n\nexport interface FilesUploadV2Options {\n waitForUpload?: boolean;\n timeout?: number;\n interval?: number;\n}\n\nexport type SlackRequestType = PostMessage | Upload | Send;\n\ninterface PostMessage {\n type: typeof SLACK_REQUEST_TYPE.WEB_API_POST_MESSAGE;\n payload: ChatPostMessageArguments;\n isDetailResult?: boolean;\n}\n\ninterface Upload {\n type: typeof SLACK_REQUEST_TYPE.WEB_API_UPLOAD;\n payload: FilesUploadArguments;\n options?: FilesUploadV2Options;\n}\n\ninterface Send {\n type: typeof SLACK_REQUEST_TYPE.WEBHOOK_SEND;\n payload: IncomingWebhookSendArguments;\n}\n\n// global declarations moved from index.ts\ndeclare global {\n namespace WebdriverIO {\n interface ReporterOption extends SlackReporterOptions {}\n }\n\n namespace NodeJS {\n interface Process {\n emit(\n event: typeof EVENTS.POST_MESSAGE,\n payload: ChatPostMessageArguments\n ): boolean;\n emit(\n event: typeof EVENTS.UPLOAD,\n args: {\n payload: FilesUploadArguments;\n options?: FilesUploadV2Options;\n }\n ): Promise<\n WebAPICallResult & {\n files: FilesCompleteUploadExternalResponse[];\n }\n >;\n emit(\n event: typeof EVENTS.SEND,\n payload: IncomingWebhookSendArguments\n ): boolean;\n emit(\n event: typeof EVENTS.SCREENSHOT,\n args: {\n buffer: string | Buffer;\n }\n ): boolean;\n emit(\n event: typeof EVENTS.RESULT,\n args: {\n result:\n | WebAPICallResult\n | IncomingWebhookResult\n | (WebAPICallResult & {\n files: FilesCompleteUploadExternalResponse[];\n })\n | undefined;\n error: any;\n }\n ): boolean;\n\n on(\n event: typeof EVENTS.POST_MESSAGE,\n listener: (\n payload: ChatPostMessageArguments\n ) => Promise<WebAPICallResult>\n ): this;\n on(\n event: typeof EVENTS.UPLOAD,\n listener: (args: {\n payload: FilesUploadArguments;\n options?: FilesUploadV2Options;\n }) => Promise<\n WebAPICallResult & {\n files: FilesCompleteUploadExternalResponse[];\n }\n >\n ): this;\n on(\n event: typeof EVENTS.SEND,\n listener: (\n payload: IncomingWebhookSendArguments\n ) => Promise<IncomingWebhookResult>\n ): this;\n on(\n event: typeof EVENTS.SCREENSHOT,\n listener: (args: { buffer: string | Buffer }) => void\n ): this;\n once(\n event: typeof EVENTS.RESULT,\n listener: (args: {\n result:\n | WebAPICallResult\n | IncomingWebhookResult\n | (WebAPICallResult & {\n files: FilesCompleteUploadExternalResponse[];\n })\n | undefined;\n error: any;\n }) => Promise<void>\n ): this;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,sBAA2B;AAkBpB,MAAM,qBAAqB,MAAM;AAAA,EAC/B;AAAA,EAEP,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;AA0BO,MAAM,sBAAsB,2BAAW;AAAA,EAC5C,QAA4B;AAC9B;","names":[]}