Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert built-in blueprints to TypeScript #19962

Merged
merged 14 commits into from
Mar 14, 2022
Merged
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
blueprints/*/*files/**/*.js
blueprints-js/*/*files/**/*.js
blueprints/*/*files/**/*.ts
node-tests/fixtures/**/*.js
/docs/
dist/
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ module.exports = {
'node-tests/**/*.js',
'tests/node/**/*.js',
'blueprints/**/*.js',
'blueprints-js/**/*.js',
'bin/**/*.js',
'tests/docs/*.js',
'config/**/*.js',
Expand Down
48 changes: 48 additions & 0 deletions blueprints-js/-addon-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict';

const stringUtil = require('ember-cli-string-utils');
const path = require('path');
const inflector = require('inflection');

module.exports = {
description: 'Generates an import wrapper.',

fileMapTokens: function () {
return {
__name__: function (options) {
return options.dasherizedModuleName;
},
__path__: function (options) {
return inflector.pluralize(options.locals.blueprintName);
},
__root__: function (options) {
if (options.inRepoAddon) {
return path.join('lib', options.inRepoAddon, 'app');
}
return 'app';
},
};
},

locals: function (options) {
let addonRawName = options.inRepoAddon ? options.inRepoAddon : options.project.name();
let addonName = stringUtil.dasherize(addonRawName);
let fileName = stringUtil.dasherize(options.entity.name);
let blueprintName = options.originBlueprintName;
let modulePathSegments = [
addonName,
inflector.pluralize(options.originBlueprintName),
fileName,
];

if (blueprintName.match(/-addon/)) {
blueprintName = blueprintName.substr(0, blueprintName.indexOf('-addon'));
modulePathSegments = [addonName, inflector.pluralize(blueprintName), fileName];
}

return {
modulePath: modulePathSegments.join('/'),
blueprintName: blueprintName,
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import startApp from '<%= dasherizedPackageName %>/tests/helpers/start-app';
<% if (destroyAppExists) { %>import destroyApp from '<%= dasherizedPackageName %>/tests/helpers/destroy-app';<% } else { %>import { run } from '@ember/runloop';<% } %>

describe('<%= friendlyTestName %>', function () {
let application;

beforeEach(function () {
application = startApp();
});

afterEach(function () {
<% if (destroyAppExists) { %>destroyApp(application);<% } else { %>run(application, 'destroy');<% } %>
});

it('can visit /<%= dasherizedModuleName %>', function () {
visit('/<%= dasherizedModuleName %>');

return andThen(() => {
expect(currentURL()).to.equal('/<%= dasherizedModuleName %>');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { test } from 'qunit';
import moduleForAcceptance from '<%= testFolderRoot %>/tests/helpers/module-for-acceptance';

moduleForAcceptance('<%= friendlyTestName %>');

test('visiting /<%= dasherizedModuleName %>', function (assert) {
visit('/<%= dasherizedModuleName %>');

andThen(function () {
assert.strictEqual(currentURL(), '/<%= dasherizedModuleName %>');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupComponentTest } from 'ember-mocha';<% if (testType === 'integration') { %>
import hbs from 'htmlbars-inline-precompile';<% } %>

describe('<%= friendlyTestDescription %>', function () {
setupComponentTest('<%= componentPathName %>', {
<% if (testType === 'integration' ) { %>integration: true,<% } else if(testType === 'unit') { %>// Specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar'],
unit: true,<% } %>
});

it('renders', function () {
<% if (testType === 'integration' ) { %>// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });

this.render(hbs`<%= selfCloseComponent(componentName) %>`);
expect(this.$()).to.have.length(1);

// Template block usage:
this.render(hbs`
<%= openComponent(componentName) %>
template block text
<%= closeComponent(componentName) %>
`);

expect(this.$().text().trim()).to.equal('template block text');<% } else if(testType === 'unit') { %>// creates the component instance
let component = this.subject();
// renders the component on the page
this.render();
expect(component).to.be.ok;
expect(this.$()).to.have.length(1);<% } %>
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { expect } from 'chai';
import { describeComponent, it } from 'ember-mocha';<% if (testType === 'integration') { %>
import hbs from 'htmlbars-inline-precompile';<% } %>

describeComponent(
'<%= componentPathName %>',
'<%= friendlyTestDescription %>',
{
<% if (testType === 'integration' ) { %>integration: true,<% } else if(testType === 'unit') { %>// Specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar'],
unit: true,<% } %>
},
function () {
it('renders', function () {
<% if (testType === 'integration' ) { %>// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });

this.render(hbs`<%= selfCloseComponent(componentName) %>`);
expect(this.$()).to.have.length(1);

// Template block usage:
this.render(hbs`
<%= openComponent(componentName) %>
template block text
<%= closeComponent(componentName) %>
`);

expect(this.$().text().trim()).to.equal('template block text');<% } else if(testType === 'unit') { %>// creates the component instance
let component = this.subject();
// renders the component on the page
this.render();
expect(component).to.be.ok;
expect(this.$()).to.have.length(1);<% } %>
});
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { moduleForComponent, test } from 'ember-qunit';<% if (testType === 'integration') { %>
import hbs from 'htmlbars-inline-precompile';<% } %>

moduleForComponent('<%= componentPathName %>', '<%= friendlyTestDescription %>', {
<% if (testType === 'integration' ) { %>integration: true,<% } else if(testType === 'unit') { %>// Specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar'],
unit: true,<% } %>
});

test('it renders', function (assert) {<% if (testType === 'integration' ) { %>
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });

this.render(hbs`<%= selfCloseComponent(componentName) %>`);

assert.strictEqual(this.$().text().trim(), '');

// Template block usage:
this.render(hbs`
<%= openComponent(componentName) %>
template block text
<%= closeComponent(componentName) %>
`);

assert.strictEqual(this.$().text().trim(), 'template block text');<% } else if(testType === 'unit') { %>
// Creates the component instance
/*let component =*/ this.subject();
// Renders the component to the page
this.render();
assert.strictEqual(this.$().text().trim(), '');<% } %>
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';

describe('<%= friendlyTestDescription %>', function () {
setupTest('controller:<%= dasherizedModuleName %>', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});

// TODO: Replace this with your real tests.
it('exists', function () {
let controller = this.subject();
expect(controller).to.be.ok;
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { expect } from 'chai';
import { describeModule, it } from 'ember-mocha';

describeModule(
'controller:<%= dasherizedModuleName %>',
'<%= friendlyTestDescription %>',
{
// Specify the other units that are required for this test.
// needs: ['controller:foo']
},
function () {
// TODO: Replace this with your real tests.
it('exists', function () {
let controller = this.subject();
expect(controller).to.be.ok;
});
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { moduleFor, test } from 'ember-qunit';

moduleFor('controller:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', {
// Specify the other units that are required for this test.
// needs: ['controller:foo']
});

// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let controller = this.subject();
assert.ok(controller);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupComponentTest } from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';

describe('<%= friendlyTestName %>', function () {
setupComponentTest('<%= dasherizedModuleName %>', {
integration: true,
});

it('renders', function () {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
// Template block usage:
// this.render(hbs`
// {{#<%= dasherizedModuleName %>}}
// template content
// {{/<%= dasherizedModuleName %>}}
// `);
this.set('inputValue', '1234');

this.render(hbs`{{<%= dasherizedModuleName %> this.inputValue}}`);

expect(this.$().text().trim()).to.equal('1234');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from 'chai';
import { describeComponent, it } from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';

describeComponent(
'<%= dasherizedModuleName %>',
'helper:<%= dasherizedModuleName %>',
{
integration: true,
},
function () {
it('renders', function () {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
// Template block usage:
// this.render(hbs`
// {{#<%= dasherizedModuleName %>}}
// template content
// {{/<%= dasherizedModuleName %>}}
// `);
this.set('inputValue', '1234');

this.render(hbs`{{<%= dasherizedModuleName %> this.inputValue}}`);

expect(this.$().text().trim()).to.equal('1234');
});
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('<%= dasherizedModuleName %>', 'helper:<%= dasherizedModuleName %>', {
integration: true,
});

// TODO: Replace this with your real tests.
test('it renders', function (assert) {
this.set('inputValue', '1234');

this.render(hbs`{{<%= dasherizedModuleName %> this.inputValue}}`);

assert.strictEqual(this.$().text().trim(), '1234');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { helper as buildHelper } from '@ember/component/helper';

export function <%= camelizedModuleName %>(positional /*, named*/) {
return positional;
}

export const helper = buildHelper(<%= camelizedModuleName %>);
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from 'chai';
import { describe, it, beforeEach, afterEach } from 'mocha';
import { run } from '@ember/runloop';
import Application from '@ember/application';
import { initialize } from '<%= modulePrefix %>/initializers/<%= dasherizedModuleName %>';
<% if (destroyAppExists) { %>import destroyApp from '../../helpers/destroy-app';\n<% } %>
describe('<%= friendlyTestName %>', function () {
let application;

beforeEach(function () {
run(function () {
application = Application.create();
application.deferReadiness();
});
});

afterEach(function () {
<% if (destroyAppExists) { %>destroyApp(application);<% } else { %>run(application, 'destroy');<% } %>
});

// TODO: Replace this with your real tests.
it('works', function () {
initialize(application);

// you would normally confirm the results of the initializer here
expect(true).to.be.ok;
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect } from 'chai';
import { describe, it, beforeEach, afterEach } from 'mocha';
import Application from '@ember/application';
import { initialize } from '<%= modulePrefix %>/initializers/<%= dasherizedModuleName %>';
<% if (destroyAppExists) { %>import destroyApp from '../../helpers/destroy-app';<% } else { %>import { run } from '@ember/runloop';<% } %>

describe('<%= friendlyTestName %>', function () {
beforeEach(function () {
this.TestApplication = Application.extend();
this.TestApplication.initializer({
name: 'initializer under test',
initialize,
});

this.application = this.TestApplication.create({
autoboot: false,
});
});

afterEach(function () {
<% if (destroyAppExists) { %>destroyApp(this.application);<% } else { %>run(this.application, 'destroy');<% } %>
});

// TODO: Replace this with your real tests.
it('works', async function () {
await this.application.boot();

// you would normally confirm the results of the initializer here
expect(true).to.be.ok;
});
});
Loading