Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update config templates to properly handle .gts files #190

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion files/__addonLocation__/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
overrides: [
<% if (typescript) { %> // ts files
{
files: ['**/*.ts'],
files: ['**/*.ts', '**/*.gts'],
extends: [
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
Expand Down
2 changes: 1 addition & 1 deletion files/__addonLocation__/babel.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
<% if (typescript) { %> "presets": [["@babel/preset-typescript"]],
<% if (typescript) { %> "presets": [["@babel/preset-typescript", { "allExtensions": true, "onlyRemoveTypeImports": true }]],
<% } %> "plugins": [
"@embroider/addon-dev/template-colocation-plugin",
"@babel/plugin-transform-class-static-block",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Component from '@glimmer/component';
import TemplateOnly from './template-only';
import { on } from '@ember/modifier';

export default class CoLocated extends Component {
export default class TemplateImport extends Component {
<template>
Hello from a GJS file but also <TemplateOnly />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Rendering | template-only', function(hooks) {
module('Rendering | template-import', function(hooks) {
setupRenderingTest(hooks);

test('it renders', async function(assert) {
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/typescript/my-addon/src/components/another-gts.gts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Component from '@glimmer/component';

interface Signature {
Element: HTMLDivElement;
}

export default class AnotherGts extends Component<Signature> {
greeting = "Hello";
<template>
<div ...attributes>
{{this.greeting}} from another GTS file!
</div>
</template>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Component from '@glimmer/component';
import TemplateOnly from './template-only';
import AnotherGts from './another-gts.gts'; // N.B. relative imports inside a v2 addon should have explicit file extensions (this is consistent with how node treats ES modules)
import { on } from '@ember/modifier';
import { action } from '@ember/object';
import { fn } from '@ember/helper';

interface Signature {
Element: HTMLDivElement;
Args: {
saying?: string;
};
}

export default class TemplateImport extends Component<Signature> {
<template>
<div ...attributes>
Hello from a GTS file but also <TemplateOnly /> and <AnotherGts />

<button {{on "click" (fn this.saySomething @saying)}}></button>
</div>
</template>

@action
saySomething(sayWhat: string | undefined) {
console.log(sayWhat || "something");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Rendering | template-import', function(hooks) {
setupRenderingTest(hooks);

test('it renders', async function(assert) {
await render(hbs`<TemplateImport @saying="what" />`);

assert.dom().hasText('Hello from a GTS file but also Hello from a template-only component and Hello from another GTS file!');
})
});
4 changes: 2 additions & 2 deletions tests/smoke-tests/--typescript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ for (let packageManager of SUPPORTED_PACKAGE_MANAGERS) {
let testResult = await helper.run('test');

expect(testResult.exitCode).toEqual(0);
expect(testResult.stdout).to.include('# tests 4');
expect(testResult.stdout).to.include('# pass 4');
expect(testResult.stdout).to.include('# tests 5');
expect(testResult.stdout).to.include('# pass 5');
expect(testResult.stdout).to.include('# fail 0');
});
});
Expand Down