diff --git a/packages/allure-mocha/test/fixtures/runners/parallel.ts b/packages/allure-mocha/test/fixtures/runners/parallel.ts new file mode 100644 index 000000000..17cb8dd52 --- /dev/null +++ b/packages/allure-mocha/test/fixtures/runners/parallel.ts @@ -0,0 +1,14 @@ +import MochaAllureReporter from "allure-mocha"; +import glob from "glob"; +import Mocha from "mocha"; +import "source-map-support/register"; + +const mocha = new Mocha({ + timeout: 16000, + reporter: MochaAllureReporter, + parallel: true, +}); + +glob.sync("test/fixtures/specs/runtime.ts").forEach((file) => mocha.addFile(file)); + +mocha.run((failures) => process.exit(failures === 0 ? 0 : 1)); diff --git a/packages/allure-mocha/test/fixtures/runners/singleThread.ts b/packages/allure-mocha/test/fixtures/runners/singleThread.ts new file mode 100644 index 000000000..a27535cdb --- /dev/null +++ b/packages/allure-mocha/test/fixtures/runners/singleThread.ts @@ -0,0 +1,13 @@ +import MochaAllureReporter from "allure-mocha"; +import glob from "glob"; +import Mocha from "mocha"; +import "source-map-support/register"; + +const mocha = new Mocha({ + timeout: 16000, + reporter: MochaAllureReporter, +}); + +glob.sync("test/fixtures/specs/runtime.ts").forEach((file) => mocha.addFile(file)); + +mocha.run((failures) => process.exit(failures === 0 ? 0 : 1)); diff --git a/packages/allure-mocha/test/fixtures/specs/runtime.ts b/packages/allure-mocha/test/fixtures/specs/runtime.ts new file mode 100644 index 000000000..e4a6f8f8c --- /dev/null +++ b/packages/allure-mocha/test/fixtures/specs/runtime.ts @@ -0,0 +1,8 @@ +import { describe, it } from "mocha"; +import { allure } from "../../../runtime"; + +describe("runtime", () => { + it("assigns label", () => { + allure.label("foo", "bar"); + }); +}); diff --git a/packages/allure-mocha/test/specs/reporter.ts b/packages/allure-mocha/test/specs/reporter.ts new file mode 100644 index 000000000..d8dc7b265 --- /dev/null +++ b/packages/allure-mocha/test/specs/reporter.ts @@ -0,0 +1,41 @@ +import { spawnSync } from "node:child_process"; +import fs from "node:fs"; +import process from "node:process"; +import { expect } from "chai"; +import { beforeEach, describe, it } from "mocha"; +import { restore, stub } from "sinon"; + +describe("reporter", () => { + beforeEach(() => { + restore(); + stub(fs, "mkdirSync").callsFake(() => ""); + }); + + describe("parallel mode", () => { + it("prints warnings about allure api", () => { + const out = spawnSync( + "ts-node", + ["--project", "test/tsconfig.json", "test/fixtures/runners/parallel.ts"], + { + cwd: process.cwd(), + }, + ); + + expect(out.stderr.toString("utf8")).contains("can't be used in parallel mode"); + }); + }); + + describe("single thread mode", () => { + it("doesn't print any warning about allure api", () => { + const out = spawnSync( + "ts-node", + ["--project", "test/tsconfig.json", "test/fixtures/runners/singleThread.ts"], + { + cwd: process.cwd(), + }, + ); + + expect(out.stderr.toString("utf8")).not.contains("can't be used in parallel mode"); + }); + }); +});