Skip to content

Commit

Permalink
feature flag typescript blueprint functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
cafreeman committed Feb 16, 2022
1 parent 2ea2b2d commit ef25864
Show file tree
Hide file tree
Showing 97 changed files with 1,137 additions and 49 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
blueprints/*/*files/**/*.js
blueprints-js/*/*files/**/*.js
blueprints/*/*files/**/*.ts
node-tests/fixtures/**/*.js
/docs/
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,13 @@
import { describe, it } from 'mocha';
import { expect } from 'chai';
import { setupApplicationTest } from 'ember-mocha';
import { visit, currentURL } from '@ember/test-helpers';

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

it('can visit /<%= dasherizedModuleName %>', async function () {
await visit('/<%= dasherizedModuleName %>');
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,13 @@
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';

module('<%= friendlyTestName %>', function (hooks) {
setupApplicationTest(hooks);

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

assert.strictEqual(currentURL(), '/<%= dasherizedModuleName %>');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '<%= modulePath %>';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '<%= modulePath %>';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= importComponent %>
<%= importTemplate %>
export default <%= defaultExport %>
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,38 @@
<% if (testType === 'integration') { %>import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupRenderingTest } from 'ember-mocha';
import { render } from '@ember/test-helpers';
<%= hbsImportStatement %>

describe('<%= friendlyTestDescription %>', function () {
setupRenderingTest();

it('renders', async function () {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

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

expect(this.element.textContent.trim()).to.equal('');

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

expect(this.element.textContent.trim()).to.equal('template block text');
});
});<% } else if (testType === 'unit') { %>import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';

describe('<%= friendlyTestDescription %>', function () {
setupTest();

it('exists', function () {
let component = this.owner.factoryFor('component:<%= componentPathName %>').create();
expect(component).to.be.ok;
});
});<% } %>
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,36 @@
<% if (testType === 'integration') { %>import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
<%= hbsImportStatement %>

module('<%= friendlyTestDescription %>', function (hooks) {
setupRenderingTest(hooks);

test('it renders', async function (assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

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

assert.dom(this.element).hasText('');

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

assert.dom(this.element).hasText('template block text');
});
});<% } else if (testType === 'unit') { %>import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('<%= friendlyTestDescription %>', function (hooks) {
setupTest(hooks);

test('it exists', function (assert) {
let component = this.owner.factoryFor('component:<%= componentPathName %>').create();
assert.ok(component);
});
});<% } %>
3 changes: 3 additions & 0 deletions blueprints-js/component/files/__root__/__path__/__name__.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= importComponent %>
<%= importTemplate %>
export default <%= defaultExport %>
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,13 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { setupTest } from 'ember-mocha';

describe('<%= friendlyTestDescription %>', function () {
setupTest();

// TODO: Replace this with your real tests.
it('exists', function () {
let controller = this.owner.lookup('controller:<%= controllerPathName %>');
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);
});
Loading

0 comments on commit ef25864

Please sign in to comment.