Skip to content

Commit

Permalink
[WIP] [Feature] helper blueprint for module unification
Browse files Browse the repository at this point in the history
  • Loading branch information
RuairiK authored and ppcano committed Nov 28, 2018
1 parent 7666b70 commit cf0c5b4
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 6 deletions.
31 changes: 26 additions & 5 deletions blueprints/helper-test/index.js
Expand Up @@ -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.',
Expand All @@ -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) {
Expand Down
29 changes: 29 additions & 0 deletions 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);
},
Expand Down
61 changes: 60 additions & 1 deletion node-tests/blueprints/helper-test.js
Expand Up @@ -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() {
Expand Down Expand Up @@ -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' });
});
Expand Down

0 comments on commit cf0c5b4

Please sign in to comment.