@itwin/build-tools 4.0.0-dev.51 → 4.0.0-dev.54
Sign up to get free protection for your applications and to get access to all the features.
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;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@itwin/build-tools",
|
3
|
-
"version": "4.0.0-dev.
|
3
|
+
"version": "4.0.0-dev.54",
|
4
4
|
"description": "Bentley build tools",
|
5
5
|
"license": "MIT",
|
6
6
|
"repository": {
|
@@ -20,7 +20,7 @@
|
|
20
20
|
"url": "http://www.bentley.com"
|
21
21
|
},
|
22
22
|
"dependencies": {
|
23
|
-
"@microsoft/api-extractor": "7.
|
23
|
+
"@microsoft/api-extractor": "7.34.4",
|
24
24
|
"chalk": "^3.0.0",
|
25
25
|
"cpx2": "^3.0.0",
|
26
26
|
"cross-spawn": "^7.0.1",
|
@@ -32,12 +32,12 @@
|
|
32
32
|
"tree-kill": "^1.2.0",
|
33
33
|
"typedoc": "^0.22.11",
|
34
34
|
"typedoc-plugin-merge-modules": "^3.0.2",
|
35
|
-
"typescript": "~
|
35
|
+
"typescript": "~5.0.2",
|
36
36
|
"wtfnode": "^0.9.1",
|
37
37
|
"yargs": "^17.4.0"
|
38
38
|
},
|
39
39
|
"devDependencies": {
|
40
|
-
"@itwin/eslint-plugin": "
|
40
|
+
"@itwin/eslint-plugin": "^4.0.0-dev.32",
|
41
41
|
"@types/node": "^18.11.5",
|
42
42
|
"eslint": "^7.11.0"
|
43
43
|
},
|
package/scripts/docs.js
CHANGED
@@ -12,7 +12,7 @@ const cpx = require("cpx2");
|
|
12
12
|
const fs = require("fs");
|
13
13
|
const { spawn, handleInterrupts } = require("./utils/simpleSpawn");
|
14
14
|
const { validateTags } = require("./utils/validateTags");
|
15
|
-
const {
|
15
|
+
const { addPackageMetadata } = require("./utils/addPackageMetadata");
|
16
16
|
const argv = require("yargs").argv;
|
17
17
|
|
18
18
|
// Makes the script crash on unhandled rejections instead of silently
|
@@ -85,13 +85,14 @@ spawn(require.resolve(".bin/typedoc"), args).then((code) => {
|
|
85
85
|
cpx.copySync(path.join(source, argv.tsIndexFile), outputDir);
|
86
86
|
fs.renameSync(path.join(outputDir, argv.tsIndexFile), path.join(outputDir, 'index.ts'));
|
87
87
|
}
|
88
|
+
|
88
89
|
// Copy CHANGELOG.json to json output folder
|
89
90
|
if (fs.existsSync(path.join(process.cwd(), 'CHANGELOG.json'))) {
|
90
91
|
cpx.copySync(path.join(process.cwd(), 'CHANGELOG.json'), outputDir);
|
91
92
|
}
|
92
93
|
|
93
|
-
// Append the directory of the package to the output
|
94
|
-
|
94
|
+
// Append the directory of the package, version and repository URL to the output
|
95
|
+
addPackageMetadata(json, process.cwd());
|
95
96
|
|
96
97
|
if (code === 0) {
|
97
98
|
let tagErrors = validateTags(json);
|
@@ -15,8 +15,18 @@ const rootPackageJson = process.env.RUSHSTACK_FILE_ERROR_BASE_FOLDER
|
|
15
15
|
// Check if path to root package.json is valid.
|
16
16
|
const rootPackageJsonPath = require.resolve(rootPackageJson);
|
17
17
|
|
18
|
+
//Find the package.json of the project and retrieve the version and repository URL
|
19
|
+
const packageJsonPath = path.join(process.cwd(), "package.json");
|
20
|
+
const packageJson = JSON.parse(FS.readFileSync(packageJsonPath));
|
21
|
+
const version = packageJson.version;
|
22
|
+
const repositoryUrl = packageJson.repository?.url;
|
23
|
+
|
24
|
+
if (!version || !repositoryUrl) {
|
25
|
+
throw new Error('version or repositoryUrl not found in package.json');
|
26
|
+
}
|
27
|
+
|
18
28
|
// Appends the directory of the package root to the Typedoc JSON output
|
19
|
-
function
|
29
|
+
function addPackageMetadata(file, directory) {
|
20
30
|
if (FS.existsSync(file) && FS.statSync(file).isFile()) {
|
21
31
|
const contents = FS.readFileSync(file, "utf-8");
|
22
32
|
const pathToRootFolder = path.dirname(rootPackageJsonPath);
|
@@ -25,10 +35,12 @@ function addSourceDir(file, directory) {
|
|
25
35
|
jsonContents["packageRoot"] = packageRoot.endsWith("src")
|
26
36
|
? packageRoot
|
27
37
|
: `${packageRoot}\\${"src"}`;
|
38
|
+
jsonContents["version"] = version;
|
39
|
+
jsonContents["repositoryUrl"] = repositoryUrl;
|
28
40
|
FS.writeFileSync(file, Buffer.from(JSON.stringify(jsonContents, null, 2)));
|
29
41
|
}
|
30
42
|
}
|
31
43
|
|
32
44
|
module.exports = {
|
33
|
-
|
45
|
+
addPackageMetadata,
|
34
46
|
};
|