Skip to content

Commit

Permalink
add test for mocha runtime api stub
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw committed Feb 27, 2023
1 parent 5ef42af commit e72d509
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/allure-mocha/test/fixtures/runners/parallel.ts
Original file line number Diff line number Diff line change
@@ -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));
13 changes: 13 additions & 0 deletions packages/allure-mocha/test/fixtures/runners/singleThread.ts
Original file line number Diff line number Diff line change
@@ -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));
8 changes: 8 additions & 0 deletions packages/allure-mocha/test/fixtures/specs/runtime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { describe, it } from "mocha";
import { allure } from "../../../runtime";

describe("runtime", () => {
it("assigns label", () => {
allure.label("foo", "bar");
});
});
41 changes: 41 additions & 0 deletions packages/allure-mocha/test/specs/reporter.ts
Original file line number Diff line number Diff line change
@@ -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");
});
});
});

0 comments on commit e72d509

Please sign in to comment.