Skip to content

Commit

Permalink
Merge pull request #47 from embroider-build/custom-component-test
Browse files Browse the repository at this point in the history
Update to use explicit resolve.extensions
  • Loading branch information
ef4 authored Aug 1, 2024
2 parents d67fed0 + c986503 commit e15c3ef
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
22 changes: 14 additions & 8 deletions files/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,24 @@ import { resolve } from 'path';
import { babel } from '@rollup/plugin-babel';

const root = 'tmp/rewritten-app';
const extensions = [
'.mjs',
'.gjs',
'.js',
'.mts',
'.gts',
'.ts',
'.hbs',
'.json',
];

export default defineConfig(({ mode }) => {
return {
root,
// esbuild in vite does not support decorators
esbuild: false,
cacheDir: resolve('node_modules', '.vite'),
resolve: {
extensions,
},
plugins: [
hbs(),
templateTag(),
Expand All @@ -31,12 +42,7 @@ export default defineConfig(({ mode }) => {

babel({
babelHelpers: 'runtime',

// this needs .hbs because our hbs() plugin above converts them to
// javascript but the javascript still also needs babel, but we don't want
// to rename them because vite isn't great about knowing how to hot-reload
// them if we resolve them to made-up names.
extensions: ['.gjs', '.js', '.hbs', '.ts', '.gts'],
extensions,
}),
],
optimizeDeps: optimizeDeps(),
Expand Down
3 changes: 3 additions & 0 deletions tests/fixture/app/components/custom-component.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="custom-component">
I am a custom component
</div>
1 change: 1 addition & 0 deletions tests/fixture/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export default class Router extends EmberRouter {

Router.map(function () {
this.route('styles');
this.route('custom-component');
});
1 change: 1 addition & 0 deletions tests/fixture/app/templates/custom-component.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<CustomComponent />
14 changes: 14 additions & 0 deletions tests/fixture/tests/acceptance/custom-component-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from '<%= name %>/tests/helpers';

module('Acceptance | custom-component page', function (hooks) {
setupApplicationTest(hooks);

test('visiting /custom-component', async function (assert) {
await visit('/custom-component');

assert.strictEqual(currentURL(), '/custom-component');
assert.dom('#custom-component').containsText('I am a custom component');
});
})

0 comments on commit e15c3ef

Please sign in to comment.