diff --git a/blueprints/component/index.js b/blueprints/component/index.js index ebbcafa0961..bb42b9590cc 100644 --- a/blueprints/component/index.js +++ b/blueprints/component/index.js @@ -5,10 +5,11 @@ const stringUtil = require('ember-cli-string-utils'); const pathUtil = require('ember-cli-path-utils'); const getPathOption = require('ember-cli-get-component-path-option'); const normalizeEntityName = require('ember-cli-normalize-entity-name'); +const useEditionDetector = require('../edition-detector'); const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject; const EOL = require('os').EOL; -module.exports = { +module.exports = useEditionDetector({ description: 'Generates a component.', availableOptions: [ @@ -101,4 +102,4 @@ module.exports = { path: getPathOption(options), }; }, -}; +}); diff --git a/blueprints/component/native-files/__root__/__path__/__name__.js b/blueprints/component/native-files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..d82d8fe8e59 --- /dev/null +++ b/blueprints/component/native-files/__root__/__path__/__name__.js @@ -0,0 +1,4 @@ +import Component from '@ember/component'; +<%= importTemplate %> +export default class <%= classifiedModuleName %>Component extends Component {<%= contents %> +} diff --git a/blueprints/component/native-files/__root__/__templatepath__/__templatename__.hbs b/blueprints/component/native-files/__root__/__templatepath__/__templatename__.hbs new file mode 100644 index 00000000000..fb5c4b157d1 --- /dev/null +++ b/blueprints/component/native-files/__root__/__templatepath__/__templatename__.hbs @@ -0,0 +1 @@ +{{yield}} \ No newline at end of file diff --git a/blueprints/controller/index.js b/blueprints/controller/index.js index 4cdd3d92796..2df4701533a 100644 --- a/blueprints/controller/index.js +++ b/blueprints/controller/index.js @@ -1,9 +1,10 @@ 'use strict'; +const useEditionDetector = require('../edition-detector'); const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject; const path = require('path'); -module.exports = { +module.exports = useEditionDetector({ description: 'Generates a controller.', fileMapTokens() { if (isModuleUnificationProject(this.project)) { @@ -26,4 +27,4 @@ module.exports = { }; } }, -}; +}); diff --git a/blueprints/controller/native-files/__root__/__path__/__name__.js b/blueprints/controller/native-files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..91414ad3759 --- /dev/null +++ b/blueprints/controller/native-files/__root__/__path__/__name__.js @@ -0,0 +1,4 @@ +import Controller from '@ember/controller'; + +export default class <%= classifiedModuleName %>Controller extends Controller { +}; diff --git a/blueprints/edition-detector.js b/blueprints/edition-detector.js new file mode 100644 index 00000000000..9c62029c700 --- /dev/null +++ b/blueprints/edition-detector.js @@ -0,0 +1,12 @@ +'use strict'; + +const path = require('path'); + +module.exports = function(blueprint) { + blueprint.filesPath = function() { + let rootPath = process.env.EMBER_VERSION === 'OCTANE' ? 'native-files' : 'files'; + return path.join(this.path, rootPath); + }; + + return blueprint; +}; diff --git a/blueprints/route/index.js b/blueprints/route/index.js index 8b85b17c81a..89f10f88c4d 100644 --- a/blueprints/route/index.js +++ b/blueprints/route/index.js @@ -5,9 +5,10 @@ const path = require('path'); const chalk = require('chalk'); const stringUtil = require('ember-cli-string-utils'); const EmberRouterGenerator = require('ember-router-generator'); +const useEditionDetector = require('../edition-detector'); const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject; -module.exports = { +module.exports = useEditionDetector({ description: 'Generates a route and a template, and registers the route with the router.', availableOptions: [ @@ -139,7 +140,7 @@ module.exports = { afterUninstall: function(options) { updateRouter.call(this, 'remove', options); }, -}; +}); function updateRouter(action, options) { let entity = options.entity; diff --git a/blueprints/route/native-files/__root__/__path__/__name__.js b/blueprints/route/native-files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..508c4dbe00c --- /dev/null +++ b/blueprints/route/native-files/__root__/__path__/__name__.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class <%= classifiedModuleName %>Route extends Route { +} diff --git a/blueprints/route/native-files/__root__/__templatepath__/__templatename__.hbs b/blueprints/route/native-files/__root__/__templatepath__/__templatename__.hbs new file mode 100644 index 00000000000..e2147cab02d --- /dev/null +++ b/blueprints/route/native-files/__root__/__templatepath__/__templatename__.hbs @@ -0,0 +1 @@ +{{outlet}} \ No newline at end of file diff --git a/blueprints/service/index.js b/blueprints/service/index.js index d9b5b4eb237..6abf9519577 100644 --- a/blueprints/service/index.js +++ b/blueprints/service/index.js @@ -1,8 +1,9 @@ 'use strict'; +const useEditionDetector = require('../edition-detector'); const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject; -module.exports = { +module.exports = useEditionDetector({ description: 'Generates a service.', fileMapTokens() { @@ -18,4 +19,4 @@ module.exports = { }; } }, -}; +}); diff --git a/blueprints/service/native-files/__root__/__path__/__name__.js b/blueprints/service/native-files/__root__/__path__/__name__.js new file mode 100644 index 00000000000..c79f7d69641 --- /dev/null +++ b/blueprints/service/native-files/__root__/__path__/__name__.js @@ -0,0 +1,4 @@ +import Service from '@ember/service'; + +export default class <%= classifiedModuleName %>Service extends Service { +} diff --git a/node-tests/blueprints/component-test.js b/node-tests/blueprints/component-test.js index 4de61e474db..22a4d7223e9 100644 --- a/node-tests/blueprints/component-test.js +++ b/node-tests/blueprints/component-test.js @@ -12,6 +12,7 @@ const expect = chai.expect; const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest'); const enableModuleUnification = require('../helpers/module-unification').enableModuleUnification; +const enableOctane = require('../helpers/setup-test-environment').enableOctane; const fixture = require('../helpers/fixture'); describe('Blueprint: component', function() { @@ -489,6 +490,75 @@ describe('Blueprint: component', function() { }); }); + describe('in app - octane', function() { + enableOctane(); + + beforeEach(function() { + return emberNew() + .then(() => + modifyPackages([ + { name: 'ember-qunit', delete: true }, + { name: 'ember-cli-qunit', dev: true }, + ]) + ) + .then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0')); + }); + + it('component foo', function() { + return emberGenerateDestroy(['component', 'foo'], _file => { + expect(_file('src/ui/components/foo/component.js')).to.equal( + fixture('component/native-component.js') + ); + + expect(_file('src/ui/components/foo/template.hbs')).to.equal('{{yield}}'); + + expect(_file('src/ui/components/foo/component-test.js')).to.equal( + fixture('component-test/default-template.js', { + replace: { + component: 'foo', + }, + }) + ); + }); + }); + + it('component x-foo', function() { + return emberGenerateDestroy(['component', 'x-foo'], _file => { + expect(_file('src/ui/components/x-foo/component.js')).to.equal( + fixture('component/native-component-dash.js') + ); + + expect(_file('src/ui/components/x-foo/template.hbs')).to.equal('{{yield}}'); + + expect(_file('src/ui/components/x-foo/component-test.js')).to.equal( + fixture('component-test/default-template.js', { + replace: { + component: 'x-foo', + }, + }) + ); + }); + }); + + it('component foo/x-foo', function() { + return emberGenerateDestroy(['component', 'foo/x-foo'], _file => { + expect(_file('src/ui/components/foo/x-foo/component.js')).to.equal( + fixture('component/native-component-nested.js') + ); + + expect(_file('src/ui/components/foo/x-foo/template.hbs')).to.equal('{{yield}}'); + + expect(_file('src/ui/components/foo/x-foo/component-test.js')).to.equal( + fixture('component-test/default-template.js', { + replace: { + component: 'foo/x-foo', + }, + }) + ); + }); + }); + }); + describe('in addon', function() { beforeEach(function() { return emberNew({ target: 'addon' }) @@ -716,6 +786,106 @@ describe('Blueprint: component', function() { }); }); + describe('in addon - octane', function() { + enableOctane(); + + beforeEach(function() { + return emberNew({ target: 'addon' }) + .then(() => + modifyPackages([ + { name: 'ember-qunit', delete: true }, + { name: 'ember-cli-qunit', dev: true }, + ]) + ) + .then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0')); + }); + + it('component foo', function() { + return emberGenerateDestroy(['component', 'foo'], _file => { + expect(_file('src/ui/components/foo/component.js')).to.equal( + fixture('component/native-component.js') + ); + + expect(_file('src/ui/components/foo/template.hbs')).to.equal('{{yield}}'); + + expect(_file('src/ui/components/foo/component-test.js')).to.equal( + fixture('component-test/default-template.js', { + replace: { + component: 'foo', + path: 'my-addon::', + }, + }) + ); + }); + }); + + it('component x-foo', function() { + return emberGenerateDestroy(['component', 'x-foo'], _file => { + expect(_file('src/ui/components/x-foo/component.js')).to.equal( + fixture('component/native-component-dash.js') + ); + + expect(_file('src/ui/components/x-foo/template.hbs')).to.equal('{{yield}}'); + + expect(_file('src/ui/components/x-foo/component-test.js')).to.equal( + fixture('component-test/default-template.js', { + replace: { + component: 'x-foo', + path: 'my-addon::', + }, + }) + ); + }); + }); + + it('component foo/x-foo', function() { + return emberGenerateDestroy(['component', 'foo/x-foo'], _file => { + expect(_file('src/ui/components/foo/x-foo/component.js')).to.equal( + fixture('component/native-component-nested.js') + ); + + expect(_file('src/ui/components/foo/x-foo/template.hbs')).to.equal('{{yield}}'); + + expect(_file('src/ui/components/foo/x-foo/component-test.js')).to.equal( + fixture('component-test/default-template.js', { + replace: { + component: 'foo/x-foo', + path: 'my-addon::', + }, + }) + ); + }); + }); + + it('component x-foo --dummy', function() { + return emberGenerateDestroy(['component', 'x-foo', '--dummy'], _file => { + expect(_file('tests/dummy/src/ui/components/x-foo/component.js')).to.equal( + fixture('component/native-component-dash.js') + ); + + expect(_file('tests/dummy/src/ui/components/x-foo/template.hbs')).to.equal('{{yield}}'); + + expect(_file('src/ui/components/x-foo/component.js')).to.not.exist; + + expect(_file('src/ui/components/x-foo/component-test.js')).to.not.exist; + }); + }); + + it('component foo/x-foo --dummy', function() { + return emberGenerateDestroy(['component', 'foo/x-foo', '--dummy'], _file => { + expect(_file('tests/dummy/src/ui/components/foo/x-foo/component.js')).to.equal( + fixture('component/native-component-nested.js') + ); + + expect(_file('tests/dummy/src/ui/components/foo/x-foo/template.hbs')).to.equal('{{yield}}'); + + expect(_file('src/ui/components/foo/x-foo/component.js')).to.not.exist; + + expect(_file('src/ui/components/foo/x-foo/component-test.js')).to.not.exist; + }); + }); + }); + describe('in in-repo-addon', function() { beforeEach(function() { return emberNew({ target: 'in-repo-addon' }) @@ -903,4 +1073,59 @@ describe('Blueprint: component', function() { }); }); }); + + describe('in in-repo-addon - octane', function() { + enableOctane(); + + beforeEach(function() { + return emberNew({ target: 'in-repo-addon' }) + .then(() => + modifyPackages([ + { name: 'ember-qunit', delete: true }, + { name: 'ember-cli-qunit', dev: true }, + ]) + ) + .then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0')); + }); + + it('component foo --in-repo-addon=my-addon', function() { + return emberGenerateDestroy(['component', 'foo', '--in-repo-addon=my-addon'], _file => { + expect(_file('packages/my-addon/src/ui/components/foo/component.js')).to.equal( + fixture('component/native-component.js') + ); + + expect(_file('packages/my-addon/src/ui/components/foo/template.hbs')).to.equal('{{yield}}'); + + expect(_file('packages/my-addon/src/ui/components/foo/component-test.js')).to.equal( + fixture('component-test/default-template.js', { + replace: { + component: 'foo', + path: 'my-addon::', + }, + }) + ); + }); + }); + + it('component x-foo --in-repo-addon=my-addon', function() { + return emberGenerateDestroy(['component', 'x-foo', '--in-repo-addon=my-addon'], _file => { + expect(_file('packages/my-addon/src/ui/components/x-foo/component.js')).to.equal( + fixture('component/native-component-dash.js') + ); + + expect(_file('packages/my-addon/src/ui/components/x-foo/template.hbs')).to.equal( + '{{yield}}' + ); + + expect(_file('packages/my-addon/src/ui/components/x-foo/component-test.js')).to.equal( + fixture('component-test/default-template.js', { + replace: { + component: 'x-foo', + path: 'my-addon::', + }, + }) + ); + }); + }); + }); }); diff --git a/node-tests/blueprints/controller-test.js b/node-tests/blueprints/controller-test.js index 028eacf5948..bc4e5e586ac 100644 --- a/node-tests/blueprints/controller-test.js +++ b/node-tests/blueprints/controller-test.js @@ -13,6 +13,7 @@ const expect = chai.expect; const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest'); const enableModuleUnification = require('../helpers/module-unification').enableModuleUnification; +const enableOctane = require('../helpers/setup-test-environment').enableOctane; const fixture = require('../helpers/fixture'); describe('Blueprint: controller', function() { @@ -302,6 +303,138 @@ describe('Blueprint: controller', function() { }); }); + describe('in app - octane', function() { + enableOctane(); + + beforeEach(function() { + return emberNew() + .then(() => + modifyPackages([ + { name: 'ember-qunit', delete: true }, + { name: 'ember-cli-qunit', dev: true }, + ]) + ) + .then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0')); + }); + + it('controller foo', function() { + return emberGenerateDestroy(['controller', 'foo'], _file => { + expect(_file('src/ui/routes/foo/controller.js')).to.equal( + fixture('controller/native-controller.js') + ); + + expect(_file('src/ui/routes/foo/controller-test.js')).to.equal( + fixture('controller-test/default.js') + ); + }); + }); + + it('controller foo/bar', function() { + return emberGenerateDestroy(['controller', 'foo/bar'], _file => { + expect(_file('src/ui/routes/foo/bar/controller.js')).to.equal( + fixture('controller/native-controller-nested.js') + ); + + expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.equal( + fixture('controller-test/default-nested.js') + ); + }); + }); + + describe('with podModulePrefix', function() { + beforeEach(function() { + setupPodConfig({ podModulePrefix: true }); + }); + + it('controller foo --pod podModulePrefix', function() { + return expectError( + emberGenerateDestroy(['controller', 'foo', '--pod']), + "Pods aren't supported within a module unification app" + ); + }); + }); + }); + + describe('in addon - octane', function() { + enableOctane(); + + beforeEach(function() { + return emberNew({ target: 'addon' }) + .then(() => + modifyPackages([ + { name: 'ember-qunit', delete: true }, + { name: 'ember-cli-qunit', dev: true }, + ]) + ) + .then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0')); + }); + + it('controller foo', function() { + return emberGenerateDestroy(['controller', 'foo'], _file => { + expect(_file('src/ui/routes/foo/controller.js')).to.equal( + fixture('controller/native-controller.js') + ); + + expect(_file('src/ui/routes/foo/controller-test.js')).to.equal( + fixture('controller-test/default.js') + ); + + expect(_file('app/controllers/foo.js')).to.not.exist; + }); + }); + + it('controller foo/bar', function() { + return emberGenerateDestroy(['controller', 'foo/bar'], _file => { + expect(_file('src/ui/routes/foo/bar/controller.js')).to.equal( + fixture('controller/native-controller-nested.js') + ); + + expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.equal( + fixture('controller-test/default-nested.js') + ); + + expect(_file('app/controllers/foo/bar.js')).to.not.exist; + }); + }); + + it('controller foo --dummy', function() { + return emberGenerateDestroy(['controller', 'foo', '--dummy'], _file => { + expect(_file('tests/dummy/src/ui/routes/foo/controller.js')).to.equal( + fixture('controller/native-controller.js') + ); + + expect(_file('src/ui/routes/foo/controller.js')).to.not.exist; + + expect(_file('src/ui/routes/foo/controller-test.js')).to.not.exist; + }); + }); + + it('controller foo/bar --dummy', function() { + return emberGenerateDestroy(['controller', 'foo/bar', '--dummy'], _file => { + expect(_file('tests/dummy/src/ui/routes/foo/bar/controller.js')).to.equal( + fixture('controller/native-controller-nested.js') + ); + + expect(_file('src/ui/routes/foo/bar/controller.js')).to.not.exist; + + expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.not.exist; + }); + }); + + describe('with podModulePrefix', function() { + beforeEach(function() { + setupPodConfig({ podModulePrefix: true }); + }); + + it('controller foo --pod podModulePrefix', function() { + return expectError( + emberGenerateDestroy(['controller', 'foo', '--pod']), + "Pods aren't supported within a module unification app" + ); + }); + }); + }); + describe('in in-repo-addon', function() { beforeEach(function() { return emberNew({ target: 'in-repo-addon' }) diff --git a/node-tests/blueprints/route-test.js b/node-tests/blueprints/route-test.js index a3a914ae49b..f70ed8250f3 100644 --- a/node-tests/blueprints/route-test.js +++ b/node-tests/blueprints/route-test.js @@ -17,6 +17,7 @@ const fs = require('fs-extra'); const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest'); const enableModuleUnification = require('../helpers/module-unification').enableModuleUnification; +const enableOctane = require('../helpers/setup-test-environment').enableOctane; const fixture = require('../helpers/fixture'); describe('Blueprint: route', function() { @@ -581,6 +582,260 @@ describe('Blueprint: route', function() { }); }); + describe('in app - octane', function() { + enableOctane(); + + beforeEach(function() { + return emberNew() + .then(() => + modifyPackages([ + { name: 'ember-qunit', delete: true }, + { name: 'ember-cli-qunit', dev: true }, + ]) + ) + .then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0')); + }); + + it('route foo', function() { + return emberGenerateDestroy(['route', 'foo'], _file => { + expect(_file('src/ui/routes/foo/route.js')).to.equal(fixture('route/native-route.js')); + + expect(_file('src/ui/routes/foo/template.hbs')).to.equal('{{outlet}}'); + + expect(_file('src/ui/routes/foo/route-test.js')).to.equal(fixture('route-test/default.js')); + + expect(file('src/router.js')).to.contain("this.route('foo')"); + }).then(() => { + expect(file('src/router.js')).to.not.contain("this.route('foo')"); + }); + }); + + it('route foo --skip-router', function() { + return emberGenerateDestroy(['route', 'foo', '--skip-router'], _file => { + expect(_file('src/ui/routes/foo/route.js')).to.exist; + expect(_file('src/ui/routes/foo/template.hbs')).to.exist; + expect(_file('src/ui/routes/foo/route-test.js')).to.exist; + expect(file('src/router.js')).to.not.contain("this.route('foo')"); + }).then(() => { + expect(file('src/router.js')).to.not.contain("this.route('foo')"); + }); + }); + + it('route foo --path=:foo_id/show', function() { + return emberGenerateDestroy(['route', 'foo', '--path=:foo_id/show'], _file => { + expect(_file('src/ui/routes/foo/route.js')).to.equal(fixture('route/native-route.js')); + + expect(_file('src/ui/routes/foo/template.hbs')).to.equal('{{outlet}}'); + + expect(_file('src/ui/routes/foo/route-test.js')).to.equal(fixture('route-test/default.js')); + + expect(file('src/router.js')) + .to.contain("this.route('foo', {") + .to.contain("path: ':foo_id/show'") + .to.contain('});'); + }).then(() => { + expect(file('src/router.js')) + .to.not.contain("this.route('foo'") + .to.not.contain("path: ':foo_id/show'"); + }); + }); + + it('route parent/child --reset-namespace', function() { + return emberGenerateDestroy(['route', 'parent/child', '--reset-namespace'], _file => { + expect(_file('src/ui/routes/parent/child/route.js')).to.equal( + fixture('route/native-route-child.js') + ); + + expect(_file('src/ui/routes/parent/child/template.hbs')).to.equal('{{outlet}}'); + + expect(_file('src/ui/routes/parent/child/route-test.js')).to.equal( + fixture('route-test/default-child.js') + ); + + expect(file('src/router.js')) + .to.contain("this.route('parent', {") + .to.contain("this.route('child', {") + .to.contain('resetNamespace: true') + .to.contain('});'); + }); + }); + + it('route parent/child --reset-namespace --pod', function() { + return expectError( + emberGenerateDestroy(['route', 'parent/child', '--reset-namespace', '--pod']), + "Pods aren't supported within a module unification app" + ); + }); + + it('route index', function() { + return emberGenerateDestroy(['route', 'index'], _file => { + expect(_file('src/ui/routes/index/route.js')).to.exist; + expect(_file('src/ui/routes/index/template.hbs')).to.exist; + expect(_file('src/ui/routes/index/route-test.js')).to.exist; + expect(file('src/router.js')).to.not.contain("this.route('index')"); + }).then(() => { + expect(file('src/router.js')).to.not.contain("this.route('index')"); + }); + }); + + it('route application', function() { + fs.removeSync('src/ui/routes/application/template.hbs'); + return emberGenerate(['route', 'application']).then(() => { + expect(file('src/ui/routes/application/template.hbs')).to.exist; + expect(file('src/router.js')).to.not.contain("this.route('application')"); + }); + }); + + it('route basic', function() { + return emberGenerateDestroy(['route', 'basic'], _file => { + expect(_file('src/ui/routes/basic/route.js')).to.exist; + expect(file('src/router.js')).to.not.contain("this.route('basic')"); + }).then(() => { + expect(file('src/router.js')).to.not.contain("this.route('basic')"); + }); + }); + + it('route foo --pod', function() { + return expectError( + emberGenerateDestroy(['route', 'foo', '--pod']), + "Pods aren't supported within a module unification app" + ); + }); + + it('route foo --pod with --path', function() { + return expectError( + emberGenerateDestroy(['route', 'foo', '--pod', '--path=:foo_id/show']), + "Pods aren't supported within a module unification app" + ); + }); + + it('route index --pod', function() { + return expectError( + emberGenerate(['route', 'index', '--pod']), + "Pods aren't supported within a module unification app" + ); + }); + + it('route application --pod', function() { + return expectError( + emberGenerate(['route', 'application', '--pod']), + "Pods aren't supported within a module unification app" + ); + }); + + it('route basic --pod', function() { + return expectError( + emberGenerate(['route', 'basic', '--pod']), + "Pods aren't supported within a module unification app" + ); + }); + + describe('with podModulePrefix', function() { + beforeEach(function() { + setupPodConfig({ podModulePrefix: true }); + }); + + it('route foo --pod', function() { + return expectError( + emberGenerateDestroy(['route', 'foo', '--pod']), + "Pods aren't supported within a module unification app" + ); + }); + }); + }); + + describe('in addon - octane', function() { + enableOctane(); + + beforeEach(function() { + return emberNew({ target: 'addon' }) + .then(() => + modifyPackages([ + { name: 'ember-qunit', delete: true }, + { name: 'ember-cli-qunit', dev: true }, + ]) + ) + .then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0')); + }); + + it('route foo', function() { + return emberGenerateDestroy(['route', 'foo'], _file => { + expect(_file('src/ui/routes/foo/route.js')).to.equal(fixture('route/native-route.js')); + + expect(_file('src/ui/routes/foo/template.hbs')).to.equal('{{outlet}}'); + + expect(_file('src/ui/routes/foo/route-test.js')).to.equal(fixture('route-test/default.js')); + + expect(file('tests/dummy/src/router.js')).to.not.contain("this.route('foo')"); + }).then(() => { + expect(file('tests/dummy/src/router.js')).to.not.contain("this.route('foo')"); + }); + }); + + it('route foo/bar', function() { + return emberGenerateDestroy(['route', 'foo/bar'], _file => { + expect(_file('src/ui/routes/foo/bar/route.js')).to.equal( + fixture('route/native-route-nested.js') + ); + + expect(_file('src/ui/routes/foo/bar/template.hbs')).to.equal('{{outlet}}'); + + expect(_file('src/ui/routes/foo/bar/route-test.js')).to.equal( + fixture('route-test/default-nested.js') + ); + + expect(file('tests/dummy/src/router.js')).to.not.contain("this.route('bar')"); + }).then(() => { + expect(file('tests/dummy/src/router.js')).to.not.contain("this.route('bar')"); + }); + }); + + it('route foo --dummy', function() { + return emberGenerateDestroy(['route', 'foo', '--dummy'], _file => { + expect(_file('tests/dummy/src/ui/routes/foo/route.js')).to.equal( + fixture('route/native-route.js') + ); + + expect(_file('tests/dummy/src/ui/routes/foo/template.hbs')).to.equal('{{outlet}}'); + + expect(_file('src/ui/routes/foo/route.js')).to.not.exist; + expect(_file('src/ui/routes/foo/template.hbs')).to.not.exist; + expect(_file('src/ui/routes/foo/route-test.js')).to.not.exist; + + expect(file('tests/dummy/src/router.js')).to.contain("this.route('foo')"); + }).then(() => { + expect(file('tests/dummy/src/router.js')).to.not.contain("this.route('foo')"); + }); + }); + + it('route foo/bar --dummy', function() { + return emberGenerateDestroy(['route', 'foo/bar', '--dummy'], _file => { + expect(_file('tests/dummy/src/ui/routes/foo/bar/route.js')).to.equal( + fixture('route/native-route-nested.js') + ); + + expect(_file('tests/dummy/src/ui/routes/foo/bar/template.hbs')).to.equal('{{outlet}}'); + + expect(_file('src/ui/routes/foo/route.js')).to.not.exist; + expect(_file('src/ui/routes/foo/template.hbs')).to.not.exist; + expect(_file('src/ui/routes/foo/route-test.js')).to.not.exist; + + expect(file('tests/dummy/src/router.js')) + .to.contain("this.route('foo', function() {") + .to.contain("this.route('bar')"); + }).then(() => { + expect(file('tests/dummy/src/router.js')).to.not.contain("this.route('bar')"); + }); + }); + + it('route foo --pod', function() { + return expectError( + emberGenerateDestroy(['route', 'foo', '--pod']), + "Pods aren't supported within a module unification app" + ); + }); + }); + describe('in in-repo-addon', function() { beforeEach(function() { return emberNew({ target: 'in-repo-addon' }) diff --git a/node-tests/blueprints/service-test.js b/node-tests/blueprints/service-test.js index caeb91a4844..29c9de8444f 100644 --- a/node-tests/blueprints/service-test.js +++ b/node-tests/blueprints/service-test.js @@ -13,6 +13,7 @@ const expect = chai.expect; const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest'); const enableModuleUnification = require('../helpers/module-unification').enableModuleUnification; +const enableOctane = require('../helpers/setup-test-environment').enableOctane; const fixture = require('../helpers/fixture'); describe('Blueprint: service', function() { @@ -139,6 +140,48 @@ describe('Blueprint: service', function() { }); }); + describe('in app - octane', function() { + enableOctane(); + + beforeEach(function() { + return emberNew() + .then(() => + modifyPackages([ + { name: 'ember-qunit', delete: true }, + { name: 'ember-cli-qunit', dev: true }, + ]) + ) + .then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0')); + }); + + it('service foo', function() { + return emberGenerateDestroy(['service', 'foo'], _file => { + expect(_file('src/services/foo.js')).to.equal(fixture('service/native-service.js')); + + expect(_file('src/services/foo-test.js')).to.equal(fixture('service-test/default.js')); + }); + }); + + it('service foo/bar', function() { + return emberGenerateDestroy(['service', 'foo/bar'], _file => { + expect(_file('src/services/foo/bar.js')).to.equal( + fixture('service/native-service-nested.js') + ); + + expect(_file('src/services/foo/bar-test.js')).to.equal( + fixture('service-test/default-nested.js') + ); + }); + }); + + it('service foo --pod', function() { + return expectError( + emberGenerateDestroy(['service', 'foo', '--pod']), + "Pods aren't supported within a module unification app" + ); + }); + }); + describe('in addon', function() { beforeEach(function() { return emberNew({ target: 'addon' }) @@ -217,6 +260,45 @@ describe('Blueprint: service', function() { }); }); + describe('in addon - octane', function() { + enableOctane(); + + beforeEach(function() { + return emberNew({ target: 'addon' }) + .then(() => + modifyPackages([ + { name: 'ember-qunit', delete: true }, + { name: 'ember-cli-qunit', dev: true }, + ]) + ) + .then(() => generateFakePackageManifest('ember-cli-qunit', '4.1.0')); + }); + + it('service foo', function() { + return emberGenerateDestroy(['service', 'foo'], _file => { + expect(_file('src/services/foo.js')).to.equal(fixture('service/native-service.js')); + + expect(_file('src/services/foo-test.js')).to.equal(fixture('service-test/default.js')); + + expect(_file('app/services/foo.js')).to.not.exist; + }); + }); + + it('service foo/bar', function() { + return emberGenerateDestroy(['service', 'foo/bar'], _file => { + expect(_file('src/services/foo/bar.js')).to.equal( + fixture('service/native-service-nested.js') + ); + + expect(_file('src/services/foo/bar-test.js')).to.equal( + fixture('service-test/default-nested.js') + ); + + expect(_file('app/services/foo/bar.js')).to.not.exist; + }); + }); + }); + describe('in in-repo-addon', function() { beforeEach(function() { return emberNew({ target: 'in-repo-addon' }) diff --git a/node-tests/fixtures/component/native-component-dash.js b/node-tests/fixtures/component/native-component-dash.js new file mode 100644 index 00000000000..6756e8858e3 --- /dev/null +++ b/node-tests/fixtures/component/native-component-dash.js @@ -0,0 +1,4 @@ +import Component from '@ember/component'; + +export default class XFooComponent extends Component { +} diff --git a/node-tests/fixtures/component/native-component-nested.js b/node-tests/fixtures/component/native-component-nested.js new file mode 100644 index 00000000000..9f64d83869a --- /dev/null +++ b/node-tests/fixtures/component/native-component-nested.js @@ -0,0 +1,4 @@ +import Component from '@ember/component'; + +export default class FooXFooComponent extends Component { +} diff --git a/node-tests/fixtures/component/native-component.js b/node-tests/fixtures/component/native-component.js new file mode 100644 index 00000000000..4cbb1f8a8db --- /dev/null +++ b/node-tests/fixtures/component/native-component.js @@ -0,0 +1,4 @@ +import Component from '@ember/component'; + +export default class FooComponent extends Component { +} diff --git a/node-tests/fixtures/controller/native-controller-nested.js b/node-tests/fixtures/controller/native-controller-nested.js new file mode 100644 index 00000000000..fed3d2f929d --- /dev/null +++ b/node-tests/fixtures/controller/native-controller-nested.js @@ -0,0 +1,4 @@ +import Controller from '@ember/controller'; + +export default class FooBarController extends Controller { +}; diff --git a/node-tests/fixtures/controller/native-controller.js b/node-tests/fixtures/controller/native-controller.js new file mode 100644 index 00000000000..e60aa582130 --- /dev/null +++ b/node-tests/fixtures/controller/native-controller.js @@ -0,0 +1,4 @@ +import Controller from '@ember/controller'; + +export default class FooController extends Controller { +}; diff --git a/node-tests/fixtures/route/native-route-child.js b/node-tests/fixtures/route/native-route-child.js new file mode 100644 index 00000000000..8481ba97ba5 --- /dev/null +++ b/node-tests/fixtures/route/native-route-child.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class ParentChildRoute extends Route { +} diff --git a/node-tests/fixtures/route/native-route-nested.js b/node-tests/fixtures/route/native-route-nested.js new file mode 100644 index 00000000000..5a0c1661f75 --- /dev/null +++ b/node-tests/fixtures/route/native-route-nested.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class FooBarRoute extends Route { +} diff --git a/node-tests/fixtures/route/native-route.js b/node-tests/fixtures/route/native-route.js new file mode 100644 index 00000000000..fa31033660d --- /dev/null +++ b/node-tests/fixtures/route/native-route.js @@ -0,0 +1,4 @@ +import Route from '@ember/routing/route'; + +export default class FooRoute extends Route { +} diff --git a/node-tests/fixtures/service/native-service-nested.js b/node-tests/fixtures/service/native-service-nested.js new file mode 100644 index 00000000000..b6205148786 --- /dev/null +++ b/node-tests/fixtures/service/native-service-nested.js @@ -0,0 +1,4 @@ +import Service from '@ember/service'; + +export default class FooBarService extends Service { +} diff --git a/node-tests/fixtures/service/native-service.js b/node-tests/fixtures/service/native-service.js new file mode 100644 index 00000000000..8447de6df53 --- /dev/null +++ b/node-tests/fixtures/service/native-service.js @@ -0,0 +1,4 @@ +import Service from '@ember/service'; + +export default class FooService extends Service { +} diff --git a/node-tests/helpers/setup-test-environment.js b/node-tests/helpers/setup-test-environment.js new file mode 100644 index 00000000000..056ee233708 --- /dev/null +++ b/node-tests/helpers/setup-test-environment.js @@ -0,0 +1,15 @@ +function enableOctane() { + beforeEach(function() { + process.env.EMBER_CLI_MODULE_UNIFICATION = 'true'; + process.env.EMBER_VERSION = 'OCTANE'; + }); + + afterEach(function() { + delete process.env.EMBER_CLI_MODULE_UNIFICATION; + delete process.env.EMBER_VERSION; + }); +} + +module.exports = { + enableOctane, +};