Skip to content

Commit 176b87e

Browse files
NullVoxPopuliclaude
andcommitted
Unify test infrastructure on precompileTemplate, remove addTemplate/addComponent/registerComponent
Remove duplicated test helper methods (addTemplate, addComponent, registerComponent, defComponent, defineComponent) from the test infrastructure and migrate all ~90 test files to use precompileTemplate from @ember/template-compilation directly. Test files now use: - precompileTemplate(template, { strictMode: false }) for loose-mode templates - precompileTemplate(template, { strictMode: true, scope: () => ({...}) }) for strict-mode - setComponentTemplate() + this.owner.register() / this.add() for component registration - Runtime compile from internal-test-helpers/lib/compile only for edge cases (keyword shadowing, dynamic template strings, intentional compile errors) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9e7b80b commit 176b87e

File tree

99 files changed

+6785
-5000
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+6785
-5000
lines changed

packages/@ember/-internals/glimmer/tests/integration/application/debug-render-tree-test.ts

Lines changed: 153 additions & 184 deletions
Large diffs are not rendered by default.

packages/@ember/-internals/glimmer/tests/integration/application/engine-test.js

Lines changed: 57 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
moduleFor,
33
ApplicationTestCase,
44
ModuleBasedTestResolver,
5-
strip,
65
runTaskNext,
76
} from 'internal-test-helpers';
87

@@ -13,7 +12,7 @@ import Controller from '@ember/controller';
1312
import Engine from '@ember/engine';
1413
import { next } from '@ember/runloop';
1514

16-
import { compile } from '../../utils/helpers';
15+
import { precompileTemplate } from '@ember/template-compilation';
1716
import { setComponentTemplate } from '@glimmer/manager';
1817
import { templateOnlyComponent } from '@glimmer/runtime';
1918

@@ -62,7 +61,7 @@ moduleFor(
6261
setupAppAndRoutableEngine(hooks = []) {
6362
let self = this;
6463

65-
this.addTemplate('application', 'Application{{outlet}}');
64+
this.add('template:application', precompileTemplate('Application{{outlet}}'));
6665

6766
this.router.map(function () {
6867
this.mount('blog');
@@ -110,7 +109,10 @@ moduleFor(
110109
queryParams = ['official'];
111110
}
112111
);
113-
this.register('template:application', compile('Engine{{this.lang}}{{outlet}}'));
112+
this.register(
113+
'template:application',
114+
precompileTemplate('Engine{{this.lang}}{{outlet}}')
115+
);
114116
this.register(
115117
'route:application',
116118
class extends Route {
@@ -144,7 +146,7 @@ moduleFor(
144146

145147
init() {
146148
super.init(...arguments);
147-
this.register('template:application', compile('Engine'));
149+
this.register('template:application', precompileTemplate('Engine'));
148150
this.register(
149151
'controller:application',
150152
class extends Controller {
@@ -160,7 +162,7 @@ moduleFor(
160162
}
161163

162164
setupRoutelessEngine(hooks) {
163-
this.addTemplate('application', 'Application{{mount "chat-engine"}}');
165+
this.add('template:application', precompileTemplate('Application{{mount "chat-engine"}}'));
164166
this.add(
165167
'route:application',
166168
class extends Route {
@@ -182,12 +184,9 @@ moduleFor(
182184
['@test sharing a template between engine and application has separate refinements']() {
183185
this.assert.expect(1);
184186

185-
let sharedTemplate = compile(strip`
186-
<h1>{{this.contextType}}</h1>
187-
{{ambiguous-curlies}}
188-
189-
{{outlet}}
190-
`);
187+
let sharedTemplate = precompileTemplate(
188+
'<h1>{{this.contextType}}</h1>{{ambiguous-curlies}}{{outlet}}'
189+
);
191190

192191
this.add('template:application', sharedTemplate);
193192
this.add(
@@ -220,7 +219,7 @@ moduleFor(
220219
this.register('template:application', sharedTemplate);
221220
this.register(
222221
'component:ambiguous-curlies',
223-
setComponentTemplate(compile(`<p>Component!</p>`), templateOnlyComponent())
222+
setComponentTemplate(precompileTemplate(`<p>Component!</p>`), templateOnlyComponent())
224223
);
225224
}
226225
}
@@ -234,21 +233,17 @@ moduleFor(
234233
['@test sharing a layout between engine and application has separate refinements']() {
235234
this.assert.expect(1);
236235

237-
let sharedLayout = compile(strip`
238-
{{ambiguous-curlies}}
239-
`);
236+
let sharedLayout = precompileTemplate('{{ambiguous-curlies}}');
240237

241238
let sharedComponent = class extends Component {
242239
layout = sharedLayout;
243240
};
244241

245-
this.addTemplate(
246-
'application',
247-
strip`
248-
<h1>Application</h1>
249-
{{my-component ambiguous-curlies="Local Data!"}}
250-
{{outlet}}
251-
`
242+
this.add(
243+
'template:application',
244+
precompileTemplate(
245+
'<h1>Application</h1>{{my-component ambiguous-curlies="Local Data!"}}{{outlet}}'
246+
)
252247
);
253248

254249
this.add('component:my-component', sharedComponent);
@@ -267,16 +262,12 @@ moduleFor(
267262
super.init(...arguments);
268263
this.register(
269264
'template:application',
270-
compile(strip`
271-
<h1>Engine</h1>
272-
{{my-component}}
273-
{{outlet}}
274-
`)
265+
precompileTemplate('<h1>Engine</h1>{{my-component}}{{outlet}}')
275266
);
276267
this.register('component:my-component', sharedComponent);
277268
this.register(
278269
'component:ambiguous-curlies',
279-
setComponentTemplate(compile(`<p>Component!</p>`), templateOnlyComponent())
270+
setComponentTemplate(precompileTemplate(`<p>Component!</p>`), templateOnlyComponent())
280271
);
281272
}
282273
}
@@ -363,7 +354,7 @@ moduleFor(
363354

364355
init() {
365356
super.init(...arguments);
366-
this.register('template:application', compile('Engine{{outlet}}'));
357+
this.register('template:application', precompileTemplate('Engine{{outlet}}'));
367358
this.register(
368359
'route:application',
369360
class extends Route {
@@ -405,7 +396,10 @@ moduleFor(
405396
}
406397
}
407398
);
408-
this.register('template:application_error', compile('Error! {{@model.message}}'));
399+
this.register(
400+
'template:application_error',
401+
precompileTemplate('Error! {{@model.message}}')
402+
);
409403
this.register(
410404
'route:post',
411405
class extends Route {
@@ -444,7 +438,7 @@ moduleFor(
444438
}
445439
}
446440
);
447-
this.register('template:error', compile('Error! {{@model.message}}'));
441+
this.register('template:error', precompileTemplate('Error! {{@model.message}}'));
448442
this.register(
449443
'route:post',
450444
class extends Route {
@@ -483,7 +477,7 @@ moduleFor(
483477
}
484478
}
485479
);
486-
this.register('template:post_error', compile('Error! {{@model.message}}'));
480+
this.register('template:post_error', precompileTemplate('Error! {{@model.message}}'));
487481
this.register(
488482
'route:post',
489483
class extends Route {
@@ -522,7 +516,7 @@ moduleFor(
522516
}
523517
}
524518
);
525-
this.register('template:post.error', compile('Error! {{@model.message}}'));
519+
this.register('template:post.error', precompileTemplate('Error! {{@model.message}}'));
526520
this.register(
527521
'route:post.comments',
528522
class extends Route {
@@ -563,8 +557,8 @@ moduleFor(
563557
}
564558
}
565559
);
566-
this.register('template:application_loading', compile('Loading'));
567-
this.register('template:post', compile('Post'));
560+
this.register('template:application_loading', precompileTemplate('Loading'));
561+
this.register('template:post', precompileTemplate('Post'));
568562
this.register(
569563
'route:post',
570564
class extends Route {
@@ -610,8 +604,8 @@ moduleFor(
610604
}
611605
}
612606
);
613-
this.register('template:loading', compile('Loading'));
614-
this.register('template:post', compile('Post'));
607+
this.register('template:loading', precompileTemplate('Loading'));
608+
this.register('template:post', precompileTemplate('Post'));
615609
this.register(
616610
'route:post',
617611
class extends Route {
@@ -647,10 +641,10 @@ moduleFor(
647641

648642
this.setupAppAndRoutableEngine();
649643
this.additionalEngineRegistrations(function () {
650-
this.register('template:post', compile('{{outlet}}'));
651-
this.register('template:post.comments', compile('Comments'));
652-
this.register('template:post.likes_loading', compile('Loading'));
653-
this.register('template:post.likes', compile('Likes'));
644+
this.register('template:post', precompileTemplate('{{outlet}}'));
645+
this.register('template:post.comments', precompileTemplate('Comments'));
646+
this.register('template:post.likes_loading', precompileTemplate('Loading'));
647+
this.register('template:post.likes', precompileTemplate('Likes'));
654648
this.register(
655649
'route:post.likes',
656650
class extends Route {
@@ -687,8 +681,8 @@ moduleFor(
687681

688682
this.setupAppAndRoutableEngine();
689683
this.additionalEngineRegistrations(function () {
690-
this.register('template:post', compile('{{outlet}}'));
691-
this.register('template:post.comments', compile('Comments'));
684+
this.register('template:post', precompileTemplate('{{outlet}}'));
685+
this.register('template:post.comments', precompileTemplate('Comments'));
692686
this.register(
693687
'route:post.loading',
694688
class extends Route {
@@ -697,8 +691,8 @@ moduleFor(
697691
}
698692
}
699693
);
700-
this.register('template:post.loading', compile('Loading'));
701-
this.register('template:post.likes', compile('Likes'));
694+
this.register('template:post.loading', precompileTemplate('Loading'));
695+
this.register('template:post.likes', precompileTemplate('Likes'));
702696
this.register(
703697
'route:post.likes',
704698
class extends Route {
@@ -730,11 +724,12 @@ moduleFor(
730724
["@test query params don't have stickiness by default between model"](assert) {
731725
assert.expect(1);
732726

733-
let tmpl = '<LinkTo @route="category" @model={{1337}}>Category 1337</LinkTo>';
734-
735727
this.setupAppAndRoutableEngine();
736728
this.additionalEngineRegistrations(function () {
737-
this.register('template:category', compile(tmpl));
729+
this.register(
730+
'template:category',
731+
precompileTemplate('<LinkTo @route="category" @model={{1337}}>Category 1337</LinkTo>')
732+
);
738733
});
739734

740735
return this.visit('/blog/category/1?type=news').then(() => {
@@ -749,11 +744,12 @@ moduleFor(
749744
'@test query params only transitions work properly'(assert) {
750745
assert.expect(1);
751746

752-
let tmpl = '<LinkTo @query={{hash type="news"}}>News</LinkTo>';
753-
754747
this.setupAppAndRoutableEngine();
755748
this.additionalEngineRegistrations(function () {
756-
this.register('template:category', compile(tmpl));
749+
this.register(
750+
'template:category',
751+
precompileTemplate('<LinkTo @query={{hash type="news"}}>News</LinkTo>')
752+
);
757753
});
758754

759755
return this.visit('/blog/category/1').then(() => {
@@ -769,11 +765,14 @@ moduleFor(
769765
assert
770766
) {
771767
assert.expect(2);
772-
let tmpl =
773-
'<LinkTo @route="author" @model={{1337}} class="author-1337">Author 1337</LinkTo><LinkTo @route="author" @model=1 class="author-1">Author 1</LinkTo>';
774768
this.setupAppAndRoutableEngine();
775769
this.additionalEngineRegistrations(function () {
776-
this.register('template:author', compile(tmpl));
770+
this.register(
771+
'template:author',
772+
precompileTemplate(
773+
'<LinkTo @route="author" @model={{1337}} class="author-1337">Author 1337</LinkTo><LinkTo @route="author" @model=1 class="author-1">Author 1</LinkTo>'
774+
)
775+
);
777776
});
778777

779778
await this.visit('/blog/author/1?official=true');
@@ -840,7 +839,9 @@ moduleFor(
840839

841840
this.register(
842841
'template:application',
843-
compile('Engine<div class="lazy-query-param">{{this.lazyQueryParam}}</div>{{outlet}}')
842+
precompileTemplate(
843+
'Engine<div class="lazy-query-param">{{this.lazyQueryParam}}</div>{{outlet}}'
844+
)
844845
);
845846

846847
this.register(

packages/@ember/-internals/glimmer/tests/integration/application/helper-registration-test.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import { moduleFor, ApplicationTestCase } from 'internal-test-helpers';
22
import Controller from '@ember/controller';
33
import Service, { service } from '@ember/service';
44
import { Helper, helper } from '@ember/-internals/glimmer';
5+
import { precompileTemplate } from '@ember/template-compilation';
56

67
moduleFor(
78
'Application Lifecycle - Helper Registration',
89
class extends ApplicationTestCase {
910
['@test Unbound dashed helpers registered on the container can be late-invoked'](assert) {
10-
this.addTemplate('application', `<div id='wrapper'>{{x-borf}} {{x-borf 'YES'}}</div>`);
11+
this.add(
12+
'template:application',
13+
precompileTemplate(`<div id='wrapper'>{{x-borf}} {{x-borf 'YES'}}</div>`)
14+
);
1115

1216
let myHelper = helper((params) => params[0] || 'BORF');
1317
this.application.register('helper:x-borf', myHelper);
@@ -22,9 +26,9 @@ moduleFor(
2226
}
2327

2428
['@test Bound helpers registered on the container can be late-invoked'](assert) {
25-
this.addTemplate(
26-
'application',
27-
`<div id='wrapper'>{{x-reverse}} {{x-reverse this.foo}}</div>`
29+
this.add(
30+
'template:application',
31+
precompileTemplate(`<div id='wrapper'>{{x-reverse}} {{x-reverse this.foo}}</div>`)
2832
);
2933

3034
this.add(
@@ -51,9 +55,9 @@ moduleFor(
5155
}
5256

5357
['@test Undashed helpers registered on the container can be invoked'](assert) {
54-
this.addTemplate(
55-
'application',
56-
`<div id='wrapper'>{{omg}}|{{yorp 'boo'}}|{{yorp 'ya'}}</div>`
58+
this.add(
59+
'template:application',
60+
precompileTemplate(`<div id='wrapper'>{{omg}}|{{yorp 'boo'}}|{{yorp 'ya'}}</div>`)
5761
);
5862

5963
this.application.register(
@@ -76,7 +80,7 @@ moduleFor(
7680
}
7781

7882
['@test Helpers can receive injections'](assert) {
79-
this.addTemplate('application', `<div id='wrapper'>{{full-name}}</div>`);
83+
this.add('template:application', precompileTemplate(`<div id='wrapper'>{{full-name}}</div>`));
8084

8185
let serviceCalled = false;
8286

0 commit comments

Comments
 (0)