@itwin/build-tools 5.1.0-dev.10 → 5.1.0-dev.13

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.
@@ -57,9 +57,54 @@ Object.defineProperty(Base, "color", {
57
57
  });
58
58
  class BentleyMochaReporter extends Spec {
59
59
  _junitReporter;
60
+ _chrome = false;
61
+ _electron = true;
60
62
  constructor(_runner, _options) {
61
63
  super(...arguments);
62
64
  this._junitReporter = new MochaJUnitReporter(...arguments);
65
+ // Detect hangs caused by tests that leave timers/other handles open - not possible in electron frontends.
66
+ if (!("electron" in process.versions)) {
67
+ this._electron = false;
68
+ if (process.argv.length > 1 && process.argv[1].endsWith("certa.js")) {
69
+ for (let i = 2; i < process.argv.length; ++i) {
70
+ if (process.argv[i] === "-r") {
71
+ if (i + 1 < process.argv.length && process.argv[i + 1] === "chrome") {
72
+ this._chrome = true;
73
+ process.on("chrome-test-runner-done", () => {
74
+ this.confirmExit();
75
+ });
76
+ }
77
+ break;
78
+ }
79
+ }
80
+ }
81
+ }
82
+ }
83
+ confirmExit(seconds = 30) {
84
+ // 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
85
+ // the process alive after n seconds. This also has the benefit of preventing the timer from showing up in wtfnode's dump of open handles.
86
+ setTimeout(() => {
87
+ logBuildError(`Handle leak detected. Node was still running ${seconds} seconds after tests completed.`);
88
+ if (debugLeaks) {
89
+ const wtf = require("wtfnode");
90
+ wtf.setLogger("info", console.error);
91
+ wtf.dump();
92
+ let activeResourcesInfo = process.getActiveResourcesInfo(); // https://nodejs.dev/en/api/v18/process#processgetactiveresourcesinfo (Not added to @types/node yet I suppose)
93
+ console.error(activeResourcesInfo);
94
+ activeResourcesInfo = activeResourcesInfo.map((value) => value.toLowerCase());
95
+ // asyncResourceStats.set(asyncId, {before: 0, after: 0, type, eid, triggerAsyncId, initStack: stack});
96
+ asyncResourceStats.forEach((value, key) => {
97
+ if (activeResourcesInfo.includes(value.type.toLowerCase())) {
98
+ console.error(`asyncId: ${key}: type: ${value.type}, eid: ${value.eid},triggerAsyncId: ${value.triggerAsyncId}, initStack: ${value.initStack}`);
99
+ }
100
+ });
101
+ }
102
+ else {
103
+ console.error("Try running with the DEBUG_LEAKS env var set to see open handles.");
104
+ }
105
+ // Not sure why, but process.exit(1) wasn't working here...
106
+ process.kill(process.pid);
107
+ }, seconds * 1000).unref();
63
108
  }
64
109
  epilogue(...args) {
65
110
  // Force test errors to be printed to stderr instead of stdout.
@@ -77,31 +122,9 @@ class BentleyMochaReporter extends Spec {
77
122
  }
78
123
  }
79
124
  // Detect hangs caused by tests that leave timers/other handles open - not possible in electron frontends.
80
- if (!("electron" in process.versions)) {
81
- // 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
82
- // the process alive after 30 seconds. This also has the benefit of preventing the timer from showing up in wtfnode's dump of open handles.
83
- setTimeout(() => {
84
- logBuildError(`Handle leak detected. Node was still running 30 seconds after tests completed.`);
85
- if (debugLeaks) {
86
- const wtf = require("wtfnode");
87
- wtf.setLogger("info", console.error);
88
- wtf.dump();
89
- let activeResourcesInfo = process.getActiveResourcesInfo(); // https://nodejs.dev/en/api/v18/process#processgetactiveresourcesinfo (Not added to @types/node yet I suppose)
90
- console.error(activeResourcesInfo);
91
- activeResourcesInfo = activeResourcesInfo.map((value) => value.toLowerCase());
92
- // asyncResourceStats.set(asyncId, {before: 0, after: 0, type, eid, triggerAsyncId, initStack: stack});
93
- asyncResourceStats.forEach((value, key) => {
94
- if (activeResourcesInfo.includes(value.type.toLowerCase())) {
95
- console.error(`asyncId: ${key}: type: ${value.type}, eid: ${value.eid},triggerAsyncId: ${value.triggerAsyncId}, initStack: ${value.initStack}`);
96
- }
97
- });
98
- }
99
- else {
100
- console.error("Try running with the DEBUG_LEAKS env var set to see open handles.");
101
- }
102
- // Not sure why, but process.exit(1) wasn't working here...
103
- process.kill(process.pid);
104
- }, 30 * 1000).unref();
125
+ if (!this._electron && !this._chrome) {
126
+ // Not running in Chrome or Electron, so check for open handles.
127
+ this.confirmExit(30);
105
128
  }
106
129
  if (!this.stats.pending)
107
130
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/build-tools",
3
- "version": "5.1.0-dev.10",
3
+ "version": "5.1.0-dev.13",
4
4
  "description": "Bentley build tools",
5
5
  "license": "MIT",
6
6
  "repository": {