Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions blueprints/helper-test/index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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,11 +81,69 @@ 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' });
});

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('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' }).then(() => fs.ensureDirSync('src'));
});

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'));
Expand Down