Permalink
Browse files

[WIP] [Feature] helper blueprint for module unification

  • Loading branch information...
RuairiK authored and ppcano committed Apr 11, 2018
1 parent 7666b70 commit cf0c5b423ba7a1338d374871f6c7e98224079967
@@ -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) {
@@ -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);
},
@@ -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' });
});

0 comments on commit cf0c5b4

Please sign in to comment.