Skip to content
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
10 changes: 8 additions & 2 deletions src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export function defineGenerator({
Math.max(...templateCompiled.split("\n").map((line) => line.length)),
);

consola.log(border);
consola.log(targetFile.path());
consola.log(border);
consola.log("");
consola.log(templateCompiled);
Expand Down Expand Up @@ -177,13 +179,17 @@ export function defineGenerator({
}

export function defineTestGenerator(
options: GeneratorOptions & { testsDir: string },
options: GeneratorOptions & { testsDir: string; testsSubDir?: string },
): Generator {
return defineGenerator({
...options,
modifyTargetFile: (targetFile, args) => {
if (args.path === undefined) {
targetFile.subDir = join("tests", options.testsDir, options.name + "s");
targetFile.subDir = join(
"tests",
options.testsDir,
options.testsSubDir ?? options.name + "s",
);
}

targetFile.name += "-test";
Expand Down
7 changes: 7 additions & 0 deletions src/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ export const generators: Generator[] = [
name: "service",
testsDir: "unit",
}),

defineTestGenerator({
args: [name(), path(), typescript()],
name: "acceptance",
testsDir: "acceptance",
testsSubDir: "",
}),
];
13 changes: 13 additions & 0 deletions templates/acceptance-test/acceptance-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { currentURL, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from '{{testHelpersImportPath}}';

module('Acceptance | {{name.path}}', function (hooks) {
setupApplicationTest(hooks);

test('it visits /{{name.path}}', async function (assert) {
await visit('/{{name.path}}');

assert.strictEqual(currentURL(), '/{{name.path}}');
});
});
13 changes: 13 additions & 0 deletions templates/acceptance-test/acceptance-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { currentURL, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from '{{testHelpersImportPath}}';

module('Acceptance | {{name.path}}', function (hooks) {
setupApplicationTest(hooks);

test('it visits /{{name.path}}', async function (assert) {
await visit('/{{name.path}}');

assert.strictEqual(currentURL(), '/{{name.path}}');
});
});
69 changes: 69 additions & 0 deletions test/__snapshots__/acceptance-test.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`generates a \`.js\` acceptance-test 1`] = `
"import { currentURL, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'v2-addon/tests/helpers';

module('Acceptance | foo', function (hooks) {
setupApplicationTest(hooks);

test('it visits /foo', async function (assert) {
await visit('/foo');

assert.strictEqual(currentURL(), '/foo');
});
});
"
`;

exports[`generates a \`.js\` acceptance-test at a custom path 1`] = `
"import { currentURL, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'v2-addon/tests/helpers';

module('Acceptance | foo', function (hooks) {
setupApplicationTest(hooks);

test('it visits /foo', async function (assert) {
await visit('/foo');

assert.strictEqual(currentURL(), '/foo');
});
});
"
`;

exports[`generates a \`.ts\` acceptance-test 1`] = `
"import { currentURL, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'v2-addon/tests/helpers';

module('Acceptance | foo', function (hooks) {
setupApplicationTest(hooks);

test('it visits /foo', async function (assert) {
await visit('/foo');

assert.strictEqual(currentURL(), '/foo');
});
});
"
`;

exports[`generates a \`.ts\` acceptance-test at a custom path 1`] = `
"import { currentURL, visit } from '@ember/test-helpers';
import { module, test } from 'qunit';
import { setupApplicationTest } from 'v2-addon/tests/helpers';

module('Acceptance | foo', function (hooks) {
setupApplicationTest(hooks);

test('it visits /foo', async function (assert) {
await visit('/foo');

assert.strictEqual(currentURL(), '/foo');
});
});
"
`;
46 changes: 46 additions & 0 deletions test/acceptance-test.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { afterEach, it } from "vitest";
import { Package } from "./helpers.ts";

let pkg: Package;

afterEach(() => pkg.cleanUp());

it("generates a `.js` acceptance-test", async (ctx) => {
pkg = await Package.create("v2-addon");

await pkg.gember("acceptance-test", "foo");

const content = await pkg.readFile("tests/acceptance/foo-test.js");

ctx.expect(content).toMatchSnapshot();
});

it("generates a `.js` acceptance-test at a custom path", async (ctx) => {
pkg = await Package.create("v2-addon");

await pkg.gember("acceptance-test", "foo", "--path=tests/foo");

const content = await pkg.readFile("tests/foo/foo-test.js");

ctx.expect(content).toMatchSnapshot();
});

it("generates a `.ts` acceptance-test", async (ctx) => {
pkg = await Package.create("v2-addon");

await pkg.gember("acceptance-test", "foo", "--ts");

const content = await pkg.readFile("tests/acceptance/foo-test.ts");

ctx.expect(content).toMatchSnapshot();
});

it("generates a `.ts` acceptance-test at a custom path", async (ctx) => {
pkg = await Package.create("v2-addon");

await pkg.gember("acceptance-test", "foo", "--path=tests/foo", "--ts");

const content = await pkg.readFile("tests/foo/foo-test.ts");

ctx.expect(content).toMatchSnapshot();
});
Loading