Skip to content

Commit

Permalink
Refactor to use existing shouldTransformTypeScript infrastructure
Browse files Browse the repository at this point in the history
`
  • Loading branch information
simonihmig committed Aug 18, 2022
1 parent 7ed8d2f commit 25aa489
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 22 deletions.
11 changes: 2 additions & 9 deletions blueprints/addon/index.js
Expand Up @@ -29,6 +29,8 @@ module.exports = {
description,
appBlueprintName: 'app',

shouldTransformTypeScript: true,

filesToRemove: [
'tests/dummy/app/styles/.gitkeep',
'tests/dummy/app/templates/.gitkeep',
Expand Down Expand Up @@ -170,15 +172,6 @@ module.exports = {
lang: options.lang,
ciProvider: options.ciProvider,
typescript: options.typescript,
ext: options.typescript ? 'ts' : 'js',
};
},

fileMapTokens(options) {
let { ext } = options.locals;

return {
__ext__: () => ext,
};
},

Expand Down
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions blueprints/app/files/tests/helpers/index.ts
@@ -0,0 +1,51 @@
import {
setupApplicationTest as upstreamSetupApplicationTest,
setupRenderingTest as upstreamSetupRenderingTest,
setupTest as upstreamSetupTest,
} from 'ember-qunit';

// This file exists to provide wrappers around ember-qunit's / ember-mocha's
// test setup functions. This way, you can easily extend the setup that is
// needed per test type.

function setupApplicationTest(
hooks: Parameters<typeof upstreamSetupApplicationTest>[0],
options?: Parameters<typeof upstreamSetupApplicationTest>[1]
) {
upstreamSetupApplicationTest(hooks, options);

// Additional setup for application tests can be done here.
//
// For example, if you need an authenticated session for each
// application test, you could do:
//
// hooks.beforeEach(async function () {
// await authenticateSession(); // ember-simple-auth
// });
//
// This is also a good place to call test setup functions coming
// from other addons:
//
// setupIntl(hooks); // ember-intl
// setupMirage(hooks); // ember-cli-mirage
}

function setupRenderingTest(
hooks: Parameters<typeof upstreamSetupApplicationTest>[0],
options?: Parameters<typeof upstreamSetupApplicationTest>[1]
) {
upstreamSetupRenderingTest(hooks, options);

// Additional setup for rendering tests can be done here.
}

function setupTest(
hooks: Parameters<typeof upstreamSetupApplicationTest>[0],
options?: Parameters<typeof upstreamSetupApplicationTest>[1]
) {
upstreamSetupTest(hooks, options);

// Additional setup for unit tests can be done here.
}

export { setupApplicationTest, setupRenderingTest, setupTest };
File renamed without changes.
11 changes: 2 additions & 9 deletions blueprints/app/index.js
Expand Up @@ -8,6 +8,8 @@ const directoryForPackageName = require('../../lib/utilities/directory-for-packa
module.exports = {
description: 'The default blueprint for ember-cli projects.',

shouldTransformTypeScript: true,

filesToRemove: [
'app/styles/.gitkeep',
'app/templates/.gitkeep',
Expand Down Expand Up @@ -58,7 +60,6 @@ module.exports = {
lang: options.lang,
ciProvider: options.ciProvider,
typescript: options.typescript,
ext: options.typescript ? 'ts' : 'js',
};
},

Expand All @@ -77,14 +78,6 @@ module.exports = {
return this._files;
},

fileMapTokens(options) {
let { ext } = options.locals;

return {
__ext__: () => ext,
};
},

beforeInstall() {
const version = require('../../package.json').version;
const prependEmoji = require('../../lib/utilities/prepend-emoji');
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/init-test.js
Expand Up @@ -47,11 +47,11 @@ describe('Acceptance: ember init', function () {
process.chdir(root);
});

function confirmBlueprinted(ext = 'js') {
function confirmBlueprinted(typescript = false) {
let blueprintPath = path.join(root, 'blueprints', 'app', 'files');
// ignore .travis.yml
let expected = walkSync(blueprintPath, { ignore: ['.travis.yml'] })
.map((name) => name.replace('__ext__', ext))
.map((name) => (typescript ? name : name.replace(/\.ts$/, '.js')))
.sort();
let actual = walkSync('.').sort();

Expand Down
7 changes: 5 additions & 2 deletions tests/acceptance/new-test.js
Expand Up @@ -43,10 +43,13 @@ describe('Acceptance: ember new', function () {
return tmp.teardown(tmpDir);
});

function confirmBlueprintedForDir(blueprintDir, expectedAppDir = 'foo', ext = 'js') {
function confirmBlueprintedForDir(blueprintDir, expectedAppDir = 'foo', typescript = false) {
let blueprintPath = path.join(root, blueprintDir, 'files');
// ignore .travis.yml
let expected = walkSync(blueprintPath, { ignore: ['.travis.yml'] }).map((name) => name.replace('__ext__', ext));
let expected = walkSync(blueprintPath, { ignore: ['.travis.yml'] }).map((name) =>
typescript ? name : name.replace(/\.ts$/, '.js')
);

let actual = walkSync('.').sort();
let directory = path.basename(process.cwd());

Expand Down
File renamed without changes.
51 changes: 51 additions & 0 deletions tests/fixtures/app/typescript-embroider/tests/helpers/index.ts
@@ -0,0 +1,51 @@
import {
setupApplicationTest as upstreamSetupApplicationTest,
setupRenderingTest as upstreamSetupRenderingTest,
setupTest as upstreamSetupTest,
} from 'ember-qunit';

// This file exists to provide wrappers around ember-qunit's / ember-mocha's
// test setup functions. This way, you can easily extend the setup that is
// needed per test type.

function setupApplicationTest(
hooks: Parameters<typeof upstreamSetupApplicationTest>[0],
options?: Parameters<typeof upstreamSetupApplicationTest>[1]
) {
upstreamSetupApplicationTest(hooks, options);

// Additional setup for application tests can be done here.
//
// For example, if you need an authenticated session for each
// application test, you could do:
//
// hooks.beforeEach(async function () {
// await authenticateSession(); // ember-simple-auth
// });
//
// This is also a good place to call test setup functions coming
// from other addons:
//
// setupIntl(hooks); // ember-intl
// setupMirage(hooks); // ember-cli-mirage
}

function setupRenderingTest(
hooks: Parameters<typeof upstreamSetupApplicationTest>[0],
options?: Parameters<typeof upstreamSetupApplicationTest>[1]
) {
upstreamSetupRenderingTest(hooks, options);

// Additional setup for rendering tests can be done here.
}

function setupTest(
hooks: Parameters<typeof upstreamSetupApplicationTest>[0],
options?: Parameters<typeof upstreamSetupApplicationTest>[1]
) {
upstreamSetupTest(hooks, options);

// Additional setup for unit tests can be done here.
}

export { setupApplicationTest, setupRenderingTest, setupTest };
51 changes: 51 additions & 0 deletions tests/fixtures/app/typescript/tests/helpers/index.ts
@@ -0,0 +1,51 @@
import {
setupApplicationTest as upstreamSetupApplicationTest,
setupRenderingTest as upstreamSetupRenderingTest,
setupTest as upstreamSetupTest,
} from 'ember-qunit';

// This file exists to provide wrappers around ember-qunit's / ember-mocha's
// test setup functions. This way, you can easily extend the setup that is
// needed per test type.

function setupApplicationTest(
hooks: Parameters<typeof upstreamSetupApplicationTest>[0],
options?: Parameters<typeof upstreamSetupApplicationTest>[1]
) {
upstreamSetupApplicationTest(hooks, options);

// Additional setup for application tests can be done here.
//
// For example, if you need an authenticated session for each
// application test, you could do:
//
// hooks.beforeEach(async function () {
// await authenticateSession(); // ember-simple-auth
// });
//
// This is also a good place to call test setup functions coming
// from other addons:
//
// setupIntl(hooks); // ember-intl
// setupMirage(hooks); // ember-cli-mirage
}

function setupRenderingTest(
hooks: Parameters<typeof upstreamSetupApplicationTest>[0],
options?: Parameters<typeof upstreamSetupApplicationTest>[1]
) {
upstreamSetupRenderingTest(hooks, options);

// Additional setup for rendering tests can be done here.
}

function setupTest(
hooks: Parameters<typeof upstreamSetupApplicationTest>[0],
options?: Parameters<typeof upstreamSetupApplicationTest>[1]
) {
upstreamSetupTest(hooks, options);

// Additional setup for unit tests can be done here.
}

export { setupApplicationTest, setupRenderingTest, setupTest };

0 comments on commit 25aa489

Please sign in to comment.