Skip to content

Commit a6caf49

Browse files
committed
add basic test app
1 parent 2995ef1 commit a6caf49

File tree

8 files changed

+165
-32
lines changed

8 files changed

+165
-32
lines changed

files/babel.config.cjs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const { buildMacros } = require('@embroider/macros/babel');
2+
3+
const macros = buildMacros();
4+
5+
module.exports = {
6+
plugins: [<% if (typescript) { %>
7+
['@babel/plugin-transform-typescript', { allowDeclareFields: true }],<% } %>
8+
[
9+
'babel-plugin-ember-template-compilation',
10+
{
11+
transforms: [...macros.templateMacros],
12+
},
13+
],
14+
[
15+
'module:decorator-transforms',
16+
{
17+
runtime: {
18+
import: require.resolve('decorator-transforms/runtime-esm'),
19+
},
20+
},
21+
],
22+
...macros.babelMacros,
23+
],
24+
25+
generatorOpts: {
26+
compact: false,
27+
},
28+
};

files/babel.config.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

files/babel.publish.config.cjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = {
2+
plugins: [<% if (typescript) { %>
3+
[
4+
'@babel/plugin-transform-typescript',
5+
{
6+
allExtensions: true,
7+
onlyRemoveTypeImports: true,
8+
allowDeclareFields: true,
9+
},
10+
],<% } %>
11+
[
12+
'babel-plugin-ember-template-compilation',
13+
{
14+
targetFormat: 'hbs',
15+
transforms: []
16+
},
17+
],
18+
[
19+
'module:decorator-transforms',
20+
{
21+
runtime: {
22+
import: 'decorator-transforms/runtime-esm',
23+
},
24+
},
25+
],
26+
],
27+
28+
generatorOpts: {
29+
compact: false,
30+
},
31+
};

files/package.json

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"lint:hbs:fix": "ember-template-lint . --fix --no-error-on-unmatched-pattern",
2525
"lint:js:fix": "eslint . --fix",<% if (typescript) { %>
2626
"lint:types": "glint",<% } %>
27-
"start": "rollup --config --watch",
28-
"test": "echo 'A v2 addon does not have tests, run tests in test-app'",
27+
"start": "vite dev",
28+
"test": "vite build --mode=development && testem --file testem.js ci",
2929
"prepack": "rollup --config"
3030
},
3131
"dependencies": {
@@ -36,12 +36,15 @@
3636
"ember-source": ">= 4.12.0"
3737
},
3838
"devDependencies": {
39-
"@babel/core": "^7.25.2",
40-
<% if (typescript) { %>"@babel/plugin-transform-typescript": "^7.25.2",<% } %>
39+
"@babel/core": "^7.25.2",<% if (typescript) { %>"@babel/plugin-transform-typescript": "^7.25.2",<% } %>
4140
"@babel/eslint-parser": "^7.25.1",
4241
"@babel/runtime": "^7.25.6",
43-
"@eslint/js": "^9.17.0",
44-
"@embroider/addon-dev": "^7.1.0",<% if (typescript) { %>
42+
"@embroider/addon-dev": "^7.1.0",
43+
"@embroider/core": "^4.0.0-alpha.10",
44+
"@embroider/macros": "^1.17.0-alpha.8",
45+
"@embroider/vite": "^1.0.0-alpha.12",
46+
"@ember/test-helpers": "^5.2.0",
47+
"@eslint/js": "^9.17.0",<% if (typescript) { %>
4548
"@glint/core": "^1.4.0",
4649
"@glint/environment-ember-loose": "^1.4.0",
4750
"@glint/environment-ember-template-imports": "^1.4.0",
@@ -50,8 +53,10 @@
5053
"@rollup/plugin-babel": "^6.0.4",
5154
"babel-plugin-ember-template-compilation": "^2.2.5",
5255
"concurrently": "^9.0.1",
53-
"ember-source": "^5.4.0",
56+
"ember-source": "^6.3.0",
57+
"ember-resolver": "^13.1.0",
5458
"ember-template-lint": "^6.0.0",
59+
"ember-qunit": "^9.0.2",
5560
"eslint": "^9.17.0",
5661
"eslint-config-prettier": "^9.1.0",
5762
"eslint-plugin-ember": "^12.3.3",
@@ -61,7 +66,9 @@
6166
"prettier": "^3.4.2",
6267
"prettier-plugin-ember-template-tag": "^2.0.4",
6368
"rollup": "^4.22.5",
64-
"rollup-plugin-copy": "^3.5.0"<% if (typescript) { %>,
69+
"qunit": "^2.24.1",
70+
"qunit-dom": "^3.4.0",
71+
"vite": "^6.2.4"<% if (typescript) { %>,
6572
"typescript-eslint": "^8.19.1",
6673
"typescript": "~5.6.0"<% } %>
6774
},

files/rollup.config.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { babel } from '@rollup/plugin-babel';
22
import { Addon } from '@embroider/addon-dev/rollup';
3+
import { fileURLToPath } from 'node:url';
34

45
const addon = new Addon({
56
srcDir: 'src',
@@ -45,6 +46,10 @@ export default {
4546
babel({
4647
extensions: ['.js', '.gjs'<% if (typescript) { %>, '.ts', '.gts'<% } %>],
4748
babelHelpers: 'bundled',
49+
configFile: resolve(
50+
dirname(fileURLToPath(import.meta.url)),
51+
'./babel.publish.config.cjs',
52+
),
4853
}),
4954

5055
// Ensure that standalone .hbs files are properly integrated as Javascript.

files/tests/index.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title><%= name %> Tests</title>
6+
<meta name="description" content="" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1" />
8+
</head>
9+
<body>
10+
<div id="qunit"></div>
11+
<div id="qunit-fixture">
12+
<div id="ember-testing-container">
13+
<div id="ember-testing"></div>
14+
</div>
15+
</div>
16+
17+
<script src="/testem.js" integrity="" data-embroider-ignore></script>
18+
<script type="module">
19+
import "ember-testing";
20+
// Needed until we have:
21+
// https://github.com/emberjs/ember-test-helpers/pull/1528
22+
globalThis.EmberENV = {};
23+
</script>
24+
25+
<script type="module">
26+
import { start } from "./test-helper.js";
27+
import.meta.glob("./**/*.{js,gjs,gts}", { eager: true });
28+
start();
29+
</script>
30+
</body>
31+
</html>

files/tests/test-helper.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import EmberApp from '@ember/application';
2+
import Resolver from 'ember-resolver';
3+
import EmberRouter from '@ember/routing/router';
4+
5+
class Router extends EmberRouter {
6+
location = 'none';
7+
rootURL = '/';
8+
}
9+
10+
class TestApp extends EmberApp {
11+
modulePrefix = 'test-app';
12+
Resolver = Resolver.withModules({
13+
'test-app/router': { default: Router },
14+
// add any custom services here
15+
});
16+
}
17+
18+
Router.map(function () {});
19+
20+
import * as QUnit from 'qunit';
21+
import { setApplication } from '@ember/test-helpers';
22+
import { setup } from 'qunit-dom';
23+
import { start as qunitStart, setupEmberOnerrorValidation } from 'ember-qunit';
24+
25+
export function start() {
26+
setApplication(
27+
TestApp.create({
28+
autoboot: false,
29+
rootElement: '#ember-testing',
30+
}),
31+
);
32+
setup(QUnit.assert);
33+
setupEmberOnerrorValidation();
34+
qunitStart();
35+
}

files/vite.config.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { defineConfig } from 'vite';
2+
import { extensions, ember, classicEmberSupport } from '@embroider/vite';
3+
import { babel } from '@rollup/plugin-babel';
4+
5+
export default defineConfig({
6+
plugins: [
7+
ember(),
8+
babel({
9+
babelHelpers: 'inline',
10+
extensions,
11+
}),
12+
],
13+
build: {
14+
rollupOptions: {
15+
input: {
16+
tests: 'tests/index.html',
17+
},
18+
},
19+
},
20+
});

0 commit comments

Comments
 (0)