Skip to content

A platform for community discussion. Free, open, simple.

DEV: Apply patch for ember-exam bug (#40382)

David Taylor59405b797a3b
diff --git a/package.json b/package.json
index bae167fb6b2..cefe7fb981e 100644
--- a/package.json
+++ b/package.json
@@ -55,7 +55,8 @@
"@ember-compat/[email protected]": "patches/@[email protected]",
},
"peerDependencyRules": {
"allowedVersions": {
diff --git a/patches/[email protected] b/patches/[email protected]
new file mode 100644
index 00000000000..d8222f50fbb
--- /dev/null
+++ b/patches/[email protected]
@@ -0,0 +1,70 @@
+diff --git a/lib/commands/exam.js b/lib/commands/exam.js
+index 870d8e4..24f50b4 100644
+--- a/lib/commands/exam.js
++++ b/lib/commands/exam.js
+@@ -325,24 +325,16 @@ module.exports = TestCommand.extend({
+ );
+ };
+
++ // Called for processError, processExit, and the finish() wrapper below.
++ // Flag avoids double-counting.
+ const browserTerminationHandler = function () {
+- // browserTerminationHandler is called for disconnect, processError or processExit events.
+- // disconnect and processExit events is fired during global error and successful test runs.
+- // On successful test runs, browserExitHandler should already be called. And is unnecessary
+- // to call it again, so we should return. This is covered by this.finish = true
+- // On global failure cases, it's possible that this.finish is also true. So we must check
+- // the timers set by onProcessExit
+- // https://github.com/testem/testem/blob/master/lib/runners/browser_test_runner.js#L266
+- // or onProcessError in testem.
+- // https://github.com/testem/testem/blob/master/lib/runners/browser_test_runner.js#L252
+- // If either timers is set, we should record the failed browser and call browserExitHandler
+- if (this.finished && !this.onProcessExitTimer && !this.pendingTimer) {
++ if (this._emberExamExitRecorded) {
+ return;
+ }
++ this._emberExamExitRecorded = true;
+ if (commands.get('writeExecutionFile')) {
+ testemEvents.recordFailedBrowserId(this.launcher, ui);
+ }
+-
+ browserExitHandler.call(this, true);
+ };
+
+@@ -381,16 +373,31 @@ module.exports = TestCommand.extend({
+ init = true;
+ }
+
++ // Monkey-patch finish() — testem exposes no event for "browser truly
++ // done", and finish() is the one method all termination paths flow
++ // through (clean exit, disconnect timeout, processExit timer). The
++ // socket `disconnect` event fires on transient drops too, so it
++ // can't be used. Microtask defers past after-tests-complete.
++ if (!this._emberExamFinishHooked) {
++ this._emberExamFinishHooked = true;
++ const originalFinish = this.finish;
++ const runner = this;
++ this.finish = function () {
++ const result = originalFinish.apply(this, arguments);
++ Promise.resolve().then(() => browserTerminationHandler.call(runner));
++ return result;
++ };
++ }
++
+ if (typeof this.launcher !== 'undefined' && this.launcher !== null) {
+ testemEvents.recordStartedLauncherId(this.launcher.id);
+ }
+ };
+
+- events['after-tests-complete'] = browserExitHandler;
+-
+- events['disconnect'] = function () {
+- // To prevent handling exiting browser browser disconnects from errors `disconnect` callback's needed to be registered.
+- browserTerminationHandler.bind(this)();
++ events['after-tests-complete'] = function (...args) {
++ // Mark the runner recorded; the finish() wrapper above checks this flag.
++ this._emberExamExitRecorded = true;
++ return browserExitHandler.apply(this, args);
+ };
+
+ events['testem:test-done-metadata'] = (details) => {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3aaa6d39a23..1554f02cb34 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -15,6 +15,9 @@ patchedDependencies:
hash: 387f93bad78f3a98b20dc742f4f0b7a165c7e6ebc65cc60356748346c0725c7f
path: patches/[email protected]
+ hash: 1b2f23c19eb9a2a0eb935bfcf98e0a5e9f77d46c41bd1b5c7d12ef4369e067e3
+ path: patches/[email protected]
hash: 85ff9a16d08431e3bdc9aea8d55280e14f437f1c2a7d8e461de56c614ad48926
path: patches/[email protected]
@@ -584,7 +587,7 @@ importers:
version: 6.1.1
ember-exam:
specifier: ^10.1.0
- version: 10.1.0(@glint/[email protected])([email protected](@babel/[email protected])(@ember/[email protected](@babel/[email protected])(@glint/[email protected]))(@glint/[email protected])([email protected]))([email protected](patch_hash=85ff9a16d08431e3bdc9aea8d55280e14f437f1c2a7d8e461de56c614ad48926)(@glimmer/[email protected])([email protected]))([email protected])([email protected](@swc/[email protected]))
+ version: 10.1.0(patch_hash=1b2f23c19eb9a2a0eb935bfcf98e0a5e9f77d46c41bd1b5c7d12ef4369e067e3)(@glint/[email protected])([email protected](@babel/[email protected])(@ember/[email protected](@babel/[email protected])(@glint/[email protected]))(@glint/[email protected])([email protected]))([email protected](patch_hash=85ff9a16d08431e3bdc9aea8d55280e14f437f1c2a7d8e461de56c614ad48926)(@glimmer/[email protected])([email protected]))([email protected])([email protected](@swc/[email protected]))
ember-load-initializers:
specifier: ^3.0.1
version: 3.0.1([email protected](patch_hash=85ff9a16d08431e3bdc9aea8d55280e14f437f1c2a7d8e461de56c614ad48926)(@glimmer/[email protected])([email protected]))
@@ -14306,7 +14309,7 @@ snapshots:
content-tag: 4.2.0
oxc-parser: 0.130.0
+ [email protected](patch_hash=1b2f23c19eb9a2a0eb935bfcf98e0a5e9f77d46c41bd1b5c7d12ef4369e067e3)(@glint/[email protected])([email protected](@babel/[email protected])(@ember/[email protected](@babel/[email protected])(@glint/[email protected]))(@glint/[email protected])([email protected]))([email protected](patch_hash=85ff9a16d08431e3bdc9aea8d55280e14f437f1c2a7d8e461de56c614ad48926)(@glimmer/[email protected])([email protected]))([email protected])([email protected](@swc/[email protected])):
dependencies:
'@babel/core': 7.29.0([email protected])
chalk: 5.6.2