diff --git a/.npmignore b/.npmignore new file mode 100644 index 00000000000..0ba0fc1c85c --- /dev/null +++ b/.npmignore @@ -0,0 +1 @@ +node-tests/ diff --git a/.travis.yml b/.travis.yml index 07a64fac025..bc1118c03f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -73,4 +73,5 @@ env: - TEST_SUITE=built-tests EMBER_ENV=production DISABLE_JSCS=true DISABLE_JSHINT=true - TEST_SUITE=old-jquery-and-extend-prototypes - TEST_SUITE=node DISABLE_JSCS=true DISABLE_JSHINT=true + - TEST_SUITE=blueprints - TEST_SUITE=sauce diff --git a/bin/run-tests.js b/bin/run-tests.js index 22503e01ecc..a3b56d24c14 100755 --- a/bin/run-tests.js +++ b/bin/run-tests.js @@ -158,6 +158,11 @@ switch (process.env.TEST_SUITE) { console.log('suite: node'); require('./run-node-tests'); return; + case 'blueprints': + console.log('suite: blueprints'); + require('../node-tests/nodetest-runner'); + server.close(); + return; case 'sauce': console.log('suite: sauce'); require('./run-sauce-tests'); diff --git a/blueprints/-addon-import.js b/blueprints/-addon-import.js new file mode 100644 index 00000000000..3b83f2b8901 --- /dev/null +++ b/blueprints/-addon-import.js @@ -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 + }; + } +}; diff --git a/blueprints/acceptance-test/index.js b/blueprints/acceptance-test/index.js new file mode 100644 index 00000000000..2a358d53a7a --- /dev/null +++ b/blueprints/acceptance-test/index.js @@ -0,0 +1,29 @@ +/*jshint node:true*/ + +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 = 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), + destroyAppExists: destroyAppExists + }; + } +}); diff --git a/blueprints/acceptance-test/mocha-files/tests/acceptance/__name__-test.js b/blueprints/acceptance-test/mocha-files/tests/acceptance/__name__-test.js new file mode 100644 index 00000000000..fb8e9ca2e68 --- /dev/null +++ b/blueprints/acceptance-test/mocha-files/tests/acceptance/__name__-test.js @@ -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 %>'); + }); + }); +}); diff --git a/blueprints/acceptance-test/qunit-files/tests/acceptance/__name__-test.js b/blueprints/acceptance-test/qunit-files/tests/acceptance/__name__-test.js new file mode 100644 index 00000000000..abbcab2497f --- /dev/null +++ b/blueprints/acceptance-test/qunit-files/tests/acceptance/__name__-test.js @@ -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 %>'); + }); +}); diff --git a/blueprints/component-addon/files/__root__/__path__/__name__.js b/blueprints/component-addon/files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..71a8b71c1c6 --- /dev/null +++ b/blueprints/component-addon/files/__root__/__path__/__name__.js @@ -0,0 +1 @@ +export { default } from '<%= modulePath %>'; \ No newline at end of file diff --git a/blueprints/component-addon/index.js b/blueprints/component-addon/index.js new file mode 100644 index 00000000000..626e24e1eba --- /dev/null +++ b/blueprints/component-addon/index.js @@ -0,0 +1,56 @@ +/*jshint node:true*/ + +var stringUtil = require('ember-cli-string-utils'); +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'); + +module.exports = { + description: 'Generates a component. Name must contain a hyphen.', + + fileMapTokens: function() { + return { + __path__: function(options) { + if (options.pod) { + return path.join(options.podPath, options.locals.path, options.dasherizedModuleName); + } + return 'components'; + }, + __name__: function(options) { + if (options.pod) { + return 'component'; + } + return options.dasherizedModuleName; + }, + __root__: function(options) { + if (options.inRepoAddon) { + return path.join('lib', options.inRepoAddon, 'app'); + } + return 'app'; + } + }; + }, + + normalizeEntityName: function(entityName) { + entityName = normalizeEntityName(entityName); + + return validComponentName(entityName); + }, + + 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 importPathName = [addonName, 'components', fileName].join('/'); + + if (options.pod) { + importPathName = [addonName, 'components', fileName,'component'].join('/'); + } + + return { + modulePath: importPathName, + path: getPathOption(options) + }; + } +}; diff --git a/blueprints/component-test/index.js b/blueprints/component-test/index.js new file mode 100644 index 00000000000..8a14227ac79 --- /dev/null +++ b/blueprints/component-test/index.js @@ -0,0 +1,68 @@ +/*jshint node:true*/ + +var path = require('path'); +var testInfo = require('ember-cli-test-info'); +var stringUtil = require('ember-cli-string-utils'); +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 = useTestFrameworkDetector({ + description: 'Generates a component integration or unit test.', + + availableOptions: [ + { + name: 'test-type', + type: ['integration', 'unit'], + default: 'integration', + aliases:[ + { 'i': 'integration'}, + { 'u': 'unit'}, + { 'integration': 'integration' }, + { 'unit': 'unit' } + ] + } + ], + + fileMapTokens: function() { + return { + __testType__: function(options) { + return options.locals.testType || 'integration'; + }, + __path__: function(options) { + if (options.pod) { + return path.join(options.podPath, options.locals.path, options.dasherizedModuleName); + } + return 'components'; + } + }; + }, + 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'); + + 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'); + } + + return { + path: getPathOption(options), + testType: testType, + 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' } + ]); + } + } +}); diff --git a/blueprints/component-test/mocha-files/tests/__testType__/__path__/__test__.js b/blueprints/component-test/mocha-files/tests/__testType__/__path__/__test__.js new file mode 100644 index 00000000000..d09de151158 --- /dev/null +++ b/blueprints/component-test/mocha-files/tests/__testType__/__path__/__test__.js @@ -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);<% } %> + }); + } +); diff --git a/blueprints/component-test/qunit-files/tests/__testType__/__path__/__test__.js b/blueprints/component-test/qunit-files/tests/__testType__/__path__/__test__.js new file mode 100644 index 00000000000..faf52d9996c --- /dev/null +++ b/blueprints/component-test/qunit-files/tests/__testType__/__path__/__test__.js @@ -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`{{<%= componentPathName %>}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#<%= componentPathName %>}} + template block text + {{/<%= componentPathName %>}} + `); + + assert.equal(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.equal(this.$().text().trim(), '');<% } %> +}); diff --git a/blueprints/component/files/__root__/__path__/__name__.js b/blueprints/component/files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..fb1798c77cb --- /dev/null +++ b/blueprints/component/files/__root__/__path__/__name__.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; +<%= importTemplate %> +export default Ember.Component.extend({<%= contents %> +}); diff --git a/blueprints/component/files/__root__/__templatepath__/__templatename__.hbs b/blueprints/component/files/__root__/__templatepath__/__templatename__.hbs new file mode 100644 index 00000000000..889d9eeadc1 --- /dev/null +++ b/blueprints/component/files/__root__/__templatepath__/__templatename__.hbs @@ -0,0 +1 @@ +{{yield}} diff --git a/blueprints/component/index.js b/blueprints/component/index.js new file mode 100644 index 00000000000..bcfaf3c6b8b --- /dev/null +++ b/blueprints/component/index.js @@ -0,0 +1,76 @@ +/*jshint node:true*/ + +var stringUtil = require('ember-cli-string-utils'); +var pathUtil = require('ember-cli-path-utils'); +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'); + +module.exports = { + description: 'Generates a component. Name must contain a hyphen.', + + availableOptions: [ + { + name: 'path', + type: String, + default: 'components', + aliases:[ + {'no-path': ''} + ] + } + ], + + fileMapTokens: function() { + return { + __path__: function(options) { + if (options.pod) { + return path.join(options.podPath, options.locals.path, options.dasherizedModuleName); + } + return 'components'; + }, + __templatepath__: function(options) { + if (options.pod) { + return path.join(options.podPath, options.locals.path, options.dasherizedModuleName); + } + return 'templates/components'; + }, + __templatename__: function(options) { + if (options.pod) { + return 'template'; + } + return options.dasherizedModuleName; + } + }; + }, + + normalizeEntityName: function(entityName) { + entityName = normalizeEntityName(entityName); + + return validComponentName(entityName); + }, + + locals: function(options) { + var templatePath = ''; + var importTemplate = ''; + var contents = ''; + // if we're in an addon, build import statement + if (options.project.isEmberCLIAddon() || options.inRepoAddon && !options.inDummy) { + if(options.pod) { + templatePath = './template'; + } else { + templatePath = pathUtil.getRelativeParentPath(options.entity.name) + + 'templates/components/' + stringUtil.dasherize(options.entity.name); + } + importTemplate = 'import layout from \'' + templatePath + '\';\n'; + contents = '\n layout'; + } + + return { + importTemplate: importTemplate, + contents: contents, + path: getPathOption(options) + }; + } +}; diff --git a/blueprints/controller-test/index.js b/blueprints/controller-test/index.js new file mode 100644 index 00000000000..d13a07b42bd --- /dev/null +++ b/blueprints/controller-test/index.js @@ -0,0 +1,13 @@ +/*jshint node:true*/ + +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') + }; + } +}); diff --git a/blueprints/controller-test/mocha-files/tests/unit/__path__/__test__.js b/blueprints/controller-test/mocha-files/tests/unit/__path__/__test__.js new file mode 100644 index 00000000000..35039ace8af --- /dev/null +++ b/blueprints/controller-test/mocha-files/tests/unit/__path__/__test__.js @@ -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; + }); + } +); diff --git a/blueprints/controller-test/qunit-files/tests/unit/__path__/__test__.js b/blueprints/controller-test/qunit-files/tests/unit/__path__/__test__.js new file mode 100644 index 00000000000..db26bfa5579 --- /dev/null +++ b/blueprints/controller-test/qunit-files/tests/unit/__path__/__test__.js @@ -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'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let controller = this.subject(); + assert.ok(controller); +}); diff --git a/blueprints/controller/files/__root__/__path__/__name__.js b/blueprints/controller/files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..55ff9aa587a --- /dev/null +++ b/blueprints/controller/files/__root__/__path__/__name__.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ +}); diff --git a/blueprints/controller/index.js b/blueprints/controller/index.js new file mode 100644 index 00000000000..cc81d473736 --- /dev/null +++ b/blueprints/controller/index.js @@ -0,0 +1,5 @@ +/*jshint node:true*/ + +module.exports = { + description: 'Generates a controller.' +}; diff --git a/blueprints/helper-addon/files/__root__/__path__/__name__.js b/blueprints/helper-addon/files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..a34b84552a1 --- /dev/null +++ b/blueprints/helper-addon/files/__root__/__path__/__name__.js @@ -0,0 +1 @@ +export { default, <%= camelizedModuleName %> } from '<%= modulePath %>'; diff --git a/blueprints/helper-addon/index.js b/blueprints/helper-addon/index.js new file mode 100644 index 00000000000..270f28f7696 --- /dev/null +++ b/blueprints/helper-addon/index.js @@ -0,0 +1,3 @@ +/*jshint node:true*/ + +module.exports = require('../-addon-import'); diff --git a/blueprints/helper-test/index.js b/blueprints/helper-test/index.js new file mode 100644 index 00000000000..5d3afcf1735 --- /dev/null +++ b/blueprints/helper-test/index.js @@ -0,0 +1,15 @@ +/*jshint node:true*/ + +var testInfo = require('ember-cli-test-info'); +var stringUtils = require('ember-cli-string-utils'); +var useTestFrameworkDetector = require('../test-framework-detector'); + +module.exports = useTestFrameworkDetector({ + description: 'Generates a helper unit test.', + locals: function(options) { + return { + friendlyTestName: testInfo.name(options.entity.name, 'Unit', 'Helper'), + dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix) + }; + } +}); diff --git a/blueprints/helper-test/mocha-files/tests/unit/helpers/__name__-test.js b/blueprints/helper-test/mocha-files/tests/unit/helpers/__name__-test.js new file mode 100644 index 00000000000..85c42e7a561 --- /dev/null +++ b/blueprints/helper-test/mocha-files/tests/unit/helpers/__name__-test.js @@ -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; + }); +}); diff --git a/blueprints/helper-test/qunit-files/tests/unit/helpers/__name__-test.js b/blueprints/helper-test/qunit-files/tests/unit/helpers/__name__-test.js new file mode 100644 index 00000000000..25a5954d155 --- /dev/null +++ b/blueprints/helper-test/qunit-files/tests/unit/helpers/__name__-test.js @@ -0,0 +1,10 @@ +import { <%= camelizedModuleName %> } from '<%= dasherizedModulePrefix %>/helpers/<%= dasherizedModuleName %>'; +import { module, test } from 'qunit'; + +module('<%= friendlyTestName %>'); + +// Replace this with your real tests. +test('it works', function(assert) { + let result = <%= camelizedModuleName %>([42]); + assert.ok(result); +}); diff --git a/blueprints/helper/files/__root__/helpers/__name__.js b/blueprints/helper/files/__root__/helpers/__name__.js new file mode 100644 index 00000000000..eb31fd5447d --- /dev/null +++ b/blueprints/helper/files/__root__/helpers/__name__.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export function <%= camelizedModuleName %>(params/*, hash*/) { + return params; +} + +export default Ember.Helper.helper(<%= camelizedModuleName %>); diff --git a/blueprints/helper/index.js b/blueprints/helper/index.js new file mode 100644 index 00000000000..ccf5b7c1807 --- /dev/null +++ b/blueprints/helper/index.js @@ -0,0 +1,10 @@ +'use strict'; +/*jshint node:true*/ +var normalizeEntityName = require('ember-cli-normalize-entity-name'); + +module.exports = { + description: 'Generates a helper function.', + normalizeEntityName: function(entityName) { + return normalizeEntityName(entityName); + } +}; diff --git a/blueprints/initializer-addon/files/__root__/__path__/__name__.js b/blueprints/initializer-addon/files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..79e541af69d --- /dev/null +++ b/blueprints/initializer-addon/files/__root__/__path__/__name__.js @@ -0,0 +1 @@ +export { default, initialize } from '<%= modulePath %>'; diff --git a/blueprints/initializer-addon/index.js b/blueprints/initializer-addon/index.js new file mode 100644 index 00000000000..270f28f7696 --- /dev/null +++ b/blueprints/initializer-addon/index.js @@ -0,0 +1,3 @@ +/*jshint node:true*/ + +module.exports = require('../-addon-import'); diff --git a/blueprints/initializer-test/index.js b/blueprints/initializer-test/index.js new file mode 100644 index 00000000000..dd48fc197e0 --- /dev/null +++ b/blueprints/initializer-test/index.js @@ -0,0 +1,15 @@ +/*jshint node:true*/ + +var testInfo = require('ember-cli-test-info'); +var stringUtils = require('ember-cli-string-utils'); +var useTestFrameworkDetector = require('../test-framework-detector'); + +module.exports = useTestFrameworkDetector({ + description: 'Generates an initializer unit test.', + locals: function(options) { + return { + friendlyTestName: testInfo.name(options.entity.name, 'Unit', 'Initializer'), + dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix) + }; + } +}); diff --git a/blueprints/initializer-test/mocha-files/tests/unit/initializers/__name__-test.js b/blueprints/initializer-test/mocha-files/tests/unit/initializers/__name__-test.js new file mode 100644 index 00000000000..f73838bb862 --- /dev/null +++ b/blueprints/initializer-test/mocha-files/tests/unit/initializers/__name__-test.js @@ -0,0 +1,24 @@ +/* jshint expr:true */ +import { expect } from 'chai'; +import { describe, it, beforeEach } from 'mocha'; +import Ember from 'ember'; +import <%= classifiedModuleName %>Initializer from '<%= dasherizedModulePrefix %>/initializers/<%= dasherizedModuleName %>'; + +describe('<%= friendlyTestName %>', function() { + let application; + + beforeEach(function() { + Ember.run(function() { + application = Ember.Application.create(); + application.deferReadiness(); + }); + }); + + // Replace this with your real tests. + it('works', function() { + <%= classifiedModuleName %>Initializer.initialize(application); + + // you would normally confirm the results of the initializer here + expect(true).to.be.ok; + }); +}); diff --git a/blueprints/initializer-test/qunit-files/tests/unit/initializers/__name__-test.js b/blueprints/initializer-test/qunit-files/tests/unit/initializers/__name__-test.js new file mode 100644 index 00000000000..b58aa2dbecc --- /dev/null +++ b/blueprints/initializer-test/qunit-files/tests/unit/initializers/__name__-test.js @@ -0,0 +1,22 @@ +import Ember from 'ember'; +import <%= classifiedModuleName %>Initializer from '<%= dasherizedModulePrefix %>/initializers/<%= dasherizedModuleName %>'; +import { module, test } from 'qunit'; + +let application; + +module('<%= friendlyTestName %>', { + beforeEach() { + Ember.run(function() { + application = Ember.Application.create(); + application.deferReadiness(); + }); + } +}); + +// Replace this with your real tests. +test('it works', function(assert) { + <%= classifiedModuleName %>Initializer.initialize(application); + + // you would normally confirm the results of the initializer here + assert.ok(true); +}); diff --git a/blueprints/initializer/files/__root__/initializers/__name__.js b/blueprints/initializer/files/__root__/initializers/__name__.js new file mode 100644 index 00000000000..f47caae7cfa --- /dev/null +++ b/blueprints/initializer/files/__root__/initializers/__name__.js @@ -0,0 +1,8 @@ +export function initialize(/* application */) { + // application.inject('route', 'foo', 'service:foo'); +} + +export default { + name: '<%= dasherizedModuleName %>', + initialize +}; diff --git a/blueprints/initializer/index.js b/blueprints/initializer/index.js new file mode 100644 index 00000000000..48760763b48 --- /dev/null +++ b/blueprints/initializer/index.js @@ -0,0 +1,5 @@ +/*jshint node:true*/ + +module.exports = { + description: 'Generates an initializer.' +}; diff --git a/blueprints/instance-initializer-addon/files/__root__/__path__/__name__.js b/blueprints/instance-initializer-addon/files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..79e541af69d --- /dev/null +++ b/blueprints/instance-initializer-addon/files/__root__/__path__/__name__.js @@ -0,0 +1 @@ +export { default, initialize } from '<%= modulePath %>'; diff --git a/blueprints/instance-initializer-addon/index.js b/blueprints/instance-initializer-addon/index.js new file mode 100644 index 00000000000..270f28f7696 --- /dev/null +++ b/blueprints/instance-initializer-addon/index.js @@ -0,0 +1,3 @@ +/*jshint node:true*/ + +module.exports = require('../-addon-import'); diff --git a/blueprints/instance-initializer-test/index.js b/blueprints/instance-initializer-test/index.js new file mode 100644 index 00000000000..f04393cbb9f --- /dev/null +++ b/blueprints/instance-initializer-test/index.js @@ -0,0 +1,15 @@ +/*jshint node:true*/ + +var testInfo = require('ember-cli-test-info'); +var stringUtils = require('ember-cli-string-utils'); +var useTestFrameworkDetector = require('../test-framework-detector'); + +module.exports = useTestFrameworkDetector({ + description: 'Generates an instance initializer unit test.', + locals: function(options) { + return { + friendlyTestName: testInfo.name(options.entity.name, 'Unit', 'Instance Initializer'), + dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix) + }; + } +}); diff --git a/blueprints/instance-initializer-test/mocha-files/tests/unit/instance-initializers/__name__-test.js b/blueprints/instance-initializer-test/mocha-files/tests/unit/instance-initializers/__name__-test.js new file mode 100644 index 00000000000..06d80f0a909 --- /dev/null +++ b/blueprints/instance-initializer-test/mocha-files/tests/unit/instance-initializers/__name__-test.js @@ -0,0 +1,30 @@ +/* jshint expr:true */ +import { expect } from 'chai'; +import { describe, it, beforeEach } from 'mocha'; +import Ember from 'ember'; +import { initialize } from '<%= dasherizedModulePrefix %>/instance-initializers/<%= dasherizedModuleName %>'; +import destroyApp from '../../helpers/destroy-app'; + +describe('<%= friendlyTestName %>', function() { + let application, appInstance; + + beforeEach(function() { + Ember.run(function() { + application = Ember.Application.create(); + appInstance = application.buildInstance(); + }); + }); + + afterEach(function() { + Ember.run(appInstance, 'destroy'); + destroyApp(application); + }); + + // Replace this with your real tests. + it('works', function() { + initialize(appInstance); + + // you would normally confirm the results of the initializer here + expect(true).to.be.ok; + }); +}); diff --git a/blueprints/instance-initializer-test/qunit-files/tests/unit/instance-initializers/__name__-test.js b/blueprints/instance-initializer-test/qunit-files/tests/unit/instance-initializers/__name__-test.js new file mode 100644 index 00000000000..ec252a8fc4d --- /dev/null +++ b/blueprints/instance-initializer-test/qunit-files/tests/unit/instance-initializers/__name__-test.js @@ -0,0 +1,25 @@ +import Ember from 'ember'; +import { initialize } from '<%= dasherizedModulePrefix %>/instance-initializers/<%= dasherizedModuleName %>'; +import { module, test } from 'qunit'; +import destroyApp from '../../helpers/destroy-app'; + +module('<%= friendlyTestName %>', { + beforeEach: function() { + Ember.run(() => { + this.application = Ember.Application.create(); + this.appInstance = this.application.buildInstance(); + }); + }, + afterEach: function() { + Ember.run(this.appInstance, 'destroy'); + destroyApp(this.application); + } +}); + +// Replace this with your real tests. +test('it works', function(assert) { + initialize(this.appInstance); + + // you would normally confirm the results of the initializer here + assert.ok(true); +}); diff --git a/blueprints/instance-initializer/files/__root__/instance-initializers/__name__.js b/blueprints/instance-initializer/files/__root__/instance-initializers/__name__.js new file mode 100644 index 00000000000..4b96d1b34ca --- /dev/null +++ b/blueprints/instance-initializer/files/__root__/instance-initializers/__name__.js @@ -0,0 +1,8 @@ +export function initialize(/* appInstance */) { + // appInstance.inject('route', 'foo', 'service:foo'); +} + +export default { + name: '<%= dasherizedModuleName %>', + initialize +}; diff --git a/blueprints/instance-initializer/index.js b/blueprints/instance-initializer/index.js new file mode 100644 index 00000000000..96afb7f58d8 --- /dev/null +++ b/blueprints/instance-initializer/index.js @@ -0,0 +1,5 @@ +/*jshint node:true*/ + +module.exports = { + description: 'Generates an instance initializer.' +}; diff --git a/blueprints/mixin-test/index.js b/blueprints/mixin-test/index.js new file mode 100644 index 00000000000..f0fb375f46d --- /dev/null +++ b/blueprints/mixin-test/index.js @@ -0,0 +1,14 @@ +/*jshint node:true*/ + +var testInfo = require('ember-cli-test-info'); +var useTestFrameworkDetector = require('../test-framework-detector'); + +module.exports = useTestFrameworkDetector({ + description: 'Generates a mixin unit test.', + locals: function(options) { + return { + projectName: options.inRepoAddon ? options.inRepoAddon : options.project.name(), + friendlyTestName: testInfo.name(options.entity.name, 'Unit', 'Mixin') + }; + } +}); diff --git a/blueprints/mixin-test/mocha-files/tests/unit/mixins/__name__-test.js b/blueprints/mixin-test/mocha-files/tests/unit/mixins/__name__-test.js new file mode 100644 index 00000000000..b59ffd058cf --- /dev/null +++ b/blueprints/mixin-test/mocha-files/tests/unit/mixins/__name__-test.js @@ -0,0 +1,14 @@ +/* jshint expr:true */ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; +import Ember from 'ember'; +import <%= classifiedModuleName %>Mixin from '<%= dasherizedPackageName %>/mixins/<%= dasherizedModuleName %>'; + +describe('<%= friendlyTestName %>', function() { + // Replace this with your real tests. + it('works', function() { + let <%= classifiedModuleName %>Object = Ember.Object.extend(<%= classifiedModuleName %>Mixin); + let subject = <%= classifiedModuleName %>Object.create(); + expect(subject).to.be.ok; + }); +}); diff --git a/blueprints/mixin-test/qunit-files/tests/unit/mixins/__name__-test.js b/blueprints/mixin-test/qunit-files/tests/unit/mixins/__name__-test.js new file mode 100644 index 00000000000..72d60b1a9b3 --- /dev/null +++ b/blueprints/mixin-test/qunit-files/tests/unit/mixins/__name__-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import <%= classifiedModuleName %>Mixin from '<%= projectName %>/mixins/<%= dasherizedModuleName %>'; +import { module, test } from 'qunit'; + +module('<%= friendlyTestName %>'); + +// Replace this with your real tests. +test('it works', function(assert) { + let <%= classifiedModuleName %>Object = Ember.Object.extend(<%= classifiedModuleName %>Mixin); + let subject = <%= classifiedModuleName %>Object.create(); + assert.ok(subject); +}); diff --git a/blueprints/mixin/files/__root__/mixins/__name__.js b/blueprints/mixin/files/__root__/mixins/__name__.js new file mode 100644 index 00000000000..abf754d7160 --- /dev/null +++ b/blueprints/mixin/files/__root__/mixins/__name__.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Mixin.create({ +}); diff --git a/blueprints/mixin/index.js b/blueprints/mixin/index.js new file mode 100644 index 00000000000..891547dd1f1 --- /dev/null +++ b/blueprints/mixin/index.js @@ -0,0 +1,5 @@ +/*jshint node:true*/ + +module.exports = { + description: 'Generates a mixin.' +}; diff --git a/blueprints/route-addon/files/__root__/__path__/__name__.js b/blueprints/route-addon/files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..d921567455f --- /dev/null +++ b/blueprints/route-addon/files/__root__/__path__/__name__.js @@ -0,0 +1 @@ +export { default } from '<%= routeModulePath %>'; diff --git a/blueprints/route-addon/files/__root__/__templatepath__/__templatename__.js b/blueprints/route-addon/files/__root__/__templatepath__/__templatename__.js new file mode 100644 index 00000000000..2701b135456 --- /dev/null +++ b/blueprints/route-addon/files/__root__/__templatepath__/__templatename__.js @@ -0,0 +1 @@ +export { default } from '<%= templateModulePath %>'; diff --git a/blueprints/route-addon/index.js b/blueprints/route-addon/index.js new file mode 100644 index 00000000000..3c9020717b4 --- /dev/null +++ b/blueprints/route-addon/index.js @@ -0,0 +1,66 @@ +/*jshint node:true*/ + +var stringUtil = require('ember-cli-string-utils'); +var path = require('path'); +var inflector = require('inflection'); + +module.exports = { + description: 'Generates import wrappers for a route and its template.', + + fileMapTokens: function() { + return { + __templatepath__: function(options) { + if (options.pod) { + return path.join(options.podPath, options.dasherizedModuleName); + } + return 'templates'; + }, + __templatename__: function(options) { + if (options.pod) { + return 'template'; + } + return options.dasherizedModuleName; + }, + __name__: function (options) { + if (options.pod) { + return 'route'; + } + + return options.dasherizedModuleName; + }, + __path__: function(options) { + if (options.pod && options.hasPathToken) { + return path.join(options.podPath, options.dasherizedModuleName); + } + + return 'routes'; + }, + __root__: function(options) { + if (options.inRepoAddon) { + return path.join('lib', options.inRepoAddon, 'app'); + } + + return 'app'; + } + }; + }, + + locals: function (options) { + var locals = {}; + var addonRawName = options.inRepoAddon ? options.inRepoAddon : options.project.name(); + var addonName = stringUtil.dasherize(addonRawName); + var fileName = stringUtil.dasherize(options.entity.name); + + ['route', 'template'].forEach(function (blueprint) { + var pathName = [addonName, inflector.pluralize(blueprint), fileName].join('/'); + + if (options.pod) { + pathName = [addonName, fileName, blueprint].join('/'); + } + + locals[blueprint + 'ModulePath'] = pathName; + }); + + return locals; + } +}; diff --git a/blueprints/route-test/index.js b/blueprints/route-test/index.js new file mode 100644 index 00000000000..ef4d986bfef --- /dev/null +++ b/blueprints/route-test/index.js @@ -0,0 +1,13 @@ +/*jshint node:true*/ + +var testInfo = require('ember-cli-test-info'); +var useTestFrameworkDetector = require('../test-framework-detector'); + +module.exports = useTestFrameworkDetector({ + description: 'Generates a route unit test.', + locals: function(options) { + return { + friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Route') + }; + }, +}); diff --git a/blueprints/route-test/mocha-files/tests/unit/__path__/__test__.js b/blueprints/route-test/mocha-files/tests/unit/__path__/__test__.js new file mode 100644 index 00000000000..54f8b9c4542 --- /dev/null +++ b/blueprints/route-test/mocha-files/tests/unit/__path__/__test__.js @@ -0,0 +1,16 @@ +/* jshint expr:true */ +import { expect } from 'chai'; +import { describeModule, it } from 'ember-mocha'; + +describeModule('route:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', + { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] + }, + function() { + it('exists', function() { + let route = this.subject(); + expect(route).to.be.ok; + }); + } +); diff --git a/blueprints/route-test/qunit-files/tests/unit/__path__/__test__.js b/blueprints/route-test/qunit-files/tests/unit/__path__/__test__.js new file mode 100644 index 00000000000..45dc2443468 --- /dev/null +++ b/blueprints/route-test/qunit-files/tests/unit/__path__/__test__.js @@ -0,0 +1,11 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('route:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', { + // Specify the other units that are required for this test. + // needs: ['controller:foo'] +}); + +test('it exists', function(assert) { + let route = this.subject(); + assert.ok(route); +}); diff --git a/blueprints/route/files/__root__/__path__/__name__.js b/blueprints/route/files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..26d9f3124ec --- /dev/null +++ b/blueprints/route/files/__root__/__path__/__name__.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ +}); diff --git a/blueprints/route/files/__root__/__templatepath__/__templatename__.hbs b/blueprints/route/files/__root__/__templatepath__/__templatename__.hbs new file mode 100644 index 00000000000..c24cd68950a --- /dev/null +++ b/blueprints/route/files/__root__/__templatepath__/__templatename__.hbs @@ -0,0 +1 @@ +{{outlet}} diff --git a/blueprints/route/index.js b/blueprints/route/index.js new file mode 100644 index 00000000000..d1b1f543820 --- /dev/null +++ b/blueprints/route/index.js @@ -0,0 +1,122 @@ +/*jshint node:true*/ + +var fs = require('fs-extra'); +var path = require('path'); +var chalk = require('chalk'); +var EmberRouterGenerator = require('ember-router-generator'); + +module.exports = { + description: 'Generates a route and a template, and registers the route with the router.', + + availableOptions: [ + { + name: 'path', + type: String, + default: '' + }, + { + name: 'skip-router', + type: Boolean, + default: false + }, + { + name: 'reset-namespace', + type: Boolean + } + ], + + fileMapTokens: function() { + return { + __templatepath__: function(options) { + if (options.pod) { + return path.join(options.podPath, options.dasherizedModuleName); + } + return 'templates'; + }, + __templatename__: function(options) { + if (options.pod) { + return 'template'; + } + return options.dasherizedModuleName; + }, + __root__: function(options) { + if (options.inRepoAddon) { + return path.join('lib', options.inRepoAddon, 'addon'); + } + + if (options.inDummy) { + return path.join('tests','dummy','app'); + } + + if (options.inAddon) { + return 'addon'; + } + + return 'app'; + } + }; + }, + + shouldEntityTouchRouter: function(name) { + var isIndex = name === 'index'; + var isBasic = name === 'basic'; + var isApplication = name === 'application'; + + return !isBasic && !isIndex && !isApplication; + }, + + shouldTouchRouter: function(name, options) { + var entityTouchesRouter = this.shouldEntityTouchRouter(name); + var isDummy = !!options.dummy; + var isAddon = !!options.project.isEmberCLIAddon(); + var isAddonDummyOrApp = (isDummy === isAddon); + + return (entityTouchesRouter && isAddonDummyOrApp && !options.dryRun && !options.inRepoAddon && !options.skipRouter); + }, + + afterInstall: function(options) { + updateRouter.call(this, 'add', options); + }, + + afterUninstall: function(options) { + updateRouter.call(this, 'remove', options); + } +}; + +function updateRouter(action, options) { + var entity = options.entity; + var actionColorMap = { + add: 'green', + remove: 'red' + }; + var color = actionColorMap[action] || 'gray'; + + if (this.shouldTouchRouter(entity.name, options)) { + writeRoute(action, entity.name, options); + + this.ui.writeLine('updating router'); + this._writeStatusToUI(chalk[color], action + ' route', entity.name); + } +} + +function findRouter(options) { + var routerPathParts = [options.project.root]; + + if (options.dummy && options.project.isEmberCLIAddon()) { + routerPathParts = routerPathParts.concat(['tests', 'dummy', 'app', 'router.js']); + } else { + routerPathParts = routerPathParts.concat(['app', 'router.js']); + } + + return routerPathParts; +} + +function writeRoute(action, name, options) { + var routerPath = path.join.apply(null, findRouter(options)); + var source = fs.readFileSync(routerPath, 'utf-8'); + + var routes = new EmberRouterGenerator(source); + var newRoutes = routes[action](name, options); + + fs.writeFileSync(routerPath, newRoutes.code()); +} diff --git a/blueprints/service-test/index.js b/blueprints/service-test/index.js new file mode 100644 index 00000000000..ca0a590e48f --- /dev/null +++ b/blueprints/service-test/index.js @@ -0,0 +1,13 @@ +/*jshint node:true*/ + +var testInfo = require('ember-cli-test-info'); +var useTestFrameworkDetector = require('../test-framework-detector'); + +module.exports = useTestFrameworkDetector({ + description: 'Generates a service unit test.', + locals: function(options) { + return { + friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Service') + }; + }, +}); diff --git a/blueprints/service-test/mocha-files/tests/unit/__path__/__name__-test.js b/blueprints/service-test/mocha-files/tests/unit/__path__/__name__-test.js new file mode 100644 index 00000000000..ddc2d6afaa6 --- /dev/null +++ b/blueprints/service-test/mocha-files/tests/unit/__path__/__name__-test.js @@ -0,0 +1,17 @@ +/* jshint expr:true */ +import { expect } from 'chai'; +import { describeModule, it } from 'ember-mocha'; + +describeModule('service:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', + { + // Specify the other units that are required for this test. + // needs: ['service:foo'] + }, + function() { + // Replace this with your real tests. + it('exists', function() { + let service = this.subject(); + expect(service).to.be.ok; + }); + } +); diff --git a/blueprints/service-test/qunit-files/tests/unit/__path__/__test__.js b/blueprints/service-test/qunit-files/tests/unit/__path__/__test__.js new file mode 100644 index 00000000000..94db075869c --- /dev/null +++ b/blueprints/service-test/qunit-files/tests/unit/__path__/__test__.js @@ -0,0 +1,12 @@ +import { moduleFor, test } from 'ember-qunit'; + +moduleFor('service:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', { + // Specify the other units that are required for this test. + // needs: ['service:foo'] +}); + +// Replace this with your real tests. +test('it exists', function(assert) { + let service = this.subject(); + assert.ok(service); +}); diff --git a/blueprints/service/files/__root__/__path__/__name__.js b/blueprints/service/files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..b9261c61d86 --- /dev/null +++ b/blueprints/service/files/__root__/__path__/__name__.js @@ -0,0 +1,4 @@ +import Ember from 'ember'; + +export default Ember.Service.extend({ +}); diff --git a/blueprints/service/index.js b/blueprints/service/index.js new file mode 100644 index 00000000000..66f5cbbd573 --- /dev/null +++ b/blueprints/service/index.js @@ -0,0 +1,5 @@ +/*jshint node:true*/ + +module.exports = { + description: 'Generates a service.' +}; diff --git a/blueprints/template/files/__root__/__path__/__name__.hbs b/blueprints/template/files/__root__/__path__/__name__.hbs new file mode 100644 index 00000000000..e69de29bb2d diff --git a/blueprints/template/index.js b/blueprints/template/index.js new file mode 100644 index 00000000000..571f9cc9d8b --- /dev/null +++ b/blueprints/template/index.js @@ -0,0 +1,5 @@ +/*jshint node:true*/ + +module.exports = { + description: 'Generates a template.' +}; diff --git a/blueprints/test-framework-detector.js b/blueprints/test-framework-detector.js new file mode 100644 index 00000000000..8f04dca3a60 --- /dev/null +++ b/blueprints/test-framework-detector.js @@ -0,0 +1,25 @@ +var path = require('path'); + +module.exports = function(blueprint) { + blueprint.supportsAddon = function() { + return false; + }; + + blueprint.filesPath = function() { + var type; + + var dependencies = this.project.dependencies(); + if ('ember-cli-qunit' in dependencies) { + type = 'qunit'; + } else if ('ember-cli-mocha' in dependencies) { + type = 'mocha'; + } else { + this.ui.writeLine('Couldn\'t determine test style - using QUnit'); + type = 'qunit'; + } + + return path.join(this.path, type + '-files'); + }; + + return blueprint; +}; diff --git a/blueprints/test-helper/files/tests/helpers/__name__.js b/blueprints/test-helper/files/tests/helpers/__name__.js new file mode 100644 index 00000000000..b5387d2d3f1 --- /dev/null +++ b/blueprints/test-helper/files/tests/helpers/__name__.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default Ember.Test.registerAsyncHelper('<%= camelizedModuleName %>', function(app) { + +}); diff --git a/blueprints/test-helper/index.js b/blueprints/test-helper/index.js new file mode 100644 index 00000000000..54fc2633604 --- /dev/null +++ b/blueprints/test-helper/index.js @@ -0,0 +1,5 @@ +/*jshint node:true*/ + +module.exports = { + description: 'Generates a test helper.' +}; diff --git a/blueprints/util-test/index.js b/blueprints/util-test/index.js new file mode 100644 index 00000000000..99248d6cb62 --- /dev/null +++ b/blueprints/util-test/index.js @@ -0,0 +1,15 @@ +/*jshint node:true*/ + +var testInfo = require('ember-cli-test-info'); +var stringUtils = require('ember-cli-string-utils'); +var useTestFrameworkDetector = require('../test-framework-detector'); + +module.exports = useTestFrameworkDetector({ + description: 'Generates a util unit test.', + locals: function(options) { + return { + friendlyTestName: testInfo.name(options.entity.name, 'Unit', 'Utility'), + dasherizedModulePrefix: stringUtils.dasherize(options.project.config().modulePrefix) + }; + } +}); diff --git a/blueprints/util-test/mocha-files/tests/unit/utils/__name__-test.js b/blueprints/util-test/mocha-files/tests/unit/utils/__name__-test.js new file mode 100644 index 00000000000..558f0fa7dd5 --- /dev/null +++ b/blueprints/util-test/mocha-files/tests/unit/utils/__name__-test.js @@ -0,0 +1,12 @@ +/* jshint expr:true */ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; +import <%= camelizedModuleName %> from '<%= dasherizedPackageName %>/utils/<%= dasherizedModuleName %>'; + +describe('<%= friendlyTestName %>', function() { + // Replace this with your real tests. + it('works', function() { + let result = <%= camelizedModuleName %>(); + expect(result).to.be.ok; + }); +}); diff --git a/blueprints/util-test/qunit-files/tests/unit/utils/__name__-test.js b/blueprints/util-test/qunit-files/tests/unit/utils/__name__-test.js new file mode 100644 index 00000000000..287fb465a45 --- /dev/null +++ b/blueprints/util-test/qunit-files/tests/unit/utils/__name__-test.js @@ -0,0 +1,10 @@ +import <%= camelizedModuleName %> from '<%= dasherizedModulePrefix %>/utils/<%= dasherizedModuleName %>'; +import { module, test } from 'qunit'; + +module('<%= friendlyTestName %>'); + +// Replace this with your real tests. +test('it works', function(assert) { + let result = <%= camelizedModuleName %>(); + assert.ok(result); +}); diff --git a/blueprints/util/files/__root__/utils/__name__.js b/blueprints/util/files/__root__/utils/__name__.js new file mode 100644 index 00000000000..ab636c1792a --- /dev/null +++ b/blueprints/util/files/__root__/utils/__name__.js @@ -0,0 +1,3 @@ +export default function <%= camelizedModuleName %>() { + return true; +} diff --git a/blueprints/util/index.js b/blueprints/util/index.js new file mode 100644 index 00000000000..eec280cac03 --- /dev/null +++ b/blueprints/util/index.js @@ -0,0 +1,5 @@ +/*jshint node:true*/ + +module.exports = { + description: 'Generates a simple utility module/function.' +}; diff --git a/node-tests/blueprints/acceptance-test-test.js b/node-tests/blueprints/acceptance-test-test.js new file mode 100644 index 00000000000..d2efd7a8300 --- /dev/null +++ b/node-tests/blueprints/acceptance-test-test.js @@ -0,0 +1,98 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy acceptance-test', function() { + setupTestHooks(this); + + it('acceptance-test foo', function() { + // pass any additional command line options in the arguments array + return generateAndDestroy(['acceptance-test', 'foo'], { + files: [ + { + file: 'tests/acceptance/foo-test.js', + contains: [ + "import { test } from 'qunit';", + "moduleForAcceptance('Acceptance | foo');", + "test('visiting /foo', function(assert) {", + "visit('/foo');", + "andThen(function() {", + "assert.equal(currentURL(), '/foo');" + ] + } + ] + }); + }); + + it('in-addon acceptance-test foo', function() { + return generateAndDestroy(['acceptance-test', 'foo'], { + target: 'addon', + files: [ + { + file: 'tests/acceptance/foo-test.js', + contains: [ + "import { test } from 'qunit';", + "moduleForAcceptance('Acceptance | foo');", + "test('visiting /foo', function(assert) {", + "visit('/foo');", + "andThen(function() {", + "assert.equal(currentURL(), '/foo');" + ] + }, + { + file: 'app/acceptance-tests/foo.js', + exists: false + } + ] + }); + }); + + it('in-addon acceptance-test foo/bar', function() { + return generateAndDestroy(['acceptance-test', 'foo/bar'], { + target: 'addon', + files: [ + { + file: 'tests/acceptance/foo/bar-test.js', + contains: [ + "import { test } from 'qunit';", + "moduleForAcceptance('Acceptance | foo/bar');", + "test('visiting /foo/bar', function(assert) {", + "visit('/foo/bar');", + "andThen(function() {", + "assert.equal(currentURL(), '/foo/bar');" + ] + }, + { + file: 'app/acceptance-tests/foo/bar.js', + exists: false + } + ] + }); + }); + + it('acceptance-test foo for mocha', function() { + // pass any additional command line options in the arguments array + return generateAndDestroy(['acceptance-test', 'foo'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/acceptance/foo-test.js', + contains: [ + "import { describe, it, beforeEach, afterEach } from 'mocha';", + "import { expect } from 'chai';", + "describe('Acceptance | foo', function() {", + "it('can visit /foo', function() {", + "visit('/foo');", + "andThen(function() {", + "expect(currentURL()).to.equal('/foo');" + ] + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/component-addon-test.js b/node-tests/blueprints/component-addon-test.js new file mode 100644 index 00000000000..447717b3c50 --- /dev/null +++ b/node-tests/blueprints/component-addon-test.js @@ -0,0 +1,23 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy component-addon', function() { + setupTestHooks(this); + + it('component-addon foo-bar', function() { + // pass any additional command line options in the arguments array + return generateAndDestroy(['component-addon', 'foo-bar'], { + target: 'addon', + // define files to assert, and their contents + files: [ + { + file: 'app/components/foo-bar.js', + contents: "export { default } from 'my-addon/components/foo-bar';" + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/component-test.js b/node-tests/blueprints/component-test.js new file mode 100644 index 00000000000..f2dd96e5723 --- /dev/null +++ b/node-tests/blueprints/component-test.js @@ -0,0 +1,1077 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate component', function() { + setupTestHooks(this); + + it('component x-foo', function() { + return generateAndDestroy(['component', 'x-foo'], { + files:[ + { + file: 'app/components/x-foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/templates/components/x-foo.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + } + ] + }); + }); + + it('component foo/x-foo', function() { + return generateAndDestroy(['component', 'foo/x-foo'], { + files: [ + { + file: 'app/components/foo/x-foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/templates/components/foo/x-foo.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/components/foo/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('foo/x-foo'", + "integration: true", + "{{foo/x-foo}}", + "{{#foo/x-foo}}" + ] + } + ] + }); + }); + + it('component x-foo ignores --path option', function() { + return generateAndDestroy(['component', 'x-foo', '--path', 'foo'], { + files: [ + { + file: 'app/components/x-foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/templates/components/x-foo.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + } + ] + }); + }); + + it('in-addon component x-foo', function() { + return generateAndDestroy(['component', 'x-foo'], { + target: 'addon', + files: [ + { + file:'addon/components/x-foo.js', + contains: [ + "import Ember from 'ember';", + "import layout from '../templates/components/x-foo';", + "export default Ember.Component.extend({", + "layout", + "});" + ] + }, + { + file:'addon/templates/components/x-foo.hbs', + contains: "{{yield}}" + }, + { + file:'app/components/x-foo.js', + contains: [ + "export { default } from 'my-addon/components/x-foo';" + ] + }, + { + file:'tests/integration/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + } + ] + }); + }); + + it('in-addon component nested/x-foo', function() { + return generateAndDestroy(['component', 'nested/x-foo'], { + target: 'addon', + files: [ + { + file:'addon/components/nested/x-foo.js', + contains: [ + "import Ember from 'ember';", + "import layout from '../../templates/components/nested/x-foo';", + "export default Ember.Component.extend({", + "layout", + "});" + ] + }, + { + file:'addon/templates/components/nested/x-foo.hbs', + contains: "{{yield}}" + }, + { + file:'app/components/nested/x-foo.js', + contains: [ + "export { default } from 'my-addon/components/nested/x-foo';" + ] + }, + { + file:'tests/integration/components/nested/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('nested/x-foo'", + "integration: true", + "{{nested/x-foo}}", + "{{#nested/x-foo}}" + ] + } + ] + }); + }); + + it('dummy component x-foo', function() { + return generateAndDestroy(['component', 'x-foo', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/dummy/app/components/x-foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'tests/dummy/app/templates/components/x-foo.hbs', + contains: "{{yield}}" + }, + { + file: 'app/components/x-foo.js', + exists: false + }, + { + file: 'tests/unit/components/x-foo-test.js', + exists: false + } + ] + }); + }); + + it('dummy component nested/x-foo', function() { + return generateAndDestroy(['component', 'nested/x-foo', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/dummy/app/components/nested/x-foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'tests/dummy/app/templates/components/nested/x-foo.hbs', + contains: "{{yield}}" + }, + { + file: 'app/components/nested/x-foo.js', + exists: false + }, + { + file: 'tests/unit/components/nested/x-foo-test.js', + exists: false + } + ] + }); + }); + + it('in-repo-addon component x-foo', function() { + return generateAndDestroy(['component', 'x-foo', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/components/x-foo.js', + contains: [ + "import Ember from 'ember';", + "import layout from '../templates/components/x-foo';", + "export default Ember.Component.extend({", + "layout", + "});" + ] + }, + { + file: 'lib/my-addon/addon/templates/components/x-foo.hbs', + contains: "{{yield}}" + }, + { + file: 'lib/my-addon/app/components/x-foo.js', + contains: [ + "export { default } from 'my-addon/components/x-foo';" + ] + }, + { + file: 'tests/integration/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + } + ] + }); + }); + + it('in-repo-addon component-test x-foo', function() { + return generateAndDestroy(['component-test', 'x-foo', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'tests/integration/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + } + ] + }); + }); + + it('in-repo-addon component-test x-foo --unit', function() { + return generateAndDestroy(['component-test', 'x-foo', '--in-repo-addon=my-addon', '--unit'], { + target: 'inRepoAddon', + files: [ + { + file: 'tests/unit/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "moduleForComponent('x-foo'", + "unit: true" + ] + } + ] + }); + }); + + it('in-repo-addon component nested/x-foo', function() { + return generateAndDestroy(['component', 'nested/x-foo', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/components/nested/x-foo.js', + contains: [ + "import Ember from 'ember';", + "import layout from '../../templates/components/nested/x-foo';", + "export default Ember.Component.extend({", + "layout", + "});" + ] + }, + { + file: 'lib/my-addon/addon/templates/components/nested/x-foo.hbs', + contains: "{{yield}}" + }, + { + file: 'lib/my-addon/app/components/nested/x-foo.js', + contains: [ + "export { default } from 'my-addon/components/nested/x-foo';" + ] + }, + { + file: 'tests/integration/components/nested/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('nested/x-foo'", + "integration: true" + ] + } + ] + }); + }); +/** +* Pod tests +* +*/ + it('component x-foo --pod', function() { + return generateAndDestroy(['component', 'x-foo', '--pod'], { + files: [ + { + file: 'app/components/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/components/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/components/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true" + ] + }, + ] + }); + }); + + it('component x-foo --pod podModulePrefix', function() { + return generateAndDestroy(['component', 'x-foo', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/components/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/pods/components/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/pods/components/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + }, + ] + }); + }); + + it('component foo/x-foo --pod', function() { + return generateAndDestroy(['component', 'foo/x-foo', '--pod'], { + files: [ + { + file: 'app/components/foo/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/components/foo/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/components/foo/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('foo/x-foo'", + "integration: true", + "{{foo/x-foo}}", + "{{#foo/x-foo}}" + ] + }, + ] + }); + }); + + it('component foo/x-foo --pod podModulePrefix', function() { + return generateAndDestroy(['component', 'foo/x-foo', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/components/foo/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/pods/components/foo/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/pods/components/foo/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('foo/x-foo'", + "integration: true", + "{{foo/x-foo}}", + "{{#foo/x-foo}}" + ] + }, + ] + }); + }); + + it('component x-foo --pod --path', function() { + return generateAndDestroy(['component', 'x-foo', '--pod', '--path', 'bar'], { + files: [ + { + file: 'app/bar/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/bar/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/bar/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('bar/x-foo'", + "integration: true", + "{{bar/x-foo}}", + "{{#bar/x-foo}}" + ] + }, + ] + }); + }); + + it('component x-foo --pod --path podModulePrefix', function() { + return generateAndDestroy(['component', 'x-foo', '--pod', '--path', 'bar'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/bar/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/pods/bar/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/pods/bar/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('bar/x-foo'", + "integration: true", + "{{bar/x-foo}}", + "{{#bar/x-foo}}" + ] + }, + ] + }); + }); + + it('component foo/x-foo --pod --path', function() { + return generateAndDestroy(['component', 'foo/x-foo', '--pod', '--path', 'bar'], { + files: [ + { + file: 'app/bar/foo/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/bar/foo/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/bar/foo/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('bar/foo/x-foo'", + "integration: true", + "{{bar/foo/x-foo}}", + "{{#bar/foo/x-foo}}" + ] + }, + ] + }); + }); + + it('component foo/x-foo --pod --path podModulePrefix', function() { + return generateAndDestroy(['component', 'foo/x-foo', '--pod', '--path', 'bar'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/bar/foo/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/pods/bar/foo/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/pods/bar/foo/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "moduleForComponent('bar/foo/x-foo'", + "integration: true", + "{{bar/foo/x-foo}}", + "{{#bar/foo/x-foo}}" + ] + }, + ] + }); + }); + + it('component x-foo --pod --path nested', function() { + return generateAndDestroy(['component', 'x-foo', '--pod', '--path', 'bar/baz'], { + files: [ + { + file: 'app/bar/baz/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/bar/baz/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/bar/baz/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('bar/baz/x-foo'", + "integration: true", + "{{bar/baz/x-foo}}", + "{{#bar/baz/x-foo}}" + ] + }, + ] + }); + }); + + it('component x-foo --pod --path nested podModulePrefix', function() { + return generateAndDestroy(['component', 'x-foo', '--pod', '--path', 'bar/baz'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/bar/baz/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/pods/bar/baz/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/pods/bar/baz/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('bar/baz/x-foo'", + "integration: true", + "{{bar/baz/x-foo}}", + "{{#bar/baz/x-foo}}" + ] + }, + ] + }); + }); + + it('component foo/x-foo --pod --path nested', function() { + return generateAndDestroy(['component', 'foo/x-foo', '--pod', '--path', 'bar/baz'], { + files: [ + { + file: 'app/bar/baz/foo/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/bar/baz/foo/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/bar/baz/foo/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('bar/baz/foo/x-foo'", + "integration: true", + "{{bar/baz/foo/x-foo}}", + "{{#bar/baz/foo/x-foo}}" + ] + }, + ] + }); + }); + + it('component foo/x-foo --pod --path nested podModulePrefix', function() { + return generateAndDestroy(['component', 'foo/x-foo', '--pod', '--path', 'bar/baz'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/bar/baz/foo/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/pods/bar/baz/foo/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/pods/bar/baz/foo/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('bar/baz/foo/x-foo'", + "integration: true", + "{{bar/baz/foo/x-foo}}", + "{{#bar/baz/foo/x-foo}}" + ] + }, + ] + }); + }); + + it('component x-foo --pod -no-path', function() { + return generateAndDestroy(['component', 'x-foo', '--pod', '-no-path'], { + files: [ + { + file: 'app/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + }, + ] + }); + }); + + it('component x-foo --pod -no-path podModulePrefix', function() { + return generateAndDestroy(['component', 'x-foo', '--pod', '-no-path'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/pods/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/pods/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + }, + ] + }); + }); + + it('component foo/x-foo --pod -no-path', function() { + return generateAndDestroy(['component', 'foo/x-foo', '--pod', '-no-path'], { + files: [ + { + file: 'app/foo/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/foo/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/foo/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('foo/x-foo'", + "integration: true", + "{{foo/x-foo}}", + "{{#foo/x-foo}}" + ] + }, + ] + }); + }); + + it('component foo/x-foo --pod -no-path podModulePrefix', function() { + return generateAndDestroy(['component', 'foo/x-foo', '--pod', '-no-path'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/foo/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Component.extend({", + "});" + ] + }, + { + file: 'app/pods/foo/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'tests/integration/pods/foo/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('foo/x-foo'", + "integration: true", + "{{foo/x-foo}}", + "{{#foo/x-foo}}" + ] + }, + ] + }); + }); + + it('in-addon component x-foo --pod', function() { + return generateAndDestroy(['component', 'x-foo', '--pod'], { + target: 'addon', + files: [ + { + file: 'addon/components/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "import layout from './template';", + "export default Ember.Component.extend({", + "layout", + "});" + ] + }, + { + file: 'addon/components/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'app/components/x-foo/component.js', + contains: [ + "export { default } from 'my-addon/components/x-foo/component';" + ] + }, + { + file: 'tests/integration/components/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "moduleForComponent('x-foo'", + "integration: true" + ] + } + ] + }); + }); + + it('in-repo-addon component x-foo --pod', function() { + return generateAndDestroy(['component', 'x-foo', '--in-repo-addon=my-addon', '--pod'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/components/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "import layout from './template';", + "export default Ember.Component.extend({", + "layout", + "});" + ] + }, + { + file: 'lib/my-addon/addon/components/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'lib/my-addon/app/components/x-foo/component.js', + contains: [ + "export { default } from 'my-addon/components/x-foo/component';" + ] + }, + { + file: 'tests/integration/components/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "moduleForComponent('x-foo'", + "integration: true" + ] + } + ] + }); + }); + + it('in-repo-addon component nested/x-foo', function() { + return generateAndDestroy(['component', 'nested/x-foo', '--in-repo-addon=my-addon', '--pod'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/components/nested/x-foo/component.js', + contains: [ + "import Ember from 'ember';", + "import layout from './template';", + "export default Ember.Component.extend({", + "layout", + "});" + ] + }, + { + file: 'lib/my-addon/addon/components/nested/x-foo/template.hbs', + contains: "{{yield}}" + }, + { + file: 'lib/my-addon/app/components/nested/x-foo/component.js', + contains: [ + "export { default } from 'my-addon/components/nested/x-foo/component';" + ] + }, + { + file: 'tests/integration/components/nested/x-foo/component-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "moduleForComponent('nested/x-foo'", + "integration: true" + ] + } + ] + }); + }); + + it('component-test x-foo', function() { + return generateAndDestroy(['component-test', 'x-foo'], { + files: [ + { + file: 'tests/integration/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + } + ] + }); + }); + + it('component-test x-foo --unit', function() { + return generateAndDestroy(['component-test', 'x-foo', '--unit'], { + files: [ + { + file: 'tests/unit/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "moduleForComponent('x-foo'", + "unit: true" + ] + } + ] + }); + }); + + it('in-addon component-test x-foo', function() { + return generateAndDestroy(['component-test', 'x-foo'], { + target: 'addon', + files: [ + { + file:'tests/integration/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + }, + { + file: 'app/component-test/x-foo.js', + exists: false + } + ] + }); + }); + + it('in-addon component-test x-foo --unit', function() { + return generateAndDestroy(['component-test', 'x-foo', '--unit'], { + target: 'addon', + files: [ + { + file:'tests/unit/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "moduleForComponent('x-foo'", + "unit: true" + ] + }, + { + file: 'app/component-test/x-foo.js', + exists: false + } + ] + }); + }); + + it('dummy component-test x-foo', function() { + return generateAndDestroy(['component-test', 'x-foo', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/integration/components/x-foo-test.js', + contains: [ + "import { moduleForComponent, test } from 'ember-qunit';", + "import hbs from 'htmlbars-inline-precompile';", + "moduleForComponent('x-foo'" + ] + }, + { + file: 'app/component-test/x-foo.js', + exists: false + } + ] + }); + }); + + it('component-test x-foo for mocha', function() { + return generateAndDestroy(['component-test', 'x-foo'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/integration/components/x-foo-test.js', + contains: [ + "import { describeComponent, it } from 'ember-mocha';", + "import hbs from 'htmlbars-inline-precompile';", + "describeComponent('x-foo', 'Integration | Component | x foo'", + "integration: true", + "{{x-foo}}", + "{{#x-foo}}" + ] + } + ] + }); + }); + + it('component-test x-foo --unit for mocha', function() { + return generateAndDestroy(['component-test', 'x-foo', '--unit'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/unit/components/x-foo-test.js', + contains: [ + "import { describeComponent, it } from 'ember-mocha';", + "describeComponent('x-foo', 'Unit | Component | x foo", + "unit: true" + ] + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/controller-test.js b/node-tests/blueprints/controller-test.js new file mode 100644 index 00000000000..66a84b6410a --- /dev/null +++ b/node-tests/blueprints/controller-test.js @@ -0,0 +1,346 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy controller', function() { + setupTestHooks(this); + + it('controller foo', function() { + return generateAndDestroy(['controller', 'foo'], { + files: [ + { + file: 'app/controllers/foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'tests/unit/controllers/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo'" + ] + }, + ] + }); + }); + + it('controller foo/bar', function() { + return generateAndDestroy(['controller', 'foo/bar'], { + files: [ + { + file: 'app/controllers/foo/bar.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'tests/unit/controllers/foo/bar-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo/bar'" + ] + } + ] + }); + }); + + it('in-addon controller foo', function() { + return generateAndDestroy(['controller', 'foo'], { + target: 'addon', + files: [ + { + file: 'addon/controllers/foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'app/controllers/foo.js', + contains: [ + "export { default } from 'my-addon/controllers/foo';" + ] + }, + { + file: 'tests/unit/controllers/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo'" + ] + } + ] + }); + }); + + it('in-addon controller foo/bar', function() { + return generateAndDestroy(['controller', 'foo/bar'], { + target: 'addon', + files: [ + { + file: 'addon/controllers/foo/bar.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'app/controllers/foo/bar.js', + contains: [ + "export { default } from 'my-addon/controllers/foo/bar';" + ] + }, + { + file: 'tests/unit/controllers/foo/bar-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo/bar'" + ] + } + ] + }); + }); + + it('dummy controller foo', function() { + return generateAndDestroy(['controller', 'foo', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/dummy/app/controllers/foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'app/controllers/foo-test.js', + exists: false + }, + { + file: 'tests/unit/controllers/foo-test.js', + exists: false + } + ] + }); + }); + + it('dummy controller foo/bar', function() { + return generateAndDestroy(['controller', 'foo/bar', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/dummy/app/controllers/foo/bar.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'app/controllers/foo/bar.js', + exists: false + }, + { + file: 'tests/unit/controllers/foo/bar-test.js', + exists: false + } + ] + }); + }); + + it('in-repo-addon controller foo', function() { + return generateAndDestroy(['controller', 'foo', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/controllers/foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'lib/my-addon/app/controllers/foo.js', + contains: [ + "export { default } from 'my-addon/controllers/foo';" + ] + }, + { + file: 'tests/unit/controllers/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo'" + ] + } + ] + }); + }); + + it('in-repo-addon controller foo/bar', function() { + return generateAndDestroy(['controller', 'foo/bar', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/controllers/foo/bar.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'lib/my-addon/app/controllers/foo/bar.js', + contains: [ + "export { default } from 'my-addon/controllers/foo/bar';" + ] + }, + { + file: 'tests/unit/controllers/foo/bar-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo/bar'" + ] + } + ] + }); + }); + +/** +* Pod tests +* +*/ + it('controller foo --pod', function() { + return generateAndDestroy(['controller', 'foo', '--pod'], { + files: [ + { + file: 'app/foo/controller.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'tests/unit/foo/controller-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo'" + ] + } + ] + }); + }); + + it('controller foo --pod podModulePrefix', function() { + return generateAndDestroy(['controller', 'foo', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/foo/controller.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'tests/unit/pods/foo/controller-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo'" + ] + } + ] + }); + }); + + it('controller foo/bar --pod', function() { + return generateAndDestroy(['controller', 'foo/bar', '--pod'], { + files: [ + { + file: 'app/foo/bar/controller.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'tests/unit/foo/bar/controller-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo/bar'" + ] + } + ] + }); + }); + + it('controller foo/bar --pod podModulePrefix', function() { + return generateAndDestroy(['controller', 'foo/bar', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/foo/bar/controller.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Controller.extend({\n});" + ] + }, + { + file: 'tests/unit/pods/foo/bar/controller-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo/bar'" + ] + } + ] + }); + }); + + it('controller-test foo', function() { + return generateAndDestroy(['controller-test', 'foo'], { + files: [ + { + file: 'tests/unit/controllers/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo'" + ] + }, + ] + }); + }); + + it('in-addon controller-test foo', function() { + return generateAndDestroy(['controller-test', 'foo'], { + target: 'addon', + files: [ + { + file: 'tests/unit/controllers/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('controller:foo'" + ] + } + ] + }); + }); + + it('controller-test foo for mocha', function() { + return generateAndDestroy(['controller-test', 'foo'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/unit/controllers/foo-test.js', + contains: [ + "import { describeModule, it } from 'ember-mocha';", + "describeModule('controller:foo', 'Unit | Controller | foo'" + ] + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/helper-addon-test.js b/node-tests/blueprints/helper-addon-test.js new file mode 100644 index 00000000000..bf8a29e8d53 --- /dev/null +++ b/node-tests/blueprints/helper-addon-test.js @@ -0,0 +1,24 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy helper-addon', function() { + setupTestHooks(this); + + it('in-addon helper-addon foo-bar', function() { + return generateAndDestroy(['helper-addon', 'foo-bar'], { + target: 'addon', + files: [ + { + file: 'app/helpers/foo-bar.js', + contains: [ + "export { default, fooBar } from 'my-addon/helpers/foo-bar';" + ] + }, + ] + }); + }); + +}); diff --git a/node-tests/blueprints/helper-test.js b/node-tests/blueprints/helper-test.js new file mode 100644 index 00000000000..f63911355f4 --- /dev/null +++ b/node-tests/blueprints/helper-test.js @@ -0,0 +1,304 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy helper', function() { + setupTestHooks(this); + + it('helper foo/bar-baz', function() { + return generateAndDestroy(['helper', 'foo/bar-baz'], { + files: [ + { + file: 'app/helpers/foo/bar-baz.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBarBaz(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBarBaz);" + }, + { + file: 'tests/unit/helpers/foo/bar-baz-test.js', + contains: "import { fooBarBaz } from 'my-app/helpers/foo/bar-baz';" + } + ] + }); + }); + + it('in-addon helper foo-bar', function() { + return generateAndDestroy(['helper', 'foo-bar'], { + target: 'addon', + files: [ + { + file: 'addon/helpers/foo-bar.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBar(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBar);" + }, + { + file: 'app/helpers/foo-bar.js', + contains: [ + "export { default, fooBar } from 'my-addon/helpers/foo-bar';" + ] + }, + { + file: 'tests/unit/helpers/foo-bar-test.js', + contains: "import { fooBar } from 'dummy/helpers/foo-bar';" + } + ] + }); + }); + + it('in-addon helper foo/bar-baz', function() { + return generateAndDestroy(['helper', 'foo/bar-baz'], { + target: 'addon', + files: [ + { + file: 'addon/helpers/foo/bar-baz.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBarBaz(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBarBaz);" + }, + { + file: 'app/helpers/foo/bar-baz.js', + contains: [ + "export { default, fooBarBaz } from 'my-addon/helpers/foo/bar-baz';" + ] + }, + { + file: 'tests/unit/helpers/foo/bar-baz-test.js', + contains: "import { fooBarBaz } from 'dummy/helpers/foo/bar-baz';" + } + ] + }); + }); + + it('dummy helper foo-bar', function() { + return generateAndDestroy(['helper', 'foo-bar', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/dummy/app/helpers/foo-bar.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBar(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBar);" + }, + { + file: 'app/helpers/foo-bar.js', + exists: false + }, + { + file: 'tests/unit/helpers/foo-bar-test.js', + exists: false + } + ] + }); + }); + + it('dummy helper foo/bar-baz', function() { + return generateAndDestroy(['helper', 'foo/bar-baz', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/dummy/app/helpers/foo/bar-baz.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBarBaz(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBarBaz);" + }, + { + file: 'app/helpers/foo/bar-baz.js', + exists: false + }, + { + file: 'tests/unit/helpers/foo/bar-baz-test.js', + exists: false + } + ] + }); + }); + + it('in-repo-addon helper foo-bar', function() { + return generateAndDestroy(['helper', 'foo-bar', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/helpers/foo-bar.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBar(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBar);" + }, + { + file: 'lib/my-addon/app/helpers/foo-bar.js', + contains: [ + "export { default, fooBar } from 'my-addon/helpers/foo-bar';" + ] + }, + { + file: 'tests/unit/helpers/foo-bar-test.js', + contains: "import { fooBar } from 'my-app/helpers/foo-bar';" + } + ] + }); + }); + + it('in-repo-addon helper foo/bar-baz', function() { + return generateAndDestroy(['helper', 'foo/bar-baz', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/helpers/foo/bar-baz.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBarBaz(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBarBaz);" + }, + { + file: 'lib/my-addon/app/helpers/foo/bar-baz.js', + contains: [ + "export { default, fooBarBaz } from 'my-addon/helpers/foo/bar-baz';" + ] + }, + { + file: 'tests/unit/helpers/foo/bar-baz-test.js', + contains: "import { fooBarBaz } from 'my-app/helpers/foo/bar-baz';" + } + ] + }); + }); + +/** +* Pod tests +* +*/ + it('helper foo-bar --pod', function() { + return generateAndDestroy(['helper', 'foo-bar', '--pod'], { + files: [ + { + file: 'app/helpers/foo-bar.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBar(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBar);" + }, + { + file: 'tests/unit/helpers/foo-bar-test.js', + contains: "import { fooBar } from 'my-app/helpers/foo-bar';" + } + ] + }); + }); + + it('helper foo-bar --pod podModulePrefix', function() { + return generateAndDestroy(['helper', 'foo-bar', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/helpers/foo-bar.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBar(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBar);" + }, + { + file: 'tests/unit/helpers/foo-bar-test.js', + contains: "import { fooBar } from 'my-app/helpers/foo-bar';" + } + ] + }); + }); + + it('helper foo/bar-baz --pod', function() { + return generateAndDestroy(['helper', 'foo/bar-baz', '--pod'], { + files: [ + { + file: 'app/helpers/foo/bar-baz.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBarBaz(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBarBaz);" + }, + { + file: 'tests/unit/helpers/foo/bar-baz-test.js', + contains: "import { fooBarBaz } from 'my-app/helpers/foo/bar-baz';" + } + ] + }); + }); + + it('helper foo/bar-baz --pod podModulePrefix', function() { + return generateAndDestroy(['helper', 'foo/bar-baz', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/helpers/foo/bar-baz.js', + contains: "import Ember from 'ember';\n\n" + + "export function fooBarBaz(params/*, hash*/) {\n" + + " return params;\n" + + "}\n\n" + + "export default Ember.Helper.helper(fooBarBaz);" + }, + { + file: 'tests/unit/helpers/foo/bar-baz-test.js', + contains: "import { fooBarBaz } from 'my-app/helpers/foo/bar-baz';" + } + ] + }); + }); + + it('helper-test foo/bar-baz', function() { + return generateAndDestroy(['helper-test', 'foo/bar-baz'], { + files: [ + { + file: 'tests/unit/helpers/foo/bar-baz-test.js', + contains: "import { fooBarBaz } from 'my-app/helpers/foo/bar-baz';" + } + ] + }); + }); + + it('in-addon helper-test foo-bar', function() { + return generateAndDestroy(['helper-test', 'foo-bar'], { + target: 'addon', + files: [ + { + file: 'tests/unit/helpers/foo-bar-test.js', + contains: "import { fooBar } from 'dummy/helpers/foo-bar';" + } + ] + }); + }); + + it('helper-test foo/bar-baz for mocha', function() { + return generateAndDestroy(['helper-test', 'foo/bar-baz'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/unit/helpers/foo/bar-baz-test.js', + contains: [ + "import { describe, it } from 'mocha';", + "import { fooBarBaz } from 'my-app/helpers/foo/bar-baz';", + "describe('Unit | Helper | foo/bar baz', function() {" + ] + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/initializer-addon-test.js b/node-tests/blueprints/initializer-addon-test.js new file mode 100644 index 00000000000..b195b3cbb3c --- /dev/null +++ b/node-tests/blueprints/initializer-addon-test.js @@ -0,0 +1,24 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy initializer-addon', function() { + setupTestHooks(this); + + it('initializer-addon foo', function() { + // pass any additional command line options in the arguments array + return generateAndDestroy(['initializer-addon', 'foo'], { + // define files to assert, and their contents + target: 'addon', + files: [ + { + file: 'app/initializers/foo.js', + contains: "export { default, initialize } from 'my-addon/initializers/foo';" + } + ] + }); + }); + +}); diff --git a/node-tests/blueprints/initializer-test.js b/node-tests/blueprints/initializer-test.js new file mode 100644 index 00000000000..978484a72db --- /dev/null +++ b/node-tests/blueprints/initializer-test.js @@ -0,0 +1,350 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy initializer', function() { + setupTestHooks(this); + + it('initializer foo', function() { + return generateAndDestroy(['initializer', 'foo'], { + files: [ + { + file:'app/initializers/foo.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + }, + { + file:'tests/unit/initializers/foo-test.js', + contains: "import FooInitializer from 'my-app/initializers/foo';" + } + ] + }); + }); + + it('initializer foo/bar', function() { + return generateAndDestroy(['initializer', 'foo/bar'], { + files: [ + { + file:'app/initializers/foo/bar.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + }, + { + file:'tests/unit/initializers/foo/bar-test.js', + contains: "import FooBarInitializer from 'my-app/initializers/foo/bar';" + } + ] + }); + }); + + it('in-addon initializer foo', function() { + return generateAndDestroy(['initializer', 'foo'], { + target: 'addon', + files: [ + { + file: 'addon/initializers/foo.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + }, + { + file: 'app/initializers/foo.js', + contains: [ + "export { default, initialize } from 'my-addon/initializers/foo';" + ] + }, + { + file: 'tests/unit/initializers/foo-test.js' + } + ] + }); + }); + + it('in-addon initializer foo/bar', function() { + return generateAndDestroy(['initializer', 'foo/bar'], { + target: 'addon', + files: [ + { + file: 'addon/initializers/foo/bar.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + }, + { + file: 'app/initializers/foo/bar.js', + contains: [ + "export { default, initialize } from 'my-addon/initializers/foo/bar';" + ] + }, + { + file: 'tests/unit/initializers/foo/bar-test.js' + } + ] + }); + }); + + it('dummy initializer foo', function() { + return generateAndDestroy(['initializer', 'foo', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/dummy/app/initializers/foo.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + }, + { + file: 'app/initializers/foo.js', + exists: false + }, + { + file: 'tests/unit/initializers/foo-test.js', + exists: false + } + ] + }); + }); + + it('dummy initializer foo/bar', function() { + return generateAndDestroy(['initializer', 'foo/bar', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/dummy/app/initializers/foo/bar.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + }, + { + file: 'app/initializers/foo/bar.js', + exists: false + }, + { + file: 'tests/unit/initializers/foo/bar-test.js', + exists: false + } + ] + }); + }); + + it('in-repo-addon initializer foo', function() { + return generateAndDestroy(['initializer', 'foo', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/initializers/foo.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + }, + { + file: 'lib/my-addon/app/initializers/foo.js', + contains: [ + "export { default, initialize } from 'my-addon/initializers/foo';" + ] + }, + { + file: 'tests/unit/initializers/foo-test.js' + } + ] + }); + }); + + it('in-repo-addon initializer foo/bar', function() { + return generateAndDestroy(['initializer', 'foo/bar', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/initializers/foo/bar.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + }, + { + file: 'lib/my-addon/app/initializers/foo/bar.js', + contains: [ + "export { default, initialize } from 'my-addon/initializers/foo/bar';" + ] + }, + { + file: 'tests/unit/initializers/foo/bar-test.js' + } + ] + }); + }); + + /* Pod tests */ + + it('initializer foo --pod', function() { + return generateAndDestroy(['initializer', 'foo', '--pod'], { + files: [ + { + file: 'app/initializers/foo.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + } + ] + }); + }); + + it('initializer foo --pod podModulePrefix', function() { + return generateAndDestroy(['initializer', 'foo', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/initializers/foo.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + } + ] + }); + }); + + it('initializer foo/bar --pod', function() { + return generateAndDestroy(['initializer', 'foo/bar', '--pod'], { + files: [ + { + file: 'app/initializers/foo/bar.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + } + ] + }); + }); + + + it('initializer foo/bar --pod podModulePrefix', function() { + return generateAndDestroy(['initializer', 'foo/bar', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/initializers/foo/bar.js', + contains: "export function initialize(/* application */) {\n" + + " // application.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + } + ] + }); + }); + + + it('initializer-test foo', function() { + return generateAndDestroy(['initializer-test', 'foo'], { + files: [ + { + file: 'tests/unit/initializers/foo-test.js', + contains: [ + "import FooInitializer from 'my-app/initializers/foo';", + "module('Unit | Initializer | foo'", + "application = Ember.Application.create();", + "FooInitializer.initialize(application);" + ] + } + ] + }); + }); + + it('in-addon initializer-test foo', function() { + return generateAndDestroy(['initializer-test', 'foo'], { + target: 'addon', + files: [ + { + file: 'tests/unit/initializers/foo-test.js', + contains: [ + "import FooInitializer from 'dummy/initializers/foo';", + "module('Unit | Initializer | foo'", + "application = Ember.Application.create();", + "FooInitializer.initialize(application);" + ] + } + ] + }); + }); + + it('initializer-test foo for mocha', function() { + return generateAndDestroy(['initializer-test', 'foo'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/unit/initializers/foo-test.js', + contains: [ + "import FooInitializer from 'my-app/initializers/foo';", + "describe('Unit | Initializer | foo', function() {", + "application = Ember.Application.create();", + "FooInitializer.initialize(application);" + ] + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/instance-initializer-addon-test.js b/node-tests/blueprints/instance-initializer-addon-test.js new file mode 100644 index 00000000000..6e159cbbc67 --- /dev/null +++ b/node-tests/blueprints/instance-initializer-addon-test.js @@ -0,0 +1,25 @@ +'use strict'; + +var tmpenv = require('ember-cli-blueprint-test-helpers/lib/helpers/tmp-env'); +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy instance-initializer-addon', function() { + setupTestHooks(this, tmpenv); + + it('instance-initializer-addon foo', function() { + // pass any additional command line options in the arguments array + return generateAndDestroy(['instance-initializer-addon', 'foo'], { + // define files to assert, and their contents + target: 'addon', + files: [ + { + file: 'app/instance-initializers/foo.js', + contains: "export { default, initialize } from 'my-addon/instance-initializers/foo';" + } + ] + }); + }); + +}); diff --git a/node-tests/blueprints/instance-initializer-test.js b/node-tests/blueprints/instance-initializer-test.js new file mode 100644 index 00000000000..94e7e0b95c0 --- /dev/null +++ b/node-tests/blueprints/instance-initializer-test.js @@ -0,0 +1,353 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy instance-initializer', function() { + setupTestHooks(this); + + it('instance-initializer foo', function() { + return generateAndDestroy(['instance-initializer', 'foo'], { + files: [ + { + file:'app/instance-initializers/foo.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + }, + { + file:'tests/unit/instance-initializers/foo-test.js', + contains: "import { initialize } from 'my-app/instance-initializers/foo';" + } + ] + }); + }); + + it('instance-initializer foo/bar', function() { + return generateAndDestroy(['instance-initializer', 'foo/bar'], { + files: [ + { + file:'app/instance-initializers/foo/bar.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + }, + { + file:'tests/unit/instance-initializers/foo/bar-test.js', + contains: "import { initialize } from 'my-app/instance-initializers/foo/bar';" + } + ] + }); + }); + + it('in-addon instance-initializer foo', function() { + return generateAndDestroy(['instance-initializer', 'foo'], { + target: 'addon', + files: [ + { + file: 'addon/instance-initializers/foo.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + }, + { + file: 'app/instance-initializers/foo.js', + contains: [ + "export { default, initialize } from 'my-addon/instance-initializers/foo';" + ] + }, + { + file: 'tests/unit/instance-initializers/foo-test.js' + } + ] + }); + }); + + it('in-addon instance-initializer foo/bar', function() { + return generateAndDestroy(['instance-initializer', 'foo/bar'], { + target: 'addon', + files: [ + { + file: 'addon/instance-initializers/foo/bar.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + }, + { + file: 'app/instance-initializers/foo/bar.js', + contains: [ + "export { default, initialize } from 'my-addon/instance-initializers/foo/bar';" + ] + }, + { + file: 'tests/unit/instance-initializers/foo/bar-test.js' + } + ] + }); + }); + + it('dummy instance-initializer foo', function() { + return generateAndDestroy(['instance-initializer', 'foo', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/dummy/app/instance-initializers/foo.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + }, + { + file: 'app/instance-initializers/foo.js', + exists: false + }, + { + file: 'tests/unit/instance-initializers/foo-test.js', + exists: false + } + ] + }); + }); + + it('dummy instance-initializer foo/bar', function() { + return generateAndDestroy(['instance-initializer', 'foo/bar', '--dummy'], { + target: 'addon', + files: [ + { + file: 'tests/dummy/app/instance-initializers/foo/bar.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + }, + { + file: 'app/instance-initializers/foo/bar.js', + exists: false + }, + { + file: 'tests/unit/instance-initializers/foo/bar-test.js', + exists: false + } + ] + }); + }); + + it('in-repo-addon instance-initializer foo', function() { + return generateAndDestroy(['instance-initializer', 'foo', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/instance-initializers/foo.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + }, + { + file: 'lib/my-addon/app/instance-initializers/foo.js', + contains: [ + "export { default, initialize } from 'my-addon/instance-initializers/foo';" + ] + }, + { + file: 'tests/unit/instance-initializers/foo-test.js' + } + ] + }); + }); + + it('in-repo-addon instance-initializer foo/bar', function() { + return generateAndDestroy(['instance-initializer', 'foo/bar', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/instance-initializers/foo/bar.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + }, + { + file: 'lib/my-addon/app/instance-initializers/foo/bar.js', + contains: [ + "export { default, initialize } from 'my-addon/instance-initializers/foo/bar';" + ] + }, + { + file: 'tests/unit/instance-initializers/foo/bar-test.js' + } + ] + }); + }); + + /* Pod tests */ + + it('instance-initializer foo --pod', function() { + return generateAndDestroy(['instance-initializer', 'foo', '--pod'], { + files: [ + { + file: 'app/instance-initializers/foo.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + } + ] + }); + }); + + it('instance-initializer foo --pod podModulePrefix', function() { + return generateAndDestroy(['instance-initializer', 'foo', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/instance-initializers/foo.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo',\n" + + " initialize\n" + + "};" + } + ] + }); + }); + + it('instance-initializer foo/bar --pod', function() { + return generateAndDestroy(['instance-initializer', 'foo/bar', '--pod'], { + files: [ + { + file: 'app/instance-initializers/foo/bar.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + } + ] + }); + }); + + + it('instance-initializer foo/bar --pod podModulePrefix', function() { + return generateAndDestroy(['instance-initializer', 'foo/bar', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/instance-initializers/foo/bar.js', + contains: "export function initialize(/* appInstance */) {\n" + + " // appInstance.inject('route', 'foo', 'service:foo');\n" + + "}\n" + + "\n"+ + "export default {\n" + + " name: 'foo/bar',\n" + + " initialize\n" + + "};" + } + ] + }); + }); + + + it('instance-initializer-test foo', function() { + return generateAndDestroy(['instance-initializer-test', 'foo'], { + files: [ + { + file: 'tests/unit/instance-initializers/foo-test.js', + contains: [ + "import { initialize } from 'my-app/instance-initializers/foo';", + "module('Unit | Instance Initializer | foo'", + "application = Ember.Application.create();", + "this.appInstance = this.application.buildInstance();", + "initialize(this.appInstance);" + ] + } + ] + }); + }); + + it('in-addon instance-initializer-test foo', function() { + return generateAndDestroy(['instance-initializer-test', 'foo'], { + target: 'addon', + files: [ + { + file: 'tests/unit/instance-initializers/foo-test.js', + contains: [ + "import { initialize } from 'dummy/instance-initializers/foo';", + "module('Unit | Instance Initializer | foo'", + "application = Ember.Application.create();", + "this.appInstance = this.application.buildInstance();", + "initialize(this.appInstance);" + ] + } + ] + }); + }); + + it('instance-initializer-test foo for mocha', function() { + return generateAndDestroy(['instance-initializer-test', 'foo'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/unit/instance-initializers/foo-test.js', + contains: [ + "import { initialize } from 'my-app/instance-initializers/foo';", + "describe('Unit | Instance Initializer | foo', function() {", + "application = Ember.Application.create();", + "appInstance = application.buildInstance();", + "initialize(appInstance);" + ] + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/mixin-test.js b/node-tests/blueprints/mixin-test.js new file mode 100644 index 00000000000..37eb296d27d --- /dev/null +++ b/node-tests/blueprints/mixin-test.js @@ -0,0 +1,336 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy mixin', function() { + setupTestHooks(this); + + it('mixin foo', function() { + return generateAndDestroy(['mixin', 'foo'], { + files: [ + { + file: 'app/mixins/foo.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo-test.js', + contains: [ + "import FooMixin from 'my-app/mixins/foo';" + ] + } + ] + }); + }); + + it('mixin foo/bar', function() { + return generateAndDestroy(['mixin', 'foo/bar'], { + files: [ + { + file: 'app/mixins/foo/bar.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo/bar-test.js', + contains: [ + "import FooBarMixin from 'my-app/mixins/foo/bar';" + ] + } + ] + }); + }); + + it('mixin foo/bar/baz', function() { + return generateAndDestroy(['mixin', 'foo/bar/baz'], { + files: [ + { + file: 'tests/unit/mixins/foo/bar/baz-test.js', + contains: [ + "import FooBarBazMixin from 'my-app/mixins/foo/bar/baz';" + ] + } + ] + }); + }); + + it('in-addon mixin foo', function() { + return generateAndDestroy(['mixin', 'foo'], { + target: 'addon', + files: [ + { + file: 'addon/mixins/foo.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo-test.js', + contains: [ + "import FooMixin from 'my-addon/mixins/foo';" + ] + }, + { + file: 'app/mixins/foo.js', + exists: false + } + ] + }); + }); + + it('in-addon mixin foo/bar', function() { + return generateAndDestroy(['mixin', 'foo/bar'], { + target: 'addon', + files: [ + { + file: 'addon/mixins/foo/bar.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo/bar-test.js', + contains: [ + "import FooBarMixin from 'my-addon/mixins/foo/bar';" + ] + }, + { + file: 'app/mixins/foo/bar.js', + exists: false + } + ] + }); + }); + + it('in-addon mixin foo/bar/baz', function() { + return generateAndDestroy(['mixin', 'foo/bar/baz'], { + target: 'addon', + files: [ + { + file: 'addon/mixins/foo/bar/baz.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo/bar/baz-test.js', + contains: [ + "import FooBarBazMixin from 'my-addon/mixins/foo/bar/baz';" + ] + }, + { + file: 'app/mixins/foo/bar/baz.js', + exists: false + } + ] + }); + }) + + it('in-repo-addon mixin foo', function() { + return generateAndDestroy(['mixin', 'foo', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/mixins/foo.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo-test.js', + contains: [ + "import FooMixin from 'my-addon/mixins/foo';" + ] + } + ] + }); + }); + + it('in-repo-addon mixin foo/bar', function() { + return generateAndDestroy(['mixin', 'foo/bar', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/mixins/foo/bar.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo/bar-test.js', + contains: [ + "import FooBarMixin from 'my-addon/mixins/foo/bar';" + ] + } + ] + }); + }); + + it('in-repo-addon mixin foo/bar/baz', function() { + return generateAndDestroy(['mixin', 'foo/bar/baz', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'tests/unit/mixins/foo/bar/baz-test.js', + contains: [ + "import FooBarBazMixin from 'my-addon/mixins/foo/bar/baz';" + ] + } + ] + }); + }); + + /* Pod tests */ + + it('mixin foo --pod', function() { + return generateAndDestroy(['mixin', 'foo', '--pod'], { + files: [ + { + file: 'app/mixins/foo.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo-test.js', + contains: [ + "import FooMixin from 'my-app/mixins/foo';" + ] + } + ] + }); + }); + + it('mixin foo --pod podModulePrefix', function() { + return generateAndDestroy(['mixin', 'foo', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/mixins/foo.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo-test.js', + contains: [ + "import FooMixin from 'my-app/mixins/foo';" + ] + } + ] + }); + }); + + it('mixin foo/bar --pod', function() { + return generateAndDestroy(['mixin', 'foo/bar', '--pod'], { + files: [ + { + file: 'app/mixins/foo/bar.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo/bar-test.js', + contains: [ + "import FooBarMixin from 'my-app/mixins/foo/bar';" + ] + } + ] + }); + }); + + it('mixin foo/bar --pod podModulePrefix', function() { + return generateAndDestroy(['mixin', 'foo/bar', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/mixins/foo/bar.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Mixin.create({\n});' + ] + }, + { + file: 'tests/unit/mixins/foo/bar-test.js', + contains: [ + "import FooBarMixin from 'my-app/mixins/foo/bar';" + ] + } + ] + }); + }); + + it('mixin foo/bar/baz --pod', function() { + return generateAndDestroy(['mixin', 'foo/bar/baz', '--pod'], { + files: [ + { + file: 'tests/unit/mixins/foo/bar/baz-test.js', + contains: [ + "import FooBarBazMixin from 'my-app/mixins/foo/bar/baz';" + ] + } + ] + }); + }); + + it('mixin-test foo', function() { + return generateAndDestroy(['mixin-test', 'foo'], { + files: [ + { + file: 'tests/unit/mixins/foo-test.js', + contains: [ + "import FooMixin from 'my-app/mixins/foo';" + ] + } + ] + }); + }); + + it('in-addon mixin-test foo', function() { + return generateAndDestroy(['mixin-test', 'foo'], { + target: 'addon', + files: [ + { + file: 'tests/unit/mixins/foo-test.js', + contains: [ + "import FooMixin from 'my-addon/mixins/foo';" + ] + } + ] + }); + }); + + it('mixin-test foo for mocha', function() { + return generateAndDestroy(['mixin-test', 'foo'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/unit/mixins/foo-test.js', + contains: [ + "import { describe, it } from 'mocha';", + "import FooMixin from 'my-app/mixins/foo';", + "describe('Unit | Mixin | foo', function() {" + ] + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/route-addon-test.js b/node-tests/blueprints/route-addon-test.js new file mode 100644 index 00000000000..ae1307d4a7d --- /dev/null +++ b/node-tests/blueprints/route-addon-test.js @@ -0,0 +1,30 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy route-addon', function() { + setupTestHooks(this); + + it('route-addon foo', function() { + return generateAndDestroy(['route-addon', 'foo'], { + target: 'addon', + files: [ + { + file: 'app/routes/foo.js', + contains: [ + "export { default } from 'my-addon/routes/foo';" + ] + }, + { + file: 'app/templates/foo.js', + contains: [ + "export { default } from 'my-addon/templates/foo';" + ] + }, + ] + }); + }); + +}); diff --git a/node-tests/blueprints/route-test.js b/node-tests/blueprints/route-test.js new file mode 100644 index 00000000000..918eb4b7b90 --- /dev/null +++ b/node-tests/blueprints/route-test.js @@ -0,0 +1,674 @@ +'use strict'; + +var fs = require('fs-extra'); +var path = require('path'); +var RSVP = require('rsvp'); +var remove = RSVP.denodeify(fs.remove); +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var initProject = require('ember-cli-blueprint-test-helpers/lib/helpers/project-init'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; +var destroy = BlueprintHelpers.destroy; + + +describe('Acceptance: ember generate and destroy route', function() { + setupTestHooks(this); + + it('route foo', function() { + var files = [ + { + file: 'app/router.js', + contains: 'this.route(\'foo\')' + }, + { + file: 'app/routes/foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'app/templates/foo.hbs', + contains: '{{outlet}}' + }, + { + file: 'tests/unit/routes/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo'" + ] + } + ]; + + return generateAndDestroy(['route', 'foo'], { + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('route foo with --skip-router', function() { + var files = [ + { + file: 'app/router.js', + doesNotContain: 'this.route(\'foo\')' + }, + { + file: 'app/routes/foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'app/templates/foo.hbs', + contains: '{{outlet}}' + }, + { + file: 'tests/unit/routes/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo'" + ] + } + ]; + + return generateAndDestroy(['route', 'foo', '--skip-router'], { + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('route foo with --path', function() { + var files = [ + { + file: 'app/router.js', + contains: [ + 'this.route(\'foo\', {', + 'path: \':foo_id/show\'', + '});' + ] + } + ]; + + return generateAndDestroy(['route', 'foo', '--path=:foo_id/show'], { + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('route index', function() { + var files = [ + { + file: 'app/router.js', + doesNotContain: "this.route('index');" + } + ]; + + return generateAndDestroy(['route', 'index'], { + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('route application', function() { + return generateAndDestroy(['route', 'foo'], { + afterGenerate: function(){ + return remove(path.join('app', 'templates', 'application.hbs')) + .then(function() { + var files = [ + { + file: 'app/router.js', + doesNotContain: "this.route('application');" + } + ]; + + return generateAndDestroy(['route', 'application'], { + skipInit: true, + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + } + }); + }); + + it('route basic isn\'t added to router', function() { + var files = [ + { + file: 'app/router.js', + doesNotContain: "this.route('basic');" + }, + { + file: 'app/routes/basic.js' + } + ]; + + return generateAndDestroy(['route', 'basic'], { + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('in-addon route foo', function() { + var files = [ + { + file: 'addon/routes/foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'app/routes/foo.js', + contains: [ + "export { default } from 'my-addon/routes/foo';" + ] + }, + { + file: 'addon/templates/foo.hbs', + contains: '{{outlet}}' + }, + { + file: 'app/templates/foo.js', + contains: "export { default } from 'my-addon/templates/foo';" + }, + { + file: 'tests/unit/routes/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo'" + ] + }, + { + file: 'tests/dummy/app/router.js', + doesNotContain: "this.route('foo');" + } + ]; + + return generateAndDestroy(['route', 'foo'], { + target: 'addon', + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.pop(); + }, + files: files, + }); + }); + + it('in-addon route foo/bar', function() { + var files = [ + { + file: 'addon/routes/foo/bar.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'app/routes/foo/bar.js', + contains: "export { default } from 'my-addon/routes/foo/bar';" + }, + { + file: 'app/templates/foo/bar.js', + contains: "export { default } from 'my-addon/templates/foo/bar';" + }, + { + file: 'tests/unit/routes/foo/bar-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo/bar'" + ] + }, + { + file: 'tests/dummy/app/router.js', + doesNotContain: "this.route('bar');" + } + ]; + + return generateAndDestroy(['route', 'foo/bar'], { + target: 'addon', + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.pop(); + }, + files: files, + }); + }); + + it('dummy route foo', function() { + var files = [ + { + file: 'tests/dummy/app/router.js', + contains: "this.route('foo');" + }, + { + file: 'tests/dummy/app/routes/foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'app/routes/foo.js', + exists: false + }, + { + file: 'tests/dummy/app/templates/foo.hbs', + contains: '{{outlet}}' + }, + { + file: 'app/templates/foo.js', + exists: false + }, + { + file: 'tests/unit/routes/foo-test.js', + exists: false + } + ]; + + return generateAndDestroy(['route', 'foo', '--dummy'], { + target: 'addon', + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('dummy route foo/bar', function() { + var files = [ + { + file: 'tests/dummy/app/router.js', + contains: [ + "this.route('foo', function() {", + "this.route('bar');", + ] + }, + { + file: 'tests/dummy/app/routes/foo/bar.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'app/routes/foo/bar.js', + exists: false + }, + { + file: 'tests/dummy/app/templates/foo/bar.hbs', + contains: '{{outlet}}' + }, + { + file: 'tests/unit/routes/foo/bar-test.js', + exists: false + } + ]; + + return generateAndDestroy(['route', 'foo/bar', '--dummy'], { + target: 'addon', + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('in-repo-addon route foo', function() { + return generateAndDestroy(['route', 'foo', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/routes/foo.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'lib/my-addon/app/routes/foo.js', + contains: "export { default } from 'my-addon/routes/foo';" + }, + { + file: 'lib/my-addon/addon/templates/foo.hbs', + contains: '{{outlet}}' + }, + { + file: 'lib/my-addon/app/templates/foo.js', + contains: "export { default } from 'my-addon/templates/foo';" + }, + { + file: 'tests/unit/routes/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo'" + ] + } + ] + }); + }); + + it('in-repo-addon route foo/bar', function() { + return generateAndDestroy(['route', 'foo/bar', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { + file: 'lib/my-addon/addon/routes/foo/bar.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'lib/my-addon/app/routes/foo/bar.js', + contains: "export { default } from 'my-addon/routes/foo/bar';" + }, + { + file: 'lib/my-addon/addon/templates/foo/bar.hbs', + contains: '{{outlet}}' + }, + { + file: 'lib/my-addon/app/templates/foo/bar.js', + contains: "export { default } from 'my-addon/templates/foo/bar';" + }, + { + file: 'tests/unit/routes/foo/bar-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo/bar'" + ] + } + ] + }); + }); + +/** +* Pod tests +* +*/ + + it('in-addon route foo --pod', function() { + return generateAndDestroy(['route', 'foo', '--pod'], { + target: 'addon', + files: [ + { + file: 'addon/foo/route.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'addon/foo/template.hbs', + contains: "{{outlet}}" + }, + { + file: 'app/foo/route.js', + contains: [ + "export { default } from 'my-addon/foo/route';" + ] + }, + { + file: 'app/foo/template.js', + contains: [ + "export { default } from 'my-addon/foo/template';" + ] + }, + { + file: 'tests/unit/foo/route-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo'" + ] + } + ] + }); + }); + + + it('route foo --pod', function() { + var files = [ + { + file: 'app/router.js', + contains: 'this.route(\'foo\')' + }, + { + file: 'app/foo/route.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'app/foo/template.hbs', + contains: '{{outlet}}' + }, + { + file: 'tests/unit/foo/route-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo'" + ] + } + ]; + + return generateAndDestroy(['route', 'foo', '--pod'], { + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('route foo --pod with --path', function() { + var files = [ + { + file: 'app/router.js', + contains: [ + 'this.route(\'foo\', {', + 'path: \':foo_id/show\'', + '});' + ] + } + ]; + + return generateAndDestroy(['route', 'foo', '--pod', '--path=:foo_id/show'], { + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + + it('route foo --pod podModulePrefix', function() { + var files = [ + { + file: 'app/router.js', + contains: 'this.route(\'foo\')' + }, + { + file: 'app/pods/foo/route.js', + contains: [ + "import Ember from 'ember';", + "export default Ember.Route.extend({\n});" + ] + }, + { + file: 'app/pods/foo/template.hbs', + contains: '{{outlet}}' + }, + { + file: 'tests/unit/pods/foo/route-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo'" + ] + } + ]; + + return generateAndDestroy(['route', 'foo', '--pod'], { + podModulePrefix: true, + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('route index --pod', function() { + var files = [ + { + file: 'app/router.js', + doesNotContain: "this.route('index');" + } + ]; + + return generateAndDestroy(['route', 'index', '--pod'], { + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('route application --pod', function() { + return generateAndDestroy(['route', 'foo'], { + afterGenerate: function(){ + return remove(path.join('app', 'templates', 'application.hbs')) + .then(function() { + var files = [ + { + file: 'app/router.js', + doesNotContain: "this.route('application');" + } + ]; + + return generateAndDestroy(['route', 'application', '--pod'], { + skipInit: true, + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + } + }); + }); + + it('route basic --pod isn\'t added to router', function() { + var files = [ + { + file: 'app/router.js', + doesNotContain: "this.route('basic');" + }, + { + file: 'app/basic/route.js' + } + ]; + + return generateAndDestroy(['route', 'basic', '--pod'], { + afterDestroy: function() { + // remove `app/router.js` to work around https://github.com/ember-cli/ember-cli-blueprint-test-helpers/issues/38 + files.shift(); + }, + files: files, + }); + }); + + it('route-test foo', function() { + return generateAndDestroy(['route-test', 'foo'], { + files: [ + { + file: 'tests/unit/routes/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo'" + ] + } + ] + }); + }); + + it('in-addon route-test foo', function() { + return generateAndDestroy(['route-test', 'foo'], { + target: 'addon', + files: [ + { + file: 'tests/unit/routes/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo'" + ] + }, + { + file: 'app/route-test/foo.js', + exists: false + } + ] + }); + }); + + + it('dummy route-test foo', function() { + return generateAndDestroy(['route-test', 'foo'], { + target: 'addon', + files: [ + { + file: 'tests/unit/routes/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('route:foo'" + ] + }, + { + file: 'app/route-test/foo.js', + exists: false + } + ] + }); + }); + + it('route-test foo for mocha', function() { + return generateAndDestroy(['route-test', 'foo'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/unit/routes/foo-test.js', + contains: [ + "import { describeModule, it } from 'ember-mocha';", + "describeModule('route:foo', 'Unit | Route | foo'" + ] + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/service-test.js b/node-tests/blueprints/service-test.js new file mode 100644 index 00000000000..d5fbe0de47e --- /dev/null +++ b/node-tests/blueprints/service-test.js @@ -0,0 +1,247 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy service', function() { + setupTestHooks(this); + + it('service foo', function() { + return generateAndDestroy(['service', 'foo'], { + files: [ + { + file: 'app/services/foo.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Service.extend({\n});' + ] + }, + { + file: 'tests/unit/services/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('service:foo'" + ] + } + ] + }); + }); + + it('service foo/bar', function() { + return generateAndDestroy(['service', 'foo/bar'], { + files: [ + { + file: 'app/services/foo/bar.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Service.extend({\n});' + ] + }, + { + file: 'tests/unit/services/foo/bar-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('service:foo/bar'" + ] + } + ] + }); + }); + it('in-addon service foo', function() { + return generateAndDestroy(['service', 'foo'], { + target: 'addon', + files: [ + { + file: 'addon/services/foo.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Service.extend({\n});' + ] + }, + { + file: 'app/services/foo.js', + contains: [ + "export { default } from 'my-addon/services/foo';" + ] + }, + { + file: 'tests/unit/services/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('service:foo'" + ] + } + ] + }); + }); + + it('in-addon service foo/bar', function() { + return generateAndDestroy(['service', 'foo/bar'], { + target: 'addon', + files: [ + { + file: 'addon/services/foo/bar.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Service.extend({\n});' + ] + }, + { + file: 'app/services/foo/bar.js', + contains: [ + "export { default } from 'my-addon/services/foo/bar';" + ] + }, + { + file: 'tests/unit/services/foo/bar-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('service:foo/bar'" + ] + } + ] + }); + }); +/** +* Pod tests +* +*/ + + it('service foo --pod', function() { + return generateAndDestroy(['service', 'foo', '--pod'], { + files: [ + { + file: 'app/foo/service.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Service.extend({\n});' + ] + }, + { + file: 'tests/unit/foo/service-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('service:foo'" + ] + } + ] + }); + }); + + it('service foo/bar --pod', function() { + return generateAndDestroy(['service', 'foo/bar', '--pod'], { + files: [ + { + file: 'app/foo/bar/service.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Service.extend({\n});' + ] + }, + { + file: 'tests/unit/foo/bar/service-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('service:foo/bar'" + ] + } + ] + }); + }); + + it('service foo --pod podModulePrefix', function() { + return generateAndDestroy(['service', 'foo', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/foo/service.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Service.extend({\n});' + ] + }, + { + file: 'tests/unit/pods/foo/service-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('service:foo'" + ] + } + ] + }); + }); + + it('service foo/bar --pod podModulePrefix', function() { + return generateAndDestroy(['service', 'foo/bar', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/pods/foo/bar/service.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Service.extend({\n});' + ] + }, + { + file: 'tests/unit/pods/foo/bar/service-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('service:foo/bar'" + ] + } + ] + }); + }); + + it('service-test foo', function() { + return generateAndDestroy(['service-test', 'foo'], { + files: [ + { + file: 'tests/unit/services/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('service:foo'" + ] + } + ] + }); + }); + + it('in-addon service-test foo', function() { + return generateAndDestroy(['service-test', 'foo'], { + target: 'addon', + files: [ + { + file: 'tests/unit/services/foo-test.js', + contains: [ + "import { moduleFor, test } from 'ember-qunit';", + "moduleFor('service:foo'" + ] + }, + { + file: 'app/service-test/foo.js', + exists: false + } + ] + }); + }); + + it('service-test foo for mocha', function() { + return generateAndDestroy(['service-test', 'foo'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/unit/services/foo-test.js', + contains: [ + "import { describeModule, it } from 'ember-mocha';", + "describeModule('service:foo', 'Unit | Service | foo'" + ] + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/template-test.js b/node-tests/blueprints/template-test.js new file mode 100644 index 00000000000..3109bd2ee17 --- /dev/null +++ b/node-tests/blueprints/template-test.js @@ -0,0 +1,118 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy template', function() { + setupTestHooks(this); + + it('template foo', function() { + return generateAndDestroy(['template', 'foo'], { + files: [ + { file: 'app/templates/foo.hbs', isEmpty: true } + ] + }); + }); + + it('template foo/bar', function() { + return generateAndDestroy(['template', 'foo/bar'], { + files: [ + { file: 'app/templates/foo/bar.hbs', isEmpty: true } + ] + }); + }); + + it('template foo --pod', function() { + return generateAndDestroy(['template', 'foo'], { + usePods: true, + files: [ + { file: 'app/foo/template.hbs', isEmpty: true } + ] + }); + }); + + it('template foo/bar --pod', function() { + return generateAndDestroy(['template', 'foo/bar'], { + usePods: true, + files: [ + { file: 'app/foo/bar/template.hbs', isEmpty: true } + ] + }); + }); + + it('template foo --pod podModulePrefix', function() { + return generateAndDestroy(['template', 'foo'], { + usePods: true, + podModulePrefix: true, + files: [ + { file: 'app/pods/foo/template.hbs', isEmpty: true } + ] + }); + }); + + it('template foo/bar --pod podModulePrefix', function() { + return generateAndDestroy(['template', 'foo/bar'], { + usePods: true, + podModulePrefix: true, + files: [ + { file: 'app/pods/foo/bar/template.hbs', isEmpty: true } + ] + }); + }); + + it('in-addon template foo', function() { + return generateAndDestroy(['template', 'foo'], { + target: 'addon', + files: [ + { file: 'addon/templates/foo.hbs', isEmpty: true } + ] + }); + }); + + it('in-addon template foo/bar', function() { + return generateAndDestroy(['template', 'foo/bar'], { + target: 'addon', + files: [ + { file: 'addon/templates/foo/bar.hbs', isEmpty: true } + ] + }); + }); + + it('dummy template foo', function() { + return generateAndDestroy(['template', 'foo', '--dummy'], { + target: 'addon', + files: [ + { file: 'tests/dummy/app/templates/foo.hbs', isEmpty: true } + ] + }); + }); + + it('dummy template foo/bar', function() { + return generateAndDestroy(['template', 'foo/bar', '--dummy'], { + target: 'addon', + files: [ + { file: 'tests/dummy/app/templates/foo/bar.hbs', isEmpty: true } + ] + }); + }); + + it('in-repo-addon template foo', function() { + return generateAndDestroy(['template', 'foo', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { file: 'lib/my-addon/addon/templates/foo.hbs', isEmpty: true } + ] + }); + }); + + it('in-repo-addon template foo/bar', function() { + return generateAndDestroy(['template', 'foo/bar', '--in-repo-addon=my-addon'], { + target: 'inRepoAddon', + files: [ + { file: 'lib/my-addon/addon/templates/foo/bar.hbs', isEmpty: true } + ] + }); + }); + +}); diff --git a/node-tests/blueprints/test-helper-test.js b/node-tests/blueprints/test-helper-test.js new file mode 100644 index 00000000000..83186422031 --- /dev/null +++ b/node-tests/blueprints/test-helper-test.js @@ -0,0 +1,23 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy test-helper', function() { + setupTestHooks(this); + + it('test-helper foo', function() { + return generateAndDestroy(['test-helper', 'foo'], { + files: [ + { + file: 'tests/helpers/foo.js', + contains: [ + "import Ember from 'ember';", + 'export default Ember.Test.registerAsyncHelper(\'foo\', function(app) {\n\n}' + ] + } + ] + }); + }); +}); diff --git a/node-tests/blueprints/util-test.js b/node-tests/blueprints/util-test.js new file mode 100644 index 00000000000..422ee9e3798 --- /dev/null +++ b/node-tests/blueprints/util-test.js @@ -0,0 +1,207 @@ +'use strict'; + +var setupTestHooks = require('ember-cli-blueprint-test-helpers/lib/helpers/setup'); +var BlueprintHelpers = require('ember-cli-blueprint-test-helpers/lib/helpers/blueprint-helper'); +var generateAndDestroy = BlueprintHelpers.generateAndDestroy; + +describe('Acceptance: ember generate and destroy util', function() { + setupTestHooks(this); + + it('util foo-bar', function() { + return generateAndDestroy(['util', 'foo-bar'], { + files: [ + { + file: 'app/utils/foo-bar.js', + contains: 'export default function fooBar() {\n' + + ' return true;\n' + + '}' + }, + { + file: 'tests/unit/utils/foo-bar-test.js', + contains: [ + "import fooBar from 'my-app/utils/foo-bar';" + ] + } + ] + }); + }); + + it('util foo-bar/baz', function() { + return generateAndDestroy(['util', 'foo/bar-baz'], { + files: [ + { + file: 'app/utils/foo/bar-baz.js', + contains: 'export default function fooBarBaz() {\n' + + ' return true;\n' + + '}' + }, + { + file: 'tests/unit/utils/foo/bar-baz-test.js', + contains: [ + "import fooBarBaz from 'my-app/utils/foo/bar-baz';" + ] + } + ] + }); + }); + + it('in-addon util foo-bar', function() { + return generateAndDestroy(['util', 'foo-bar'], { + target: 'addon', + files: [ + { + file: 'addon/utils/foo-bar.js', + contains: 'export default function fooBar() {\n' + + ' return true;\n' + + '}' + }, + { + file: 'app/utils/foo-bar.js', + contains: [ + "export { default } from 'my-addon/utils/foo-bar';" + ] + }, + { + file: 'tests/unit/utils/foo-bar-test.js', + contains: [ + "import fooBar from 'dummy/utils/foo-bar';" + ] + } + ] + }); + }); + + it('in-addon util foo-bar/baz', function() { + return generateAndDestroy(['util', 'foo/bar-baz'], { + target: 'addon', + files: [ + { + file: 'addon/utils/foo/bar-baz.js', + contains: 'export default function fooBarBaz() {\n' + + ' return true;\n' + + '}' + }, + { + file: 'app/utils/foo/bar-baz.js', + contains: [ + "export { default } from 'my-addon/utils/foo/bar-baz';" + ] + }, + { + file: 'tests/unit/utils/foo/bar-baz-test.js', + contains: [ + "import fooBarBaz from 'dummy/utils/foo/bar-baz';" + ] + } + ] + }); + }); +/** +* Pod tests +* +*/ + + it('util foo-bar --pod', function() { + return generateAndDestroy(['util', 'foo-bar', '--pod'], { + files: [ + { + file: 'app/utils/foo-bar.js', + contains: 'export default function fooBar() {\n' + + ' return true;\n' + + '}' + }, + { + file: 'tests/unit/utils/foo-bar-test.js', + contains: [ + "import fooBar from 'my-app/utils/foo-bar';" + ] + } + ] + }); + }); + + it('util foo-bar --pod podModulePrefix', function() { + return generateAndDestroy(['util', 'foo-bar', '--pod'], { + podModulePrefix: true, + files: [ + { + file: 'app/utils/foo-bar.js', + contains: 'export default function fooBar() {\n' + + ' return true;\n' + + '}' + }, + { + file: 'tests/unit/utils/foo-bar-test.js', + contains: [ + "import fooBar from 'my-app/utils/foo-bar';" + ] + } + ] + }); + }); + + it('util foo-bar/baz --pod', function() { + return generateAndDestroy(['util', 'foo/bar-baz', '--pod'], { + files: [ + { + file: 'app/utils/foo/bar-baz.js', + contains: 'export default function fooBarBaz() {\n' + + ' return true;\n' + + '}' + }, + { + file: 'tests/unit/utils/foo/bar-baz-test.js', + contains: [ + "import fooBarBaz from 'my-app/utils/foo/bar-baz';" + ] + } + ] + }); + }); + + it('util-test foo-bar', function() { + return generateAndDestroy(['util-test', 'foo-bar'], { + files: [ + { + file: 'tests/unit/utils/foo-bar-test.js', + contains: [ + "import fooBar from 'my-app/utils/foo-bar';" + ] + } + ] + }); + }); + + it('in-addon util-test foo-bar', function() { + return generateAndDestroy(['util-test', 'foo-bar'], { + target: 'addon', + files: [ + { + file: 'tests/unit/utils/foo-bar-test.js', + contains: [ + "import fooBar from 'dummy/utils/foo-bar';" + ] + } + ] + }); + }); + + it('util-test foo-bar for mocha', function() { + return generateAndDestroy(['util-test', 'foo-bar'], { + packages: [ + { name: 'ember-cli-qunit', delete: true }, + { name: 'ember-cli-mocha', dev: true } + ], + files: [ + { + file: 'tests/unit/utils/foo-bar-test.js', + contains: [ + "import { describe, it } from 'mocha';", + "import fooBar from 'my-app/utils/foo-bar';", + "describe('Unit | Utility | foo bar', function() {" + ] + } + ] + }); + }); +}); diff --git a/node-tests/fixtures/addon/package/package.json b/node-tests/fixtures/addon/package/package.json new file mode 100644 index 00000000000..bef04646b4b --- /dev/null +++ b/node-tests/fixtures/addon/package/package.json @@ -0,0 +1,22 @@ +{ + "name": "my-addon", + "version": "0.0.0", + "description": "Addon fixture package for ember-cli-blueprint-test-helpers", + "engines": { + "node": ">= 0.10.0" + }, + "devDependencies": { + "ember-cli": "*", + "ember": "*" + }, + "keywords": [ + "ember-addon" + ], + "dependencies": { + "ember-cli-htmlbars": "*", + "ember-cli-babel": "*" + }, + "ember-addon": { + "configPath": "tests/dummy/config" + } +} diff --git a/node-tests/fixtures/app/package/package.json b/node-tests/fixtures/app/package/package.json new file mode 100644 index 00000000000..0039eae9d41 --- /dev/null +++ b/node-tests/fixtures/app/package/package.json @@ -0,0 +1,13 @@ +{ + "name": "my-app", + "version": "0.0.0", + "description": "App fixture package for ember-cli-blueprint-test-helpers", + "private": true, + "engines": { + "node": ">= 0.10.0" + }, + "devDependencies": { + "ember-cli": "*", + "ember": "*" + } +} diff --git a/node-tests/nodetest-runner.js b/node-tests/nodetest-runner.js new file mode 100644 index 00000000000..db5defd637b --- /dev/null +++ b/node-tests/nodetest-runner.js @@ -0,0 +1,74 @@ +'use strict'; + +var glob = require('glob'); +var Mocha = require('mocha'); +var RSVP = require('rsvp'); +var rimraf = require('rimraf'); +var mochaOnlyDetector = require('mocha-only-detector'); + +if (process.env.EOLNEWLINE) { + require('os').EOL = '\n'; +} + +rimraf.sync('.node_modules-tmp'); +rimraf.sync('.bower_components-tmp'); + +var root = 'node-tests/{blueprints,acceptance,unit}'; +var _checkOnlyInTests = RSVP.denodeify(mochaOnlyDetector.checkFolder.bind(null, root + '/**/*{-test}.js')); +var optionOrFile = process.argv[2]; +var mocha = new Mocha({ + timeout: 5000, + reporter: 'spec' +}); +var testFiles = glob.sync(root + '/**/*-test.js'); +/*var jshintPosition = testFiles.indexOf('tests/unit/jshint-test.js'); +var jshint = testFiles.splice(jshintPosition, 1); + +testFiles = jshint.concat(testFiles); +*/ +if (optionOrFile === 'all') { + addFiles(mocha, testFiles); + addFiles(mocha, 'node-tests/**/*-test.js'); + addFiles(mocha, '/**/*-test-slow.js'); +} else if (process.argv.length > 2) { + addFiles(mocha, process.argv.slice(2)); +} else { + addFiles(mocha, testFiles); +} + +function addFiles(mocha, files) { + files = (typeof files === 'string') ? glob.sync(root + files) : files; + files.forEach(mocha.addFile.bind(mocha)); +} + +function checkOnlyInTests() { + console.log('Verifing `.only` in tests'); + return _checkOnlyInTests().then(function() { + console.log('No `.only` found'); + }); +} + +function runMocha() { + mocha.run(function(failures) { + process.on('exit', function() { + process.exit(failures); + }); + }); +} + +function ciVerificationStep() { + if (process.env.CI === 'true') { + return checkOnlyInTests(); + } else { + return RSVP.Promise.resolve(); + } +} + +ciVerificationStep() + .then(function() { + runMocha(); + }) + .catch(function(error) { + console.error(error); + process.exit(1); + }); diff --git a/package.json b/package.json index 33e868174ef..b62e5992999 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "test": "bin/run-tests.js", "test:sauce": "bin/run-sauce-tests.js", "test:testem": "testem -f testem.dist.json", + "test:blueprints": "node node-tests/nodetest-runner.js", "start": "ember serve", "docs": "ember ember-cli-yuidoc", "sauce:launch": "ember sauce:launch" @@ -27,7 +28,9 @@ "broccoli-stew": "^1.2.0", "chalk": "^0.5.1", "ember-cli": "^2.2.0-beta.2", + "ember-cli-blueprint-test-helpers": "^0.9.0", "ember-cli-dependency-checker": "^1.2.0", + "ember-cli-internal-test-helpers": "^0.7.0", "ember-cli-sauce": "^1.4.2", "ember-cli-yuidoc": "0.7.0", "ember-publisher": "0.0.7", @@ -36,14 +39,25 @@ "finalhandler": "^0.4.0", "github": "^0.2.3", "glimmer-engine": "tildeio/glimmer#d6ae47a", - "glob": "~4.3.2", + "glob": "^5.0.13", "htmlbars": "0.14.14", + "mocha": "^2.4.5", + "mocha-only-detector": "0.0.2", "qunit-extras": "^1.4.0", "qunitjs": "^1.20.0", + "rimraf": "^2.5.2", "route-recognizer": "0.1.5", "rsvp": "~3.1.0", "serve-static": "^1.10.0", "simple-dom": "^0.2.7", "testem": "^1.0.0-rc.3" + }, + "dependencies": { + "ember-cli-get-component-path-option": "^1.0.0", + "ember-cli-normalize-entity-name": "^1.0.0", + "ember-cli-path-utils": "^1.0.0", + "ember-cli-string-utils": "^1.0.0", + "ember-cli-test-info": "^1.0.0", + "ember-cli-valid-component-name": "^1.0.0" } }