diff --git a/src/generator.ts b/src/generator.ts
index 2f3db9b..a01b0fd 100644
--- a/src/generator.ts
+++ b/src/generator.ts
@@ -1,10 +1,10 @@
import { camelCase, pascalCase, pathCase } from "change-case";
import consola from "consola";
-import { ensureDir, readJson } from "fs-extra/esm";
+import { ensureDir, pathExists, readJson } from "fs-extra/esm";
import Handlebars from "handlebars";
import { readFile, writeFile } from "node:fs/promises";
import { dirname, join, relative } from "node:path";
-import { cwd, stdout } from "node:process";
+import { cwd } from "node:process";
import { fileURLToPath } from "node:url";
import { resolveConfig, type Config } from "./config.js";
import { FileReference } from "./file-reference.js";
@@ -117,10 +117,17 @@ export function defineGenerator({
signature: entityNameCases.pascal + "Signature",
},
package: packageJson,
+ testHelpersImportPath:
+ (await pathExists(join(packagePath, "tests", "helpers.js"))) ||
+ (await pathExists(join(packagePath, "tests", "helpers.ts")))
+ ? `${packageJson.name}/tests/helpers`
+ : "ember-qunit",
});
if (resolvedArgs.log) {
- const border = "─".repeat(stdout.columns ? stdout.columns / 2 : 120);
+ const border = "─".repeat(
+ Math.max(...templateCompiled.split("\n").map((line) => line.length)),
+ );
consola.log(border);
consola.log("");
diff --git a/templates/component-test/component-test.gjs b/templates/component-test/component-test.gjs
index da45d40..6b6f8af 100644
--- a/templates/component-test/component-test.gjs
+++ b/templates/component-test/component-test.gjs
@@ -1,7 +1,7 @@
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import {{name.pascal}} from '{{package.name}}/components/{{name.path}}';
-import { setupRenderingTest } from '{{package.name}}/tests/helpers';
+import { setupRenderingTest } from '{{testHelpersImportPath}}';
module('Integration | Component | {{name.pascal}}', function (hooks) {
setupRenderingTest(hooks);
diff --git a/templates/component-test/component-test.gts b/templates/component-test/component-test.gts
index da45d40..6b6f8af 100644
--- a/templates/component-test/component-test.gts
+++ b/templates/component-test/component-test.gts
@@ -1,7 +1,7 @@
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
import {{name.pascal}} from '{{package.name}}/components/{{name.path}}';
-import { setupRenderingTest } from '{{package.name}}/tests/helpers';
+import { setupRenderingTest } from '{{testHelpersImportPath}}';
module('Integration | Component | {{name.pascal}}', function (hooks) {
setupRenderingTest(hooks);
diff --git a/templates/helper-test/helper-test.gjs b/templates/helper-test/helper-test.gjs
index e07a681..f1c362c 100644
--- a/templates/helper-test/helper-test.gjs
+++ b/templates/helper-test/helper-test.gjs
@@ -1,6 +1,6 @@
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
-import { setupRenderingTest } from '{{package.name}}/tests/helpers';
+import { setupRenderingTest } from '{{testHelpersImportPath}}';
module('Integration | Helper | {{name.camel}}', function (hooks) {
setupRenderingTest(hooks);
diff --git a/templates/helper-test/helper-test.gts b/templates/helper-test/helper-test.gts
index e07a681..f1c362c 100644
--- a/templates/helper-test/helper-test.gts
+++ b/templates/helper-test/helper-test.gts
@@ -1,6 +1,6 @@
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
-import { setupRenderingTest } from '{{package.name}}/tests/helpers';
+import { setupRenderingTest } from '{{testHelpersImportPath}}';
module('Integration | Helper | {{name.camel}}', function (hooks) {
setupRenderingTest(hooks);
diff --git a/templates/modifier-test/modifier-test.gjs b/templates/modifier-test/modifier-test.gjs
index 8826f8d..676357f 100644
--- a/templates/modifier-test/modifier-test.gjs
+++ b/templates/modifier-test/modifier-test.gjs
@@ -1,6 +1,6 @@
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
-import { setupRenderingTest } from '{{package.name}}/tests/helpers';
+import { setupRenderingTest } from '{{testHelpersImportPath}}';
module('Integration | Modifier | {{name.camel}}', function (hooks) {
setupRenderingTest(hooks);
diff --git a/templates/modifier-test/modifier-test.gts b/templates/modifier-test/modifier-test.gts
index 8826f8d..676357f 100644
--- a/templates/modifier-test/modifier-test.gts
+++ b/templates/modifier-test/modifier-test.gts
@@ -1,6 +1,6 @@
import { render } from '@ember/test-helpers';
import { module, test } from 'qunit';
-import { setupRenderingTest } from '{{package.name}}/tests/helpers';
+import { setupRenderingTest } from '{{testHelpersImportPath}}';
module('Integration | Modifier | {{name.camel}}', function (hooks) {
setupRenderingTest(hooks);
diff --git a/templates/service-test/service-test.js b/templates/service-test/service-test.js
index d935a9e..a50dc95 100644
--- a/templates/service-test/service-test.js
+++ b/templates/service-test/service-test.js
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
-import { setupTest } from '{{package.name}}/tests/helpers';
+import { setupTest } from '{{testHelpersImportPath}}';
module('Unit | Service | {{name.pascal}}', function (hooks) {
setupTest(hooks);
diff --git a/templates/service-test/service-test.ts b/templates/service-test/service-test.ts
index d935a9e..a50dc95 100644
--- a/templates/service-test/service-test.ts
+++ b/templates/service-test/service-test.ts
@@ -1,5 +1,5 @@
import { module, test } from 'qunit';
-import { setupTest } from '{{package.name}}/tests/helpers';
+import { setupTest } from '{{testHelpersImportPath}}';
module('Unit | Service | {{name.pascal}}', function (hooks) {
setupTest(hooks);
diff --git a/test/__snapshots__/support.test.ts.snap b/test/__snapshots__/support.test.ts.snap
index 215464d..fcbbe31 100644
--- a/test/__snapshots__/support.test.ts.snap
+++ b/test/__snapshots__/support.test.ts.snap
@@ -15,6 +15,34 @@ exports[`supports v2 addons 1`] = `
"
`;
+exports[`supports v2 addons 2`] = `
+"import { render } from '@ember/test-helpers';
+import { module, test } from 'qunit';
+import Foo from 'v2-addon/components/foo';
+import { setupRenderingTest } from 'ember-qunit';
+
+module('Integration | Component | Foo', function (hooks) {
+ setupRenderingTest(hooks);
+
+ test('it renders', async function (assert) {
+ await render();
+
+ assert.dom().hasText('');
+
+ await render(
+
+
+ template block text
+
+
+ );
+
+ assert.dom().hasText('template block text');
+ });
+});
+"
+`;
+
exports[`supports v2 apps 1`] = `
"{{yield}}
"
diff --git a/test/helpers.ts b/test/helpers.ts
index c7590b3..87a3347 100644
--- a/test/helpers.ts
+++ b/test/helpers.ts
@@ -25,6 +25,10 @@ export class Package {
return readFile(join(this.path, path), "utf-8");
}
+ async remove(path: string): Promise {
+ await remove(join(this.path, path));
+ }
+
static async create(name: string, path: string = uuidv4()): Promise {
const pkg = new this(join("test", "output", path));
diff --git a/test/packages/v2-addon/tests/helpers.ts b/test/packages/v2-addon/tests/helpers.ts
new file mode 100644
index 0000000..e69de29
diff --git a/test/support.test.ts b/test/support.test.ts
index e5a7e2b..44edfd9 100644
--- a/test/support.test.ts
+++ b/test/support.test.ts
@@ -38,9 +38,12 @@ it("supports v1 addons", async (ctx) => {
it("supports v2 addons", async (ctx) => {
pkg = await Package.create("v2-addon");
+ await pkg.remove("tests/helpers.ts");
await pkg.gember("component", "foo");
+ await pkg.gember("component-test", "foo");
- const content = await pkg.readFile("src/components/foo.gjs");
-
- ctx.expect(content).toMatchSnapshot();
+ ctx.expect(await pkg.readFile("src/components/foo.gjs")).toMatchSnapshot();
+ ctx
+ .expect(await pkg.readFile("tests/integration/components/foo-test.gjs"))
+ .toMatchSnapshot();
});