Skip to content

Commit

Permalink
Merge pull request #190 from lukemelia/gts-error
Browse files Browse the repository at this point in the history
Update config templates to properly handle .gts files
  • Loading branch information
NullVoxPopuli authored Sep 6, 2023
2 parents 4581f7d + 680ce5c commit c7ad65d
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 6 deletions.
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

0 comments on commit c7ad65d

Please sign in to comment.