@itwin/build-tools 4.0.0-dev.48 → 4.0.0-dev.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mocha-reporter/index.js +96 -96
- package/package.json +1 -1
package/mocha-reporter/index.js
CHANGED
@@ -1,96 +1,96 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
/*---------------------------------------------------------------------------------------------
|
4
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
5
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
6
|
-
*--------------------------------------------------------------------------------------------*/
|
7
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
8
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
9
|
-
/* eslint-disable no-console */
|
10
|
-
const debugLeaks = process.env.DEBUG_LEAKS;
|
11
|
-
if (debugLeaks)
|
12
|
-
require("wtfnode");
|
13
|
-
const path = require("path");
|
14
|
-
const fs = require("fs-extra");
|
15
|
-
const { logBuildWarning, logBuildError, failBuild } = require("../scripts/utils/utils");
|
16
|
-
const Base = require("mocha/lib/reporters/base");
|
17
|
-
const Spec = require("mocha/lib/reporters/spec");
|
18
|
-
const MochaJUnitReporter = require("mocha-junit-reporter");
|
19
|
-
function withStdErr(callback) {
|
20
|
-
const originalConsoleLog = Base.consoleLog;
|
21
|
-
Base.consoleLog = console.error;
|
22
|
-
callback();
|
23
|
-
Base.consoleLog = originalConsoleLog;
|
24
|
-
}
|
25
|
-
const isCI = process.env.CI || process.env.TF_BUILD;
|
26
|
-
// Force rush test to fail CI builds if describe.only or it.only is used.
|
27
|
-
// These should only be used for debugging and must not be committed, otherwise we may be accidentally skipping lots of tests.
|
28
|
-
if (isCI) {
|
29
|
-
if (typeof (mocha) !== "undefined")
|
30
|
-
mocha.forbidOnly();
|
31
|
-
else
|
32
|
-
require.cache[require.resolve("mocha/lib/mocharc.json", { paths: require.main?.paths ?? module.paths })].exports.forbidOnly = true;
|
33
|
-
}
|
34
|
-
// This is necessary to enable colored output when running in rush test:
|
35
|
-
Object.defineProperty(Base, "color", {
|
36
|
-
get: () => process.env.FORCE_COLOR !== "false" && process.env.FORCE_COLOR !== "0",
|
37
|
-
set: () => { },
|
38
|
-
});
|
39
|
-
class BentleyMochaReporter extends Spec {
|
40
|
-
constructor(_runner, _options) {
|
41
|
-
super(...arguments);
|
42
|
-
this._junitReporter = new MochaJUnitReporter(...arguments);
|
43
|
-
}
|
44
|
-
epilogue(...args) {
|
45
|
-
// Force test errors to be printed to stderr instead of stdout.
|
46
|
-
// This will allow rush to correctly summarize test failure when running rush test.
|
47
|
-
if (this.stats.failures) {
|
48
|
-
withStdErr(() => super.epilogue(...args));
|
49
|
-
}
|
50
|
-
else {
|
51
|
-
super.epilogue(...args);
|
52
|
-
if (0 === this.stats.passes) {
|
53
|
-
logBuildError("There were 0 passing tests. That doesn't seem right."
|
54
|
-
+ "\nIf there are really no passing tests and no failures, then what was even the point?"
|
55
|
-
+ "\nIt seems likely that tests were skipped by it.only, it.skip, or grep filters, so I'm going to fail now.");
|
56
|
-
failBuild();
|
57
|
-
}
|
58
|
-
}
|
59
|
-
// Detect hangs caused by tests that leave timers/other handles open - not possible in electron frontends.
|
60
|
-
if (!("electron" in process.versions)) {
|
61
|
-
// NB: By calling unref() on this timer, we stop it from keeping the process alive, so it will only fire if _something else_ is still keeping
|
62
|
-
// the process alive after 5 seconds. This also has the benefit of preventing the timer from showing up in wtfnode's dump of open handles.
|
63
|
-
setTimeout(() => {
|
64
|
-
logBuildError(`Handle leak detected. Node was still running 5 seconds after tests completed.`);
|
65
|
-
if (debugLeaks) {
|
66
|
-
const wtf = require("wtfnode");
|
67
|
-
wtf.setLogger("info", console.error);
|
68
|
-
wtf.dump();
|
69
|
-
}
|
70
|
-
else {
|
71
|
-
console.error("Try running with the DEBUG_LEAKS env var set to see open handles.");
|
72
|
-
}
|
73
|
-
// Not sure why, but process.exit(1) wasn't working here...
|
74
|
-
process.kill(process.pid);
|
75
|
-
}, 5000).unref();
|
76
|
-
}
|
77
|
-
if (!this.stats.pending)
|
78
|
-
return;
|
79
|
-
// Also log warnings in CI builds when tests have been skipped.
|
80
|
-
const currentPkgJson = path.join(process.cwd(), "package.json");
|
81
|
-
if (fs.existsSync(currentPkgJson)) {
|
82
|
-
const currentPackage = require(currentPkgJson).name;
|
83
|
-
if (this.stats.pending === 1)
|
84
|
-
logBuildWarning(`1 test skipped in ${currentPackage}`);
|
85
|
-
else
|
86
|
-
logBuildWarning(`${this.stats.pending} tests skipped in ${currentPackage}`);
|
87
|
-
}
|
88
|
-
else {
|
89
|
-
if (this.stats.pending === 1)
|
90
|
-
logBuildWarning(`1 test skipped`);
|
91
|
-
else
|
92
|
-
logBuildWarning(`${this.stats.pending} tests skipped`);
|
93
|
-
}
|
94
|
-
}
|
95
|
-
}
|
96
|
-
module.exports = BentleyMochaReporter;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
/*---------------------------------------------------------------------------------------------
|
4
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
5
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
6
|
+
*--------------------------------------------------------------------------------------------*/
|
7
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
8
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
9
|
+
/* eslint-disable no-console */
|
10
|
+
const debugLeaks = process.env.DEBUG_LEAKS;
|
11
|
+
if (debugLeaks)
|
12
|
+
require("wtfnode");
|
13
|
+
const path = require("path");
|
14
|
+
const fs = require("fs-extra");
|
15
|
+
const { logBuildWarning, logBuildError, failBuild } = require("../scripts/utils/utils");
|
16
|
+
const Base = require("mocha/lib/reporters/base");
|
17
|
+
const Spec = require("mocha/lib/reporters/spec");
|
18
|
+
const MochaJUnitReporter = require("mocha-junit-reporter");
|
19
|
+
function withStdErr(callback) {
|
20
|
+
const originalConsoleLog = Base.consoleLog;
|
21
|
+
Base.consoleLog = console.error;
|
22
|
+
callback();
|
23
|
+
Base.consoleLog = originalConsoleLog;
|
24
|
+
}
|
25
|
+
const isCI = process.env.CI || process.env.TF_BUILD;
|
26
|
+
// Force rush test to fail CI builds if describe.only or it.only is used.
|
27
|
+
// These should only be used for debugging and must not be committed, otherwise we may be accidentally skipping lots of tests.
|
28
|
+
if (isCI) {
|
29
|
+
if (typeof (mocha) !== "undefined")
|
30
|
+
mocha.forbidOnly();
|
31
|
+
else
|
32
|
+
require.cache[require.resolve("mocha/lib/mocharc.json", { paths: require.main?.paths ?? module.paths })].exports.forbidOnly = true;
|
33
|
+
}
|
34
|
+
// This is necessary to enable colored output when running in rush test:
|
35
|
+
Object.defineProperty(Base, "color", {
|
36
|
+
get: () => process.env.FORCE_COLOR !== "false" && process.env.FORCE_COLOR !== "0",
|
37
|
+
set: () => { },
|
38
|
+
});
|
39
|
+
class BentleyMochaReporter extends Spec {
|
40
|
+
constructor(_runner, _options) {
|
41
|
+
super(...arguments);
|
42
|
+
this._junitReporter = new MochaJUnitReporter(...arguments);
|
43
|
+
}
|
44
|
+
epilogue(...args) {
|
45
|
+
// Force test errors to be printed to stderr instead of stdout.
|
46
|
+
// This will allow rush to correctly summarize test failure when running rush test.
|
47
|
+
if (this.stats.failures) {
|
48
|
+
withStdErr(() => super.epilogue(...args));
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
super.epilogue(...args);
|
52
|
+
if (0 === this.stats.passes) {
|
53
|
+
logBuildError("There were 0 passing tests. That doesn't seem right."
|
54
|
+
+ "\nIf there are really no passing tests and no failures, then what was even the point?"
|
55
|
+
+ "\nIt seems likely that tests were skipped by it.only, it.skip, or grep filters, so I'm going to fail now.");
|
56
|
+
failBuild();
|
57
|
+
}
|
58
|
+
}
|
59
|
+
// Detect hangs caused by tests that leave timers/other handles open - not possible in electron frontends.
|
60
|
+
if (!("electron" in process.versions)) {
|
61
|
+
// NB: By calling unref() on this timer, we stop it from keeping the process alive, so it will only fire if _something else_ is still keeping
|
62
|
+
// the process alive after 5 seconds. This also has the benefit of preventing the timer from showing up in wtfnode's dump of open handles.
|
63
|
+
setTimeout(() => {
|
64
|
+
logBuildError(`Handle leak detected. Node was still running 5 seconds after tests completed.`);
|
65
|
+
if (debugLeaks) {
|
66
|
+
const wtf = require("wtfnode");
|
67
|
+
wtf.setLogger("info", console.error);
|
68
|
+
wtf.dump();
|
69
|
+
}
|
70
|
+
else {
|
71
|
+
console.error("Try running with the DEBUG_LEAKS env var set to see open handles.");
|
72
|
+
}
|
73
|
+
// Not sure why, but process.exit(1) wasn't working here...
|
74
|
+
process.kill(process.pid);
|
75
|
+
}, 5000).unref();
|
76
|
+
}
|
77
|
+
if (!this.stats.pending)
|
78
|
+
return;
|
79
|
+
// Also log warnings in CI builds when tests have been skipped.
|
80
|
+
const currentPkgJson = path.join(process.cwd(), "package.json");
|
81
|
+
if (fs.existsSync(currentPkgJson)) {
|
82
|
+
const currentPackage = require(currentPkgJson).name;
|
83
|
+
if (this.stats.pending === 1)
|
84
|
+
logBuildWarning(`1 test skipped in ${currentPackage}`);
|
85
|
+
else
|
86
|
+
logBuildWarning(`${this.stats.pending} tests skipped in ${currentPackage}`);
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
if (this.stats.pending === 1)
|
90
|
+
logBuildWarning(`1 test skipped`);
|
91
|
+
else
|
92
|
+
logBuildWarning(`${this.stats.pending} tests skipped`);
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
module.exports = BentleyMochaReporter;
|