Skip to content

Commit

Permalink
[Feature] module unification controller & controller-test blueprints
Browse files Browse the repository at this point in the history
Remove missed comment


Remove packagelock.json


Remove uneeded file are per PR comments


Add tests for nested components
  • Loading branch information
Dexter Edwards committed May 18, 2018
1 parent 2d6579a commit 8caa131
Show file tree
Hide file tree
Showing 13 changed files with 395 additions and 1 deletion.
39 changes: 39 additions & 0 deletions blueprints/controller-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,54 @@
const stringUtil = require('ember-cli-string-utils');

const useTestFrameworkDetector = require('../test-framework-detector');
const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;
const path = require('path');

module.exports = useTestFrameworkDetector({
description: 'Generates a controller unit test.',
locals: function(options) {
let dasherizedModuleName = stringUtil.dasherize(options.entity.name);
let controllerPathName = dasherizedModuleName;

return {
controllerPathName: controllerPathName,
friendlyTestDescription: ['Unit', 'Controller', dasherizedModuleName].join(' | '),
};
},
fileMapTokens: function() {
if (isModuleUnificationProject(this.project)) {
return {
__test__() {
return 'controller-test';
},
__testType__() {
return '';
},
__root__(options) {
if (options.pod) {
throw "Pods aren't supported within a module unification app";
}
return 'src';
},
__path__(options) {
return path.join('ui', 'routes', options.dasherizedModuleName);
},
};
} else {
return {
__root__() {
return 'tests';
},
__testType__() {
return 'unit';
},
__path__(options) {
if (options.pod) {
return path.join(options.podPath, options.dasherizedModuleName);
}
return 'controllers';
},
};
}
},
});
24 changes: 24 additions & 0 deletions blueprints/controller/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
'use strict';

const isModuleUnificationProject = require('../module-unification').isModuleUnificationProject;
const path = require('path');

module.exports = {
description: 'Generates a controller.',
fileMapTokens() {
if (isModuleUnificationProject(this.project)) {
return {
__root__(options) {
if (options.pod) {
throw "Pods aren't supported within a module unification app";
}
if (options.inDummy) {
return path.join('tests', 'dummy', 'src');
}
return 'src';
},
__path__(options) {
return path.join('ui', 'routes', options.dasherizedModuleName);
},
__name__() {
return 'controller';
},
};
}
},
};
2 changes: 1 addition & 1 deletion blueprints/module-unification.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module.exports = {
isModuleUnificationProject(project) {
return project.isModuleUnification && project.isModuleUnification();
return project && project.isModuleUnification && project.isModuleUnification();
},
};
159 changes: 159 additions & 0 deletions node-tests/blueprints/controller-test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const expect = chai.expect;

const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
const fixture = require('../helpers/fixture');
const fs = require('fs-extra');

describe('Blueprint: controller-test', function() {
setupTestHooks(this);
Expand All @@ -28,6 +29,14 @@ describe('Blueprint: controller-test', function() {
});
});

it('controller-test foo/bar', function() {
return emberGenerateDestroy(['controller-test', 'foo/bar'], _file => {
expect(_file('tests/unit/controllers/foo/bar-test.js')).to.equal(
fixture('controller-test/default-nested.js')
);
});
});

describe('with [email protected]', function() {
beforeEach(function() {
generateFakePackageManifest('ember-cli-qunit', '4.2.0');
Expand All @@ -40,6 +49,14 @@ describe('Blueprint: controller-test', function() {
);
});
});

it('controller-test foo/bar', function() {
return emberGenerateDestroy(['controller-test', 'foo/bar'], _file => {
expect(_file('tests/unit/controllers/foo/bar-test.js')).to.equal(
fixture('controller-test/rfc232-nested.js')
);
});
});
});

describe('with [email protected]', function() {
Expand All @@ -58,6 +75,14 @@ describe('Blueprint: controller-test', function() {
);
});
});

it('controller-test foo/bar for mocha', function() {
return emberGenerateDestroy(['controller-test', 'foo/bar'], _file => {
expect(_file('tests/unit/controllers/foo/bar-test.js')).to.equal(
fixture('controller-test/mocha-nested.js')
);
});
});
});

describe('with [email protected]', function() {
Expand All @@ -76,6 +101,110 @@ describe('Blueprint: controller-test', function() {
);
});
});

it('controller-test foo/bar', function() {
return emberGenerateDestroy(['controller-test', 'foo/bar'], _file => {
expect(_file('tests/unit/controllers/foo/bar-test.js')).to.equal(
fixture('controller-test/mocha-0.12-nested.js')
);
});
});
});
});

describe('in app - module unification', function() {
beforeEach(function() {
return emberNew().then(() => fs.ensureDirSync('src'));
});

it('controller-test foo', function() {
return emberGenerateDestroy(['controller-test', 'foo'], _file => {
expect(_file('src/ui/routes/foo/controller-test.js')).to.equal(
fixture('controller-test/default.js')
);
});
});

it('controller-test foo/bar', function() {
return emberGenerateDestroy(['controller-test', 'foo/bar'], _file => {
expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.equal(
fixture('controller-test/default-nested.js')
);
});
});

describe('with [email protected]', function() {
beforeEach(function() {
generateFakePackageManifest('ember-cli-qunit', '4.2.0');
});

it('controller-test foo', function() {
return emberGenerateDestroy(['controller-test', 'foo'], _file => {
expect(_file('src/ui/routes/foo/controller-test.js')).to.equal(
fixture('controller-test/rfc232.js')
);
});
});

it('controller-test foo/bar', function() {
return emberGenerateDestroy(['controller-test', 'foo/bar'], _file => {
expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.equal(
fixture('controller-test/rfc232-nested.js')
);
});
});
});

describe('with [email protected]', function() {
beforeEach(function() {
modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-cli-mocha', dev: true },
]);
generateFakePackageManifest('ember-cli-mocha', '0.11.0');
});

it('controller-test foo for mocha', function() {
return emberGenerateDestroy(['controller-test', 'foo'], _file => {
expect(_file('src/ui/routes/foo/controller-test.js')).to.equal(
fixture('controller-test/mocha.js')
);
});
});

it('controller-test foo/bar for mocha', function() {
return emberGenerateDestroy(['controller-test', 'foo/bar'], _file => {
expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.equal(
fixture('controller-test/mocha-nested.js')
);
});
});
});

describe('with [email protected]', function() {
beforeEach(function() {
modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-cli-mocha', dev: true },
]);
generateFakePackageManifest('ember-cli-mocha', '0.12.0');
});

it('controller-test foo', function() {
return emberGenerateDestroy(['controller-test', 'foo'], _file => {
expect(_file('src/ui/routes/foo/controller-test.js')).to.equal(
fixture('controller-test/mocha-0.12.js')
);
});
});

it('controller-test foo/bar', function() {
return emberGenerateDestroy(['controller-test', 'foo/bar'], _file => {
expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.equal(
fixture('controller-test/mocha-0.12-nested.js')
);
});
});
});
});

Expand All @@ -91,5 +220,35 @@ describe('Blueprint: controller-test', function() {
);
});
});

it('controller-test foo/bar', function() {
return emberGenerateDestroy(['controller-test', 'foo/bar'], _file => {
expect(_file('tests/unit/controllers/foo/bar-test.js')).to.equal(
fixture('controller-test/default-nested.js')
);
});
});
});

describe('in addon - module unification', function() {
beforeEach(function() {
return emberNew().then(() => fs.ensureDirSync('src'));
});

it('controller-test foo', function() {
return emberGenerateDestroy(['controller-test', 'foo'], _file => {
expect(_file('src/ui/routes/foo/controller-test.js')).to.equal(
fixture('controller-test/default.js')
);
});
});

it('controller-test foo/bar', function() {
return emberGenerateDestroy(['controller-test', 'foo/bar'], _file => {
expect(_file('src/ui/routes/foo/bar/controller-test.js')).to.equal(
fixture('controller-test/default-nested.js')
);
});
});
});
});
Loading

0 comments on commit 8caa131

Please sign in to comment.