Skip to content
This repository has been archived by the owner on Nov 25, 2018. It is now read-only.

Commit

Permalink
Import blueprints from ember.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Mar 15, 2016
1 parent c5a0ad3 commit ea9d810
Show file tree
Hide file tree
Showing 60 changed files with 4,685 additions and 92 deletions.
54 changes: 54 additions & 0 deletions blueprints/-addon-import.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*jshint node:true*/

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

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

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

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

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

if (options.pod) {
modulePathSegments = [addonName, fileName, blueprintName];
}

return {
modulePath: modulePathSegments.join('/'),
blueprintName: blueprintName
};
}
};
21 changes: 0 additions & 21 deletions blueprints/acceptance-test/files/tests/acceptance/__name__-test.js

This file was deleted.

15 changes: 12 additions & 3 deletions blueprints/acceptance-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
var testInfo = require('ember-cli-test-info');
var pathUtil = require('ember-cli-path-utils');
var stringUtils = require('ember-cli-string-utils');
var existsSync = require('exists-sync');
var path = require('path');
var useTestFrameworkDetector = require('../test-framework-detector');

module.exports = {
module.exports = useTestFrameworkDetector({
description: 'Generates an acceptance test for a feature.',

locals: function(options) {
var testFolderRoot = stringUtils.dasherize(options.project.name());

if (options.project.isEmberCLIAddon()) {
testFolderRoot = pathUtil.getRelativeParentPath(options.entity.name, -1, false);
}

var destroyAppExists =
existsSync(path.join(this.project.root, '/tests/helpers/destroy-app.js'));

return {
testFolderRoot: testFolderRoot,
friendlyTestName: testInfo.name(options.entity.name, "Acceptance", null)
friendlyTestName: testInfo.name(options.entity.name, 'Acceptance', null),
destroyAppExists: destroyAppExists
};
}
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* jshint expr:true */
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import startApp from '../helpers/start-app';
<% if (destroyAppExists) { %>import destroyApp from '../helpers/destroy-app';<% } else { %>import Ember from 'ember';<% } %>

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

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

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

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

andThen(function() {
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.equal(currentURL(), '/<%= dasherizedModuleName %>');
});
});
4 changes: 2 additions & 2 deletions blueprints/component-addon/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*jshint node:true*/

var stringUtil = require('ember-cli-string-utils');
var validComponentName = require('ember-cli/lib/utilities/valid-component-name');
var getPathOption = require('ember-cli/lib/utilities/get-component-path-option');
var validComponentName = require('ember-cli-valid-component-name');
var getPathOption = require('ember-cli-get-component-path-option');
var path = require('path');
var normalizeEntityName = require('ember-cli-normalize-entity-name');

Expand Down
21 changes: 15 additions & 6 deletions blueprints/component-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
var path = require('path');
var testInfo = require('ember-cli-test-info');
var stringUtil = require('ember-cli-string-utils');
var getPathOption = require('ember-cli/lib/utilities/get-component-path-option');
var isPackageMissing = require('ember-cli-is-package-missing');
var getPathOption = require('ember-cli-get-component-path-option');
var useTestFrameworkDetector = require('../test-framework-detector');

module.exports = {
module.exports = useTestFrameworkDetector({
description: 'Generates a component integration or unit test.',

availableOptions: [
Expand Down Expand Up @@ -38,15 +40,15 @@ module.exports = {
locals: function(options) {
var dasherizedModuleName = stringUtil.dasherize(options.entity.name);
var componentPathName = dasherizedModuleName;
var testType = options.testType || "integration";
var friendlyTestDescription = testInfo.description(options.entity.name, "Integration", "Component");
var testType = options.testType || 'integration';
var friendlyTestDescription = testInfo.description(options.entity.name, 'Integration', 'Component');

if (options.pod && options.path !== 'components' && options.path !== '') {
componentPathName = [options.path, dasherizedModuleName].join('/');
}

if (options.testType === 'unit') {
friendlyTestDescription = testInfo.description(options.entity.name, "Unit", "Component");
friendlyTestDescription = testInfo.description(options.entity.name, 'Unit', 'Component');
}

return {
Expand All @@ -55,5 +57,12 @@ module.exports = {
componentPathName: componentPathName,
friendlyTestDescription: friendlyTestDescription
};
},
afterInstall: function(options) {
if (!options.dryRun && options.testType === 'integration' && isPackageMissing(this, 'ember-cli-htmlbars-inline-precompile')) {
return this.addPackagesToProject([
{ name: 'ember-cli-htmlbars-inline-precompile', target: '^0.3.1' }
]);
}
}
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* jshint expr:true */
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) { ... });
// Template block usage:
// this.render(hbs`
// {{#<%= dasherizedModuleName %>}}
// template content
// {{/<%= dasherizedModuleName %>}}
// `);

this.render(hbs`{{<%= dasherizedModuleName %>}}`);
expect(this.$()).to.have.length(1);<% } 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
Expand Up @@ -8,26 +8,23 @@ moduleForComponent('<%= componentPathName %>', '<%= friendlyTestDescription %>',
});

test('it renders', function(assert) {
<% if (testType === 'integration' ) { %>assert.expect(2);

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

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

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

// Template block usage:" + EOL +
// Template block usage:
this.render(hbs`
{{#<%= componentPathName %>}}
template block text
{{/<%= componentPathName %>}}
`);

assert.equal(this.$().text().trim(), 'template block text');<% } else if(testType === 'unit') { %>assert.expect(1);

assert.equal(this.$().text().trim(), 'template block text');<% } else if(testType === 'unit') { %>
// Creates the component instance
/*var component =*/ this.subject();
/*let component =*/ this.subject();
// Renders the component to the page
this.render();
assert.equal(this.$().text().trim(), '');<% } %>
Expand Down
6 changes: 3 additions & 3 deletions blueprints/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

var stringUtil = require('ember-cli-string-utils');
var pathUtil = require('ember-cli-path-utils');
var validComponentName = require('ember-cli/lib/utilities/valid-component-name');
var getPathOption = require('ember-cli/lib/utilities/get-component-path-option');
var validComponentName = require('ember-cli-valid-component-name');
var getPathOption = require('ember-cli-get-component-path-option');
var path = require('path');

var normalizeEntityName = require('ember-cli-normalize-entity-name');
Expand Down Expand Up @@ -64,7 +64,7 @@ module.exports = {
'templates/components/' + stringUtil.dasherize(options.entity.name);
}
importTemplate = 'import layout from \'' + templatePath + '\';\n';
contents = '\n layout: layout';
contents = '\n layout';
}

return {
Expand Down
14 changes: 11 additions & 3 deletions blueprints/controller-test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/*jshint node:true*/

module.exports = {
description: 'Generates a controller unit test.'
};
var testInfo = require('ember-cli-test-info');
var useTestFrameworkDetector = require('../test-framework-detector');

module.exports = useTestFrameworkDetector({
description: 'Generates a controller unit test.',
locals: function(options) {
return {
friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Controller')
};
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* jshint expr:true */
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() {
// 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
@@ -1,12 +1,12 @@
import { moduleFor, test } from 'ember-qunit';

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

// Replace this with your real tests.
test('it exists', function(assert) {
var controller = this.subject();
let controller = this.subject();
assert.ok(controller);
});
2 changes: 1 addition & 1 deletion blueprints/helper-addon/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*jshint node:true*/

module.exports = require('ember-cli/blueprints/addon-import');
module.exports = require('../-addon-import');
11 changes: 6 additions & 5 deletions blueprints/helper-test/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*jshint node:true*/

var getDependencyDepth = require('ember-cli-get-dependency-depth');
var testInfo = require('ember-cli-test-info');
var stringUtils = require('ember-cli-string-utils');
var useTestFrameworkDetector = require('../test-framework-detector');

module.exports = {
module.exports = useTestFrameworkDetector({
description: 'Generates a helper unit test.',
locals: function(options) {
return {
friendlyTestName: testInfo.name(options.entity.name, "Unit", "Helper"),
dependencyDepth: getDependencyDepth(options.entity.name)
friendlyTestName: testInfo.name(options.entity.name, 'Unit', 'Helper'),
dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix)
};
}
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* jshint expr:true */
import { expect } from 'chai';
import { describe, it } from 'mocha';
import { <%= camelizedModuleName %> } from '<%= dasherizedPackageName %>/helpers/<%= dasherizedModuleName %>';

describe('<%= friendlyTestName %>', function() {
// Replace this with your real tests.
it('works', function() {
let result = <%= camelizedModuleName %>(42);
expect(result).to.be.ok;
});
});
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { <%= camelizedModuleName %> } from '<%= dependencyDepth %>/helpers/<%= dasherizedModuleName %>';
import { <%= camelizedModuleName %> } from '<%= dasherizedModulePrefix %>/helpers/<%= dasherizedModuleName %>';
import { module, test } from 'qunit';

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

// Replace this with your real tests.
test('it works', function(assert) {
var result = <%= camelizedModuleName %>(42);
let result = <%= camelizedModuleName %>([42]);
assert.ok(result);
});
2 changes: 1 addition & 1 deletion blueprints/initializer-addon/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/*jshint node:true*/

module.exports = require('ember-cli/blueprints/addon-import');
module.exports = require('../-addon-import');
Loading

0 comments on commit ea9d810

Please sign in to comment.