Skip to content

[CLEANUP] Fix missing ApplicationInstance in Router tests#21095

Merged
NullVoxPopuli merged 2 commits intoemberjs:mainfrom
crazylogic03:fix/router-app-instance-clean
Feb 17, 2026
Merged

[CLEANUP] Fix missing ApplicationInstance in Router tests#21095
NullVoxPopuli merged 2 commits intoemberjs:mainfrom
crazylogic03:fix/router-app-instance-clean

Conversation

@crazylogic03
Copy link
Contributor

This PR removes a workaround in packages/@ember/routing/router.ts that allowed ApplicationInstance to be missing in tests. This occurred because RouterNonApplicationTestCase in packages/internal-test-helpers did not register an application instance.

I have updated the test case to register a mock ApplicationInstance, allowing the router to enforce strict dependency checks and removing the TODO(SAFETY) comment.

This ensures better type safety and correctness in the router's dependencies.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 17, 2026

Estimated Asset Sizes

Diff

--- main/out.txt	2026-02-16 14:34:00.000000000 +0000
+++ pr/./pr-22088232688/out.txt	2026-02-17 06:25:12.000000000 +0000
@@ -1,13 +1,13 @@
 ╔═══════╤═══════════╤═══════════╗
 ║       │ Min       │ Gzip      ║
 ╟───────┼───────────┼───────────╢
-║ Total │ 352.02 KB │ 203.83 KB ║
+║ Total │ 351.99 KB │ 203.84 KB ║
 ╚═══════╧═══════════╧═══════════╝
 
 ╔══════════════════════╤═══════════╤═══════════╗
 ║ @ember/*             │ Min       │ Gzip      ║
 ╟──────────────────────┼───────────┼───────────╢
-║ Total                │ 313.42 KB │ 181.89 KB ║
+║ Total                │ 313.39 KB │ 181.91 KB ║
 ╟──────────────────────┼───────────┼───────────╢
 ║ -internals           │ 36.65 KB  │ 26.22 KB  ║
 ║ application          │ 13.23 KB  │ 8.05 KB   ║
@@ -25,7 +25,7 @@
 ║ object               │ 35.94 KB  │ 22.16 KB  ║
 ║ owner                │ 159 B     │ 178 B     ║
 ║ renderer             │ 630 B     │ 487 B     ║
-║ routing              │ 59.33 KB  │ 34.1 KB   ║
+║ routing              │ 59.3 KB   │ 34.12 KB  ║
 ║ runloop              │ 2.36 KB   │ 1.5 KB    ║
 ║ service              │ 1 KB      │ 845 B     ║
 ║ template             │ 654 B     │ 541 B     ║

Details

This PRmain
╔═══════╤═══════════╤═══════════╗
║       │ Min       │ Gzip      ║
╟───────┼───────────┼───────────╢
║ Total │ 351.99 KB │ 203.84 KB ║
╚═══════╧═══════════╧═══════════╝

╔══════════════════════╤═══════════╤═══════════╗
║ @ember/*             │ Min       │ Gzip      ║
╟──────────────────────┼───────────┼───────────╢
║ Total                │ 313.39 KB │ 181.91 KB ║
╟──────────────────────┼───────────┼───────────╢
║ -internals           │ 36.65 KB  │ 26.22 KB  ║
║ application          │ 13.23 KB  │ 8.05 KB   ║
║ array                │ 13.01 KB  │ 7.46 KB   ║
║ canary-features      │ 304 B     │ 389 B     ║
║ component            │ 2.05 KB   │ 1.64 KB   ║
║ controller           │ 1.96 KB   │ 1.41 KB   ║
║ debug                │ 11.69 KB  │ 8.12 KB   ║
║ deprecated-features  │ 31 B      │ 77 B      ║
║ destroyable          │ 561 B     │ 383 B     ║
║ enumerable           │ 259 B     │ 387 B     ║
║ helper               │ 1.08 KB   │ 811 B     ║
║ instrumentation      │ 2.43 KB   │ 1.79 KB   ║
║ modifier             │ 1.22 KB   │ 965 B     ║
║ object               │ 35.94 KB  │ 22.16 KB  ║
║ owner                │ 159 B     │ 178 B     ║
║ renderer             │ 630 B     │ 487 B     ║
║ routing              │ 59.3 KB   │ 34.12 KB  ║
║ runloop              │ 2.36 KB   │ 1.5 KB    ║
║ service              │ 1 KB      │ 845 B     ║
║ template             │ 654 B     │ 541 B     ║
║ template-compilation │ 429 B     │ 366 B     ║
║ template-compiler    │ 123.08 KB │ 59.45 KB  ║
║ template-factory     │ 370 B     │ 374 B     ║
║ test                 │ 923 B     │ 627 B     ║
║ utils                │ 4.11 KB   │ 3.6 KB    ║
║ version              │ 55 B      │ 131 B     ║
╚══════════════════════╧═══════════╧═══════════╝

╔═════════════════╤══════════╤══════════╗
║ @glimmer/*      │ Min      │ Gzip     ║
╟─────────────────┼──────────┼──────────╢
║ Total           │ 38.6 KB  │ 21.94 KB ║
╟─────────────────┼──────────┼──────────╢
║ destroyable     │ 2.77 KB  │ 1.39 KB  ║
║ encoder         │ 81 B     │ 171 B    ║
║ env             │ 38 B     │ 87 B     ║
║ global-context  │ 886 B    │ 545 B    ║
║ manager         │ 977 B    │ 608 B    ║
║ node            │ 175 B    │ 260 B    ║
║ opcode-compiler │ 1.11 KB  │ 894 B    ║
║ owner           │ 159 B    │ 202 B    ║
║ program         │ 252 B    │ 301 B    ║
║ reference       │ 548 B    │ 531 B    ║
║ runtime         │ 10.32 KB │ 5.32 KB  ║
║ tracking        │ 1.34 KB  │ 1.16 KB  ║
║ util            │ 1.94 KB  │ 1.68 KB  ║
║ validator       │ 15.75 KB │ 6.96 KB  ║
║ vm              │ 495 B    │ 569 B    ║
║ wire-format     │ 1.84 KB  │ 1.35 KB  ║
╚═════════════════╧══════════╧══════════╝
╔═══════╤═══════════╤═══════════╗
║       │ Min       │ Gzip      ║
╟───────┼───────────┼───────────╢
║ Total │ 352.02 KB │ 203.83 KB ║
╚═══════╧═══════════╧═══════════╝

╔══════════════════════╤═══════════╤═══════════╗
║ @ember/*             │ Min       │ Gzip      ║
╟──────────────────────┼───────────┼───────────╢
║ Total                │ 313.42 KB │ 181.89 KB ║
╟──────────────────────┼───────────┼───────────╢
║ -internals           │ 36.65 KB  │ 26.22 KB  ║
║ application          │ 13.23 KB  │ 8.05 KB   ║
║ array                │ 13.01 KB  │ 7.46 KB   ║
║ canary-features      │ 304 B     │ 389 B     ║
║ component            │ 2.05 KB   │ 1.64 KB   ║
║ controller           │ 1.96 KB   │ 1.41 KB   ║
║ debug                │ 11.69 KB  │ 8.12 KB   ║
║ deprecated-features  │ 31 B      │ 77 B      ║
║ destroyable          │ 561 B     │ 383 B     ║
║ enumerable           │ 259 B     │ 387 B     ║
║ helper               │ 1.08 KB   │ 811 B     ║
║ instrumentation      │ 2.43 KB   │ 1.79 KB   ║
║ modifier             │ 1.22 KB   │ 965 B     ║
║ object               │ 35.94 KB  │ 22.16 KB  ║
║ owner                │ 159 B     │ 178 B     ║
║ renderer             │ 630 B     │ 487 B     ║
║ routing              │ 59.33 KB  │ 34.1 KB   ║
║ runloop              │ 2.36 KB   │ 1.5 KB    ║
║ service              │ 1 KB      │ 845 B     ║
║ template             │ 654 B     │ 541 B     ║
║ template-compilation │ 429 B     │ 366 B     ║
║ template-compiler    │ 123.08 KB │ 59.45 KB  ║
║ template-factory     │ 370 B     │ 374 B     ║
║ test                 │ 923 B     │ 627 B     ║
║ utils                │ 4.11 KB   │ 3.6 KB    ║
║ version              │ 55 B      │ 131 B     ║
╚══════════════════════╧═══════════╧═══════════╝

╔═════════════════╤══════════╤══════════╗
║ @glimmer/*      │ Min      │ Gzip     ║
╟─────────────────┼──────────┼──────────╢
║ Total           │ 38.6 KB  │ 21.94 KB ║
╟─────────────────┼──────────┼──────────╢
║ destroyable     │ 2.77 KB  │ 1.39 KB  ║
║ encoder         │ 81 B     │ 171 B    ║
║ env             │ 38 B     │ 87 B     ║
║ global-context  │ 886 B    │ 545 B    ║
║ manager         │ 977 B    │ 608 B    ║
║ node            │ 175 B    │ 260 B    ║
║ opcode-compiler │ 1.11 KB  │ 894 B    ║
║ owner           │ 159 B    │ 202 B    ║
║ program         │ 252 B    │ 301 B    ║
║ reference       │ 548 B    │ 531 B    ║
║ runtime         │ 10.32 KB │ 5.32 KB  ║
║ tracking        │ 1.34 KB  │ 1.16 KB  ║
║ util            │ 1.94 KB  │ 1.68 KB  ║
║ validator       │ 15.75 KB │ 6.96 KB  ║
║ vm              │ 495 B    │ 569 B    ║
║ wire-format     │ 1.84 KB  │ 1.35 KB  ║
╚═════════════════╧══════════╧══════════╝

@crazylogic03
Copy link
Contributor Author

@NullVoxPopuli Please Have a Review On this PR and Let me Know if this requires any Update or changes

@NullVoxPopuli
Copy link
Contributor

What error were you running in to that prompted looking in to this?

@crazylogic03
Copy link
Contributor Author

@NullVoxPopuli I wasn't encountering a specific error in an application. I was looking through the codebase for cleanup opportunities and found the TODO(SAFETY) comment in

packages/@ember/routing/router.ts.
The comment explicitly flagged that Router Service - non application test was running without a correctly set

ApplicationInstance:
// TODO(SAFETY): At least one test runs without this set correctly. At a later time, update the test to configure this correctly.I addressed this by updating RouterNonApplicationTestCase to register a mock ApplicationInstance, which allowed me to remove the workaround and enforce the presence of the instance in
router.ts, improving the safety of the code.

@NullVoxPopuli
Copy link
Contributor

Excellent! That certainly is helpful and i appreciate the effort!

To ensure there is no regression in the future, could you add a test that fails before this change and passes after? (Or, if you remove the register do a bunch of tests fail? This would satisfy regression prevention as well)

It's already a good signal that the whole test suite is currently passing already.

@crazylogic03
Copy link
Contributor Author

@NullVoxPopuli i verified this locally. The changes to RouterNonApplicationTestCase
effectively serve as the regression test.
To confirm, I temporarily reverted the registration of -application-instance:main in the test case, and the test failed immediately with the expected assertion error: Assertion Failed: [BUG] unexpectedly missing -application-instance:main
This confirms that the existing test suite now covers this scenario and will catch any future regressions where the instance is missing.

@NullVoxPopuli NullVoxPopuli merged commit 02c62b0 into emberjs:main Feb 17, 2026
30 checks passed
@kategengler
Copy link
Member

There is no such thing as [CLEANUP beta] ... we do not backport Cleanup

@kategengler kategengler changed the title [CLEANUP beta] Fix missing ApplicationInstance in Router tests [CLEANUP] Fix missing ApplicationInstance in Router tests Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants