Skip to content

Commit

Permalink
add tests for unique-id helper
Browse files Browse the repository at this point in the history
  • Loading branch information
void-mAlex committed Jun 22, 2024
1 parent 6414375 commit a333b32
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions tests/scenarios/compat-resolver-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ Scenarios.fromProject(() => new Project())
Qmodule(scenario.name, function (hooks) {
let expectTranspiled: (file: string) => ReturnType<ReturnType<ExpectFile>['transform']>;
let givenFiles: (files: Record<string, string>) => void;
let configure: (opts?: Partial<CompatResolverOptions['options']>, extraOpts?: ConfigureOpts) => Promise<void>;
let configure: (
opts?: Partial<CompatResolverOptions['options']>,
extraOpts?: ConfigureOpts,
emberVersion?: string
) => Promise<void>;

interface ConfigureOpts {
appPackageRules?: Partial<PackageRules>;
Expand All @@ -59,13 +63,17 @@ Scenarios.fromProject(() => new Project())
outputFileSync(resolve(app.dir, filename), contents, 'utf8');
}
};
configure = async function (opts?: Partial<CompatResolverOptions['options']>, extraOpts?: ConfigureOpts) {
configure = async function (
opts?: Partial<CompatResolverOptions['options']>,
extraOpts?: ConfigureOpts,
emberVersion = '4.6.0' //based on app-template package.json
) {
let etcOptions: EtcOptions = {
compilerPath: require.resolve('ember-source-latest/dist/ember-template-compiler'),
targetFormat: 'hbs',
transforms: [
...(extraOpts?.astPlugins ?? []),
[require.resolve('@embroider/compat/src/resolver-transform'), { appRoot: app.dir }],
[require.resolve('@embroider/compat/src/resolver-transform'), { appRoot: app.dir, emberVersion }],
],
};

Expand Down Expand Up @@ -1140,6 +1148,36 @@ Scenarios.fromProject(() => new Project())
`);
});

test('built-in helper unique-id is not imported when used with ember source version <5.2', async function () {
givenFiles({
'templates/application.hbs': `{{(unique-id)}}`,
});
await configure({ staticHelpers: true }, undefined, '4.6.0');
expectTranspiled('templates/application.hbs').equalsCode(`
import { precompileTemplate } from "@ember/template-compilation";
export default precompileTemplate("{{(unique-id)}}", {
moduleName: "my-app/templates/application.hbs",
});
`);
});

test('built-in helper unique-id is imported when used with ember source version >=5.2', async function () {
givenFiles({
'templates/application.hbs': `{{(unique-id)}}`,
});
await configure({ staticHelpers: true }, undefined, '5.2.0');
expectTranspiled('templates/application.hbs').equalsCode(`
import { precompileTemplate } from "@ember/template-compilation";
import { uniqueId } from "@ember/helper";
export default precompileTemplate("{{(uniqueId)}}", {
moduleName: "my-app/templates/application.hbs",
scope: () => ({
uniqueId,
}),
});
`);
});

test('built-in modifiers are ignored when used with the modifier keyword', async function () {
givenFiles({
'templates/application.hbs': `{{modifier "on"}}{{modifier "action"}}`,
Expand Down

0 comments on commit a333b32

Please sign in to comment.