diff --git a/packages/allure-mocha/test/samples/customReporter.cjs b/packages/allure-mocha/test/samples/customReporter.cjs new file mode 100644 index 000000000..97b63a6ee --- /dev/null +++ b/packages/allure-mocha/test/samples/customReporter.cjs @@ -0,0 +1,13 @@ +const Mocha = require("mocha"); + +class CustomReporter extends Mocha.reporters.Base { + constructor(runner, opts) { + super(runner, opts); + runner.on("start", () => { + // eslint-disable-next-line no-console + console.log(JSON.stringify(opts.reporterOptions)); + }); + } +} + +module.exports = CustomReporter; diff --git a/packages/allure-mocha/test/spec/framework/extraReporters.test.ts b/packages/allure-mocha/test/spec/framework/extraReporters.test.ts index bd449137b..b7c83fdd0 100644 --- a/packages/allure-mocha/test/spec/framework/extraReporters.test.ts +++ b/packages/allure-mocha/test/spec/framework/extraReporters.test.ts @@ -206,6 +206,34 @@ describe("extra reporters", () => { }); }); + describe("local reporter", () => { + test("local reporter without options", async () => { + const { tests, stdout } = await runMochaInlineTest( + { + extraReporters: "./customReporter.cjs", + inputFiles: ["customReporter.cjs"], + }, + "plain-mocha/testInSuite", + ); + + expect(tests).toEqual([expect.objectContaining({ name: "a test in a suite" })]); + expect(JSON.parse(stdout.join(""))).toEqual({}); + }); + + test("local reporter with options", async () => { + const { tests, stdout } = await runMochaInlineTest( + { + extraReporters: ["./customReporter.cjs", { foo: "bar" }], + inputFiles: ["customReporter.cjs"], + }, + "plain-mocha/testInSuite", + ); + + expect(tests).toEqual([expect.objectContaining({ name: "a test in a suite" })]); + expect(JSON.parse(stdout.join(""))).toEqual({ foo: "bar" }); + }); + }); + describe("errors", () => { test("a reporter must be a string", async () => { const { exitCode, stderr } = await runMochaInlineTest( diff --git a/packages/allure-mocha/test/utils.ts b/packages/allure-mocha/test/utils.ts index bda123d88..c80060c6a 100644 --- a/packages/allure-mocha/test/utils.ts +++ b/packages/allure-mocha/test/utils.ts @@ -13,6 +13,7 @@ type MochaRunOptions = { environmentInfo?: { [keys: string]: string }; categories?: readonly Category[]; extraReporters?: AllureMochaReporterConfig["extraReporters"]; + inputFiles?: string[]; outputFiles?: Record; }; @@ -88,7 +89,10 @@ abstract class AllureMochaTestRunner { const testDir = path.join(this.runResultsDir, randomUUID()); - const filesToCopy = [...this.getFilesToCopy(testDir)]; + const filesToCopy = [ + ...this.getFilesToCopy(testDir), + ...(this.config.inputFiles?.map((f) => this.getCopyEntry(f, testDir)) ?? []), + ]; const filesToTransform = [ ...this.getFilesToTransform(testDir), ...samples.map((sample) => this.#getSampleEntry(sample, this.specsPath, testDir)),