Skip to content

Commit

Permalink
Merge pull request emberjs#16524 from jackbeegan/jb/mixin-blueprint
Browse files Browse the repository at this point in the history
[Feature] Adds mixin blueprint for module unification
  • Loading branch information
rwjblue authored Jun 6, 2018
2 parents 03b512c + df591a6 commit fe23def
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 0 deletions.
30 changes: 30 additions & 0 deletions blueprints/mixin-test/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
'use strict';

const path = require('path');

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

module.exports = useTestFrameworkDetector({
description: 'Generates a mixin unit test.',

fileMapTokens() {
if (isModuleUnificationProject(this.project)) {
return {
__root__(options) {
if (options.pod) {
throw "Pods aren't supported within a module unification app";
}

return 'src';
},
__testType__() {
return 'mixins';
},
};
} else {
return {
__root__() {
return 'tests';
},
__testType__() {
return path.join('unit', 'mixins');
},
};
}
},

locals: function(options) {
return {
projectName: options.inRepoAddon ? options.inRepoAddon : options.project.name(),
Expand Down
16 changes: 16 additions & 0 deletions blueprints/mixin/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
'use strict';

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

module.exports = {
description: 'Generates a mixin.',

fileMapTokens() {
if (isModuleUnificationProject(this.project)) {
return {
__root__(options) {
if (options.pod) {
throw "Pods aren't supported within a module unification app";
}

return 'src';
},
};
}
},
};
64 changes: 64 additions & 0 deletions node-tests/blueprints/mixin-test-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const modifyPackages = blueprintHelpers.modifyPackages;

const chai = require('ember-cli-blueprint-test-helpers/chai');
const expect = chai.expect;
const fs = require('fs-extra');

const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
const fixture = require('../helpers/fixture');
Expand Down Expand Up @@ -54,6 +55,45 @@ describe('Blueprint: mixin-test', function() {
});
});

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

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

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

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

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

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

describe('in addon', function() {
beforeEach(function() {
return emberNew({ target: 'addon' });
Expand All @@ -65,4 +105,28 @@ describe('Blueprint: mixin-test', function() {
});
});
});

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

it('mixin-test foo', function() {
return emberGenerateDestroy(['mixin-test', 'foo'], _file => {
expect(_file('src/mixins/foo-test.js')).to.equal(fixture('mixin-test/addon.js'));
});
});
});

describe('in in-repo-addon', function() {
beforeEach(function() {
return emberNew({ target: 'in-repo-addon' });
});

it('mixin-test foo --in-repo-addon=my-addon', function() {
return emberGenerateDestroy(['mixin-test', 'foo', '--in-repo-addon=my-addon'], _file => {
expect(_file('tests/unit/mixins/foo-test.js')).to.equal(fixture('mixin-test/addon.js'));
});
});
});
});
93 changes: 93 additions & 0 deletions node-tests/blueprints/mixin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ const setupTestHooks = blueprintHelpers.setupTestHooks;
const emberNew = blueprintHelpers.emberNew;
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
const setupPodConfig = blueprintHelpers.setupPodConfig;
const expectError = require('../helpers/expect-error');

const chai = require('ember-cli-blueprint-test-helpers/chai');
const expect = chai.expect;
const fs = require('fs-extra');

describe('Blueprint: mixin', function() {
setupTestHooks(this);
Expand Down Expand Up @@ -112,6 +114,55 @@ describe('Blueprint: mixin', function() {
});
});

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

it('mixin foo', function() {
return emberGenerateDestroy(['mixin', 'foo'], _file => {
expect(_file('src/mixins/foo.js'))
.to.contain("import Mixin from '@ember/object/mixin';")
.to.contain('export default Mixin.create({\n});');

expect(_file('src/mixins/foo-test.js')).to.contain(
"import FooMixin from 'my-app/mixins/foo';"
);
});
});

it('mixin foo/bar', function() {
return emberGenerateDestroy(['mixin', 'foo/bar'], _file => {
expect(_file('src/mixins/foo/bar.js'))
.to.contain("import Mixin from '@ember/object/mixin';")
.to.contain('export default Mixin.create({\n});');

expect(_file('src/mixins/foo/bar-test.js')).to.contain(
"import FooBarMixin from 'my-app/mixins/foo/bar';"
);
});
});

it('mixin foo/bar/baz', function() {
return emberGenerateDestroy(['mixin', 'foo/bar/baz'], _file => {
expect(_file('src/mixins/foo/bar/baz.js'))
.to.contain("import Mixin from '@ember/object/mixin';")
.to.contain('export default Mixin.create({\n});');

expect(_file('src/mixins/foo/bar/baz-test.js')).to.contain(
"import FooBarBazMixin from 'my-app/mixins/foo/bar/baz';"
);
});
});

it('mixin foo --pod', function() {
return expectError(
emberGenerateDestroy(['service', 'foo', '--pod']),
"Pods aren't supported within a module unification app"
);
});
});

describe('in addon', function() {
beforeEach(function() {
return emberNew({ target: 'addon' });
Expand Down Expand Up @@ -160,6 +211,48 @@ describe('Blueprint: mixin', function() {
});
});

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

it('mixin foo', function() {
return emberGenerateDestroy(['mixin', 'foo'], _file => {
expect(_file('src/mixins/foo.js'))
.to.contain("import Mixin from '@ember/object/mixin';")
.to.contain('export default Mixin.create({\n});');

expect(_file('src/mixins/foo-test.js')).to.contain(
"import FooMixin from 'my-addon/mixins/foo';"
);
});
});

it('mixin foo/bar', function() {
return emberGenerateDestroy(['mixin', 'foo/bar'], _file => {
expect(_file('src/mixins/foo/bar.js'))
.to.contain("import Mixin from '@ember/object/mixin';")
.to.contain('export default Mixin.create({\n});');

expect(_file('src/mixins/foo/bar-test.js')).to.contain(
"import FooBarMixin from 'my-addon/mixins/foo/bar';"
);
});
});

it('mixin foo/bar/baz', function() {
return emberGenerateDestroy(['mixin', 'foo/bar/baz'], _file => {
expect(_file('src/mixins/foo/bar/baz.js'))
.to.contain("import Mixin from '@ember/object/mixin';")
.to.contain('export default Mixin.create({\n});');

expect(_file('src/mixins/foo/bar/baz-test.js')).to.contain(
"import FooBarBazMixin from 'my-addon/mixins/foo/bar/baz';"
);
});
});
});

describe('in in-repo-addon', function() {
beforeEach(function() {
return emberNew({ target: 'in-repo-addon' });
Expand Down

0 comments on commit fe23def

Please sign in to comment.