From cf0c5b423ba7a1338d374871f6c7e98224079967 Mon Sep 17 00:00:00 2001 From: Ruairi Kenny Date: Wed, 11 Apr 2018 19:31:24 +0100 Subject: [PATCH] [WIP] [Feature] helper blueprint for module unification --- blueprints/helper-test/index.js | 31 ++++++++-- .../__collection__}/__name__-test.js | 0 .../__collection__}/__name__-test.js | 0 .../__collection__}/__name__-test.js | 0 .../__collection__}/__name__-test.js | 0 .../{helpers => __collection__}/__name__.js | 0 blueprints/helper/index.js | 29 +++++++++ node-tests/blueprints/helper-test.js | 61 ++++++++++++++++++- 8 files changed, 115 insertions(+), 6 deletions(-) rename blueprints/helper-test/mocha-0.12-files/{tests/__testType__/helpers => __root__/__testType__/__collection__}/__name__-test.js (100%) rename blueprints/helper-test/mocha-files/{tests/__testType__/helpers => __root__/__testType__/__collection__}/__name__-test.js (100%) rename blueprints/helper-test/qunit-files/{tests/__testType__/helpers => __root__/__testType__/__collection__}/__name__-test.js (100%) rename blueprints/helper-test/qunit-rfc-232-files/{tests/__testType__/helpers => __root__/__testType__/__collection__}/__name__-test.js (100%) rename blueprints/helper/files/__root__/{helpers => __collection__}/__name__.js (100%) diff --git a/blueprints/helper-test/index.js b/blueprints/helper-test/index.js index ebbb8cff206..e7ed683902d 100644 --- a/blueprints/helper-test/index.js +++ b/blueprints/helper-test/index.js @@ -4,6 +4,7 @@ const stringUtils = require('ember-cli-string-utils'); const isPackageMissing = require('ember-cli-is-package-missing'); const useTestFrameworkDetector = require('../test-framework-detector'); +const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject; module.exports = useTestFrameworkDetector({ description: 'Generates a helper integration test or a unit test.', @@ -23,11 +24,31 @@ module.exports = useTestFrameworkDetector({ ], fileMapTokens: function() { - return { - __testType__: function(options) { - return options.locals.testType || 'integration'; - }, - }; + if (isModuleUnificationProject(this.project)) { + return { + __root__() { + return 'src'; + }, + __testType__() { + return ''; + }, + __collection__() { + return 'ui/components'; + }, + }; + } else { + return { + __root__() { + return 'tests'; + }, + __testType__(options) { + return options.locals.testType || 'integration'; + }, + __collection__() { + return 'helpers'; + }, + }; + } }, locals: function(options) { diff --git a/blueprints/helper-test/mocha-0.12-files/tests/__testType__/helpers/__name__-test.js b/blueprints/helper-test/mocha-0.12-files/__root__/__testType__/__collection__/__name__-test.js similarity index 100% rename from blueprints/helper-test/mocha-0.12-files/tests/__testType__/helpers/__name__-test.js rename to blueprints/helper-test/mocha-0.12-files/__root__/__testType__/__collection__/__name__-test.js diff --git a/blueprints/helper-test/mocha-files/tests/__testType__/helpers/__name__-test.js b/blueprints/helper-test/mocha-files/__root__/__testType__/__collection__/__name__-test.js similarity index 100% rename from blueprints/helper-test/mocha-files/tests/__testType__/helpers/__name__-test.js rename to blueprints/helper-test/mocha-files/__root__/__testType__/__collection__/__name__-test.js diff --git a/blueprints/helper-test/qunit-files/tests/__testType__/helpers/__name__-test.js b/blueprints/helper-test/qunit-files/__root__/__testType__/__collection__/__name__-test.js similarity index 100% rename from blueprints/helper-test/qunit-files/tests/__testType__/helpers/__name__-test.js rename to blueprints/helper-test/qunit-files/__root__/__testType__/__collection__/__name__-test.js diff --git a/blueprints/helper-test/qunit-rfc-232-files/tests/__testType__/helpers/__name__-test.js b/blueprints/helper-test/qunit-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js similarity index 100% rename from blueprints/helper-test/qunit-rfc-232-files/tests/__testType__/helpers/__name__-test.js rename to blueprints/helper-test/qunit-rfc-232-files/__root__/__testType__/__collection__/__name__-test.js diff --git a/blueprints/helper/files/__root__/helpers/__name__.js b/blueprints/helper/files/__root__/__collection__/__name__.js similarity index 100% rename from blueprints/helper/files/__root__/helpers/__name__.js rename to blueprints/helper/files/__root__/__collection__/__name__.js diff --git a/blueprints/helper/index.js b/blueprints/helper/index.js index fb1df4e4dff..2fbed5c8214 100644 --- a/blueprints/helper/index.js +++ b/blueprints/helper/index.js @@ -1,9 +1,38 @@ 'use strict'; +const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject; const normalizeEntityName = require('ember-cli-normalize-entity-name'); module.exports = { description: 'Generates a helper function.', + + fileMapTokens() { + if (isModuleUnificationProject(this.project)) { + return { + __root__(options) { + if (options.pod) { + throw "Pods aren't supported within a module unification app"; + } + + return 'src'; + }, + __collection__(options) { + if (options.pod) { + throw "Pods aren't supported within a module unification app"; + } + + return 'ui/components'; + }, + }; + } else { + return { + __collection__() { + return 'helpers'; + }, + }; + } + }, + normalizeEntityName: function(entityName) { return normalizeEntityName(entityName); }, diff --git a/node-tests/blueprints/helper-test.js b/node-tests/blueprints/helper-test.js index 1b020034eed..637c3862786 100644 --- a/node-tests/blueprints/helper-test.js +++ b/node-tests/blueprints/helper-test.js @@ -10,8 +10,9 @@ const chai = require('ember-cli-blueprint-test-helpers/chai'); const expect = chai.expect; const fixture = require('../helpers/fixture'); +const fs = require('fs-extra'); -describe('Blueprint: helper', function() { +describe.only('Blueprint: helper', function() { setupTestHooks(this); describe('in app', function() { @@ -80,7 +81,65 @@ describe('Blueprint: helper', function() { }); }); + describe('in app - module unification', function() { + beforeEach(function() { + return emberNew().then(() => fs.ensureDirSync('src')); + }); + + it('helper foo/bar-baz', function() { + return emberGenerateDestroy(['helper', 'foo/bar-baz'], _file => { + expect(_file('src/ui/components/foo/bar-baz.js')).to.equal(fixture('helper.js')); + expect(_file('src/ui/components/foo/bar-baz-test.js')).to.equal( + fixture('helper-test/integration.js') + ); + }); + }); + + it('helper foo/bar-baz unit', function() { + return emberGenerateDestroy(['helper', '--test-type=unit', 'foo/bar-baz'], _file => { + expect(_file('src/ui/components/foo/bar-baz.js')).to.equal(fixture('helper.js')); + expect(_file('src/ui/components/foo/bar-baz-test.js')).to.equal( + fixture('helper-test/unit.js') + ); + }); + }); + }); + describe('in addon', function() { + beforeEach(function() { + return emberNew({ target: 'addon' }).then(() => fs.ensureDirSync('src')); + }); + + it.only('helper foo/bar-baz', function() { + return emberGenerateDestroy(['helper', 'foo/bar-baz'], _file => { + expect(_file('src/ui/components/foo/bar-baz.js')).to.equal(fixture('helper.js')); + expect(_file('app/helpers/foo/bar-baz.js')).to.not.exist; + expect(_file('src/ui/components/foo/bar-baz.js-test.js')).to.equal( + fixture('helper-test/integration.js') + ); + }); + }); + + it('helper foo/bar-baz', function() { + return emberGenerateDestroy(['helper', 'foo/bar-baz'], _file => { + expect(_file('addon/helpers/foo/bar-baz.js')).to.equal(fixture('helper.js')); + expect(_file('app/helpers/foo/bar-baz.js')).to.equal(fixture('helper-addon.js')); + expect(_file('tests/integration/helpers/foo/bar-baz-test.js')).to.equal( + fixture('helper-test/integration.js') + ); + }); + }); + + it('helper foo/bar-baz --dummy', function() { + return emberGenerateDestroy(['helper', 'foo/bar-baz', '--dummy'], _file => { + expect(_file('tests/dummy/app/helpers/foo/bar-baz.js')).to.equal(fixture('helper.js')); + expect(_file('app/helpers/foo/bar-baz.js')).to.not.exist; + expect(_file('tests/integration/helpers/foo/bar-baz-test.js')).to.not.exist; + }); + }); + }); + + describe('in addon - module unification', function() { beforeEach(function() { return emberNew({ target: 'addon' }); });