Skip to content

Commit 6578855

Browse files
committed
Update test
1 parent 41cb338 commit 6578855

File tree

1 file changed

+22
-79
lines changed

1 file changed

+22
-79
lines changed

test-packages/package-test-core/__tests__/transform/rewrite.test.ts

Lines changed: 22 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ describe('Transform: rewriteModule', () => {
469469

470470

471471
test('handles satisfies', () => {
472-
const emberTemplateImportsEnvironment = GlintEnvironment.load('ember-template-imports');
472+
const emberTemplateImportsEnvironment = GlintEnvironment.load(['ember-template-imports']);
473473

474474
let script = {
475475
filename: 'test.gts',
@@ -479,7 +479,7 @@ describe('Transform: rewriteModule', () => {
479479
`const SmolComp = `,
480480
` <template>`,
481481
` Hello there, {{@name}}`,
482-
` <template> satisfies TOC<{ Args: { name: string }}>;`,
482+
` </template> satisfies TOC<{ Args: { name: string }}>;`,
483483
``,
484484
`<template>`,
485485
` <SmolComp @name="Ember" />`,
@@ -490,83 +490,26 @@ describe('Transform: rewriteModule', () => {
490490

491491
let transformedModule = rewriteModule(ts, { script }, emberTemplateImportsEnvironment);
492492

493-
expect(transformedModule?.transformedContents).toMatchInlineSnapshot('two components');
494-
expect(transformedModule?.errors).toEqual([]);
495-
});
496-
497-
test('embedded gts templates', () => {
498-
let customEnv = GlintEnvironment.load(['ember-loose', 'ember-template-imports']);
499-
let script = {
500-
filename: 'foo.gts',
501-
contents: stripIndent`
502-
class MyComponent {
503-
<template>
504-
Hello, {{this.target}}!
505-
</template>
506-
507-
private target = 'World';
508-
}
509-
`,
510-
};
511-
512-
let rewritten = rewriteModule(ts, { script }, customEnv);
513-
let roundTripOffset = (offset: number): number | undefined =>
514-
rewritten?.getOriginalOffset(rewritten.getTransformedOffset(script.filename, offset))
515-
.offset;
516-
517-
let classOffset = script.contents.indexOf('MyComponent');
518-
let accessOffset = script.contents.indexOf('this.target');
519-
let fieldOffset = script.contents.indexOf('private target');
520-
521-
expect(roundTripOffset(classOffset)).toEqual(classOffset);
522-
expect(roundTripOffset(accessOffset)).toEqual(accessOffset);
523-
expect(roundTripOffset(fieldOffset)).toEqual(fieldOffset);
524-
525-
expect(rewritten?.toDebugString()).toMatchInlineSnapshot(`
526-
"TransformedModule
527-
528-
| Mapping: TemplateEmbedding
529-
| hbs(22:74): <template>\\n Hello, {{this.target}}!\\n </template>
530-
| ts(22:369): static { ({} as typeof import("@glint/environment-ember-template-imports/-private/dsl")).templateForBackingValue(this, function(__glintRef__, __glintDSL__: typeof import("@glint/environment-ember-template-imports/-private/dsl")) {\\n__glintDSL__.emitContent(__glintDSL__.resolveOrReturn(__glintRef__.this.target)());\\n__glintRef__; __glintDSL__;\\n}) }
531-
|
532-
| | Mapping: Template
533-
| | hbs(32:63): Hello, {{this.target}}!
534-
| | ts(253:337): __glintDSL__.emitContent(__glintDSL__.resolveOrReturn(__glintRef__.this.target)());
535-
| |
536-
| | | Mapping: TextContent
537-
| | | hbs(37:43): Hello,
538-
| | | ts(253:253):
539-
| | |
540-
| | | Mapping: MustacheStatement
541-
| | | hbs(44:59): {{this.target}}
542-
| | | ts(253:335): __glintDSL__.emitContent(__glintDSL__.resolveOrReturn(__glintRef__.this.target)())
543-
| | |
544-
| | | | Mapping: MustacheStatement
545-
| | | | hbs(44:59): {{this.target}}
546-
| | | | ts(278:334): __glintDSL__.resolveOrReturn(__glintRef__.this.target)()
547-
| | | |
548-
| | | | | Mapping: PathExpression
549-
| | | | | hbs(46:57): this.target
550-
| | | | | ts(307:331): __glintRef__.this.target
551-
| | | | |
552-
| | | | | | Mapping: Identifier
553-
| | | | | | hbs(46:50): this
554-
| | | | | | ts(320:324): this
555-
| | | | | |
556-
| | | | | | Mapping: Identifier
557-
| | | | | | hbs(51:57): target
558-
| | | | | | ts(325:331): target
559-
| | | | | |
560-
| | | | |
561-
| | | |
562-
| | |
563-
| | | Mapping: TextContent
564-
| | | hbs(59:60): !
565-
| | | ts(337:337):
566-
| | |
567-
| |
568-
|"
569-
`);
493+
expect(transformedModule?.errors?.length).toBe(0);
494+
expect(transformedModule?.transformedContents).toMatchInlineSnapshot(`
495+
"import type { TOC } from '@ember/component/template-only';
496+
497+
const SmolComp =
498+
({} as typeof import("@glint/environment-ember-template-imports/-private/dsl")).templateExpression(function(__glintRef__, __glintDSL__: typeof import("@glint/environment-ember-template-imports/-private/dsl")) {
499+
__glintDSL__.emitContent(__glintDSL__.resolveOrReturn(__glintRef__.args.name)());
500+
__glintRef__; __glintDSL__;
501+
}) satisfies TOC<{ Args: { name: string }}>;
502+
503+
export default ({} as typeof import("@glint/environment-ember-template-imports/-private/dsl")).templateExpression(function(__glintRef__, __glintDSL__: typeof import("@glint/environment-ember-template-imports/-private/dsl")) {
504+
{
505+
const __glintY__ = __glintDSL__.emitComponent(__glintDSL__.resolve(SmolComp)({
506+
name: "Ember", ...__glintDSL__.NamedArgsMarker }));
507+
__glintY__;
508+
}
509+
__glintRef__; __glintDSL__;
510+
}) satisfies TOC<{ Args: {}, Blocks: {}, Element: null }>
511+
"
512+
`);
570513
});
571514

572515
test('implicit default export', () => {

0 commit comments

Comments
 (0)