import path from 'node:path' import { log } from 'node:console' import { describe, it, expect, afterEach, beforeEach, beforeAll, afterAll, vi } from 'vitest' import type { Label, Parameter, Link, Attachment } from 'allure-js-commons' import { LabelName } from 'allure-js-commons' import { Status, LinkType, Stage } from 'allure-js-commons' import { temporaryDirectory } from 'tempy' import AllureReporter from '../src/reporter.js' import { TYPE } from '../src/types.js' /** * this is not a real package and only used to utilize helper * methods without having to ignore them for test coverage */ import { clean, getResults, mapBy } from './helpers/wdio-allure-helper.js' import { runnerEnd, runnerStart } from './__fixtures__/runner.js' import { suiteEnd, suiteStart } from './__fixtures__/suite.js' import { testFailed, testPending, testStart, testFailedWithMultipleErrors, testFailedWithMultipleErrorsAndStacksNotContainingMessages, hookStart, hookFailed, testFailedWithAssertionErrorFromExpectWebdriverIO, eachHookFailed, eachHookStart } from './__fixtures__/testState.js' import { commandStart, commandEnd, commandEndScreenShot, commandStartScreenShot } from './__fixtures__/command.js' import type { AfterCommandArgs, BeforeCommandArgs } from '@wdio/reporter' vi.mock('@wdio/reporter', () => import(path.join(process.cwd(), '__mocks__', '@wdio/reporter'))) let processOn: any beforeAll(() => { processOn = process.on.bind(process) process.on = vi.fn() }) afterAll(() => { process.on = processOn }) describe('Passing tests', () => { const outputDir = temporaryDirectory() let allureResult: Record let allureContainer: Record let allureEnvInfo: Record beforeAll(() => { const reporter = new AllureReporter({ outputDir, issueLinkTemplate: 'https://example.org/issues/{}', tmsLinkTemplate: 'https://example.org/tests/{}', reportedEnvironmentVars:{ jenkins: '1.2.3', OS: 'Mocked' } }) const step = { step: { attachment: { content: 'baz', name: 'attachment' }, status: Status.FAILED, title: 'foo' } } reporter.onRunnerStart(runnerStart()) reporter.onSuiteStart(suiteStart()) reporter.onTestStart(testStart()) reporter.addLabel({ name: 'customLabel', value: 'Label' }) reporter.addStory({ storyName: 'Story' }) reporter.addFeature({ featureName: 'foo' }) reporter.addSeverity({ severity: 'baz' }) reporter.addIssue({ issue: '1' }) reporter.addTestId({ testId: '2' }) reporter.addDescription({ description: 'functions', descriptionType: TYPE.HTML }) reporter.addAttachment({ name: 'My attachment', content: '99thoughtz', type: 'text/plain' }) reporter.addArgument({ name: 'os', value: 'osx' }) reporter.startStep('bar') reporter.endStep(Status.PASSED) reporter.addStep(step) reporter.onTestPass() reporter.onSuiteEnd(suiteEnd()) reporter.onRunnerEnd(runnerEnd()) const { results, containers, environmentInfo } = getResults(outputDir) expect(results).toHaveLength(1) expect(containers).toHaveLength(1) expect(Object.values(environmentInfo)).toHaveLength(2) allureResult = results[0] allureContainer = containers[0] allureEnvInfo = environmentInfo }) afterAll(() => { clean(outputDir) }) it('should report one suite', () => { expect(allureContainer.name).toEqual('A passing Suite') }) it('should detect passed test case', () => { expect(allureResult.name).toEqual('should can do something') expect(allureResult.status).toEqual(Status.PASSED) }) it('should detect analytics labels in test case', () => { const labels = mapBy