velocious 1.0.506 → 1.0.508

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.
@@ -46,7 +46,7 @@ import singularizeModelName from "../../utils/singularize-model-name.js"
46
46
  import {defineModelScope} from "../../utils/model-scope.js"
47
47
  import { normalizeDateStringForWrite, normalizeDateValueForRead, normalizeDateValueForWrite } from "../datetime-storage.js"
48
48
  import {formatValue} from "../../utils/format-value.js"
49
- import {captureCreateAuditChanges, captureUpdateAuditChanges, createAudit, createCreateAudit, createDestroyAudit, createUpdateAudit, registerAuditCallback, registerAuditing, withoutAudit} from "./auditing.js"
49
+ import {captureCreateAuditChanges, captureUpdateAuditChanges, createAudit, createCreateAudit, createDestroyAudit, createUpdateAudit, initializeAuditing, registerAuditCallback, registerAuditing, withoutAudit} from "./auditing.js"
50
50
  import {registerMagnitudeCounterCache} from "./counter-cache-magnitude.js"
51
51
  import {stateMachine} from "./state-machine.js"
52
52
  import ValidatorsFormat from "./validators/format.js"
@@ -1533,6 +1533,7 @@ class VelociousDatabaseRecord {
1533
1533
  }
1534
1534
 
1535
1535
  await this._defineTranslationMethods()
1536
+ await initializeAuditing(this)
1536
1537
  this._initialized = true
1537
1538
  }
1538
1539
 
@@ -218,6 +218,12 @@ export default class VelociousDatabaseRecordHasManyInstanceRelationship extends
218
218
 
219
219
  whereArgs[foreignKey] = primaryModelID
220
220
 
221
+ if (this.getRelationship().getPolymorphic()) {
222
+ const typeColumn = this.getRelationship().getPolymorphicTypeColumn()
223
+
224
+ whereArgs[typeColumn] = this.getModel().getModelClass().getModelName()
225
+ }
226
+
221
227
  const query = TargetModelClass.where(whereArgs)
222
228
 
223
229
  return this.applyScope(query)
@@ -55,8 +55,12 @@ function runWithTimeout(promise, timeoutMs, testDescription) {
55
55
  * Waits for an abandoned (timed-out) test lifecycle to settle, bounded by a
56
56
  * grace period, so its afterEach database cleanup runs on the shared connection
57
57
  * before the next test reuses it. Resolves early the moment the lifecycle
58
- * settles; otherwise resolves once the grace elapses (never rejects, and never
59
- * keeps the process alive on its own).
58
+ * settles; otherwise resolves once the grace elapses (never rejects).
59
+ *
60
+ * The grace timer is kept ref'd so it cannot let Node exit with an unsettled
61
+ * top-level await when the timed-out lifecycle has no ref'd handles of its own
62
+ * (for example a stalled mocked async API). Once the caller continues past this
63
+ * await, the timer has already resolved and no longer anchors the event loop.
60
64
  * @param {Promise<?>} lifecycle - The abandoned per-test lifecycle promise.
61
65
  * @param {number} graceMs - Maximum time to wait for the lifecycle to settle.
62
66
  * @returns {Promise<boolean>} - Whether the lifecycle settled within the grace period.
@@ -71,8 +75,6 @@ function awaitSettledOrGrace(lifecycle, graceMs) {
71
75
  resolve(false)
72
76
  }, graceMs)
73
77
 
74
- if (typeof graceTimer.unref === "function") graceTimer.unref()
75
-
76
78
  Promise.resolve(lifecycle).then(() => {}, () => {}).then(() => {
77
79
  if (settled) return
78
80
 
@@ -913,6 +915,14 @@ export default class TestRunner {
913
915
  * still wait for it to settle after runWithTimeout has abandoned it.
914
916
  * @type {Promise<?> | undefined} */
915
917
  let testLifecycle
918
+ /**
919
+ * Shared mutable flag so the catch block can suppress the
920
+ * `_successfulTests` increment inside the still-detached lifecycle:
921
+ * when the lifecycle eventually resolves after a timeout rejection,
922
+ * the success increment must not count a test that was already
923
+ * recorded as failed.
924
+ * @type {{timedOut: boolean}} */
925
+ const timeoutState = {timedOut: false}
916
926
  const stopConsoleCapture = this.startConsoleCapture({
917
927
  passthrough: testConfig.consoleOutput === "live"
918
928
  })
@@ -946,7 +956,9 @@ export default class TestRunner {
946
956
  line: testData.line ?? 0
947
957
  }
948
958
  await testData.function(testArgs)
949
- this._successfulTests++
959
+ if (!timeoutState.timedOut) {
960
+ this._successfulTests++
961
+ }
950
962
  } finally {
951
963
  for (const afterEachData of newAfterEaches) {
952
964
  await afterEachData.callback({configuration: this.getConfiguration(), testArgs, testData})
@@ -982,6 +994,7 @@ export default class TestRunner {
982
994
  const timedOut = Boolean(/** @type {TestTimeoutError} */ (error)?.velociousTestTimeout)
983
995
 
984
996
  if (timedOut && testLifecycle) {
997
+ timeoutState.timedOut = true
985
998
  await awaitSettledOrGrace(testLifecycle, timeoutMs ?? 60000)
986
999
  }
987
1000