1 | "use strict";
|
2 | var _a, _b;
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const path = require("path");
|
12 | const fs = require("fs-extra");
|
13 | const { logBuildWarning, logBuildError, failBuild } = require("../scripts/rush/utils");
|
14 | const Base = require("mocha/lib/reporters/base");
|
15 | const Spec = require("mocha/lib/reporters/spec");
|
16 | const MochaJUnitReporter = require("mocha-junit-reporter");
|
17 | function withStdErr(callback) {
|
18 | const originalConsoleLog = console.log;
|
19 | console.log = console.error;
|
20 | callback();
|
21 | console.log = originalConsoleLog;
|
22 | }
|
23 | const isCI = process.env.CI || process.env.TF_BUILD;
|
24 |
|
25 |
|
26 | if (isCI) {
|
27 | if (typeof (mocha) !== "undefined")
|
28 | mocha.forbidOnly();
|
29 | else
|
30 | require.cache[require.resolve("mocha/lib/mocharc.json", { paths: (_b = (_a = require.main) === null || _a === void 0 ? void 0 : _a.paths) !== null && _b !== void 0 ? _b : module.paths })].exports.forbidOnly = true;
|
31 | }
|
32 |
|
33 | Object.defineProperty(Base, "color", {
|
34 | get: () => process.env.FORCE_COLOR !== "false" && process.env.FORCE_COLOR !== "0",
|
35 | set: () => { },
|
36 | });
|
37 | class BentleyMochaReporter extends Spec {
|
38 | constructor(_runner, _options) {
|
39 | super(...arguments);
|
40 | this._junitReporter = new MochaJUnitReporter(...arguments);
|
41 | }
|
42 | epilogue(...args) {
|
43 |
|
44 |
|
45 | if (this.stats.failures) {
|
46 | withStdErr(() => super.epilogue(...args));
|
47 | }
|
48 | else {
|
49 | super.epilogue(...args);
|
50 | if (0 === this.stats.passes) {
|
51 | logBuildError("There were 0 passing tests. That doesn't seem right."
|
52 | + "\nIf there are really no passing tests and no failures, then what was even the point?"
|
53 | + "\nIt seems likely that tests were skipped by it.only, it.skip, or grep filters, so I'm going to fail now.");
|
54 | failBuild();
|
55 | }
|
56 | }
|
57 | if (!this.stats.pending)
|
58 | return;
|
59 |
|
60 | const currentPkgJson = path.join(process.cwd(), "package.json");
|
61 | if (fs.existsSync(currentPkgJson)) {
|
62 | const currentPackage = require(currentPkgJson).name;
|
63 | if (this.stats.pending === 1)
|
64 | logBuildWarning(`1 test skipped in ${currentPackage}`);
|
65 | else
|
66 | logBuildWarning(`${this.stats.pending} tests skipped in ${currentPackage}`);
|
67 | }
|
68 | else {
|
69 | if (this.stats.pending === 1)
|
70 | logBuildWarning(`1 test skipped`);
|
71 | else
|
72 | logBuildWarning(`${this.stats.pending} tests skipped`);
|
73 | }
|
74 | }
|
75 | }
|
76 | module.exports = BentleyMochaReporter;
|