Skip to content

Commit

Permalink
Merge pull request #5495 from dcyriller/mu-transform-blueprint
Browse files Browse the repository at this point in the history
[Feature] Add MU transform{,-test} blueprints
  • Loading branch information
runspired authored Sep 26, 2018
2 parents 58cd257 + 45e7f19 commit e349ec2
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 50 deletions.
34 changes: 31 additions & 3 deletions blueprints/transform-test/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
var testInfo = require('ember-cli-test-info');
var useTestFrameworkDetector = require('../test-framework-detector');
const testInfo = require('ember-cli-test-info');
const useTestFrameworkDetector = require('../test-framework-detector');
const isModuleUnificationProject = require('../../lib/utilities/module-unification')
.isModuleUnificationProject;
const path = require('path');

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

locals: function(options) {
fileMapTokens(options) {
if (isModuleUnificationProject(this.project)) {
return {
__root__() {
return 'src';
},
__path__(options) {
return path.join('data', 'transforms');
},
__test__() {
return `${options.dasherizedModuleName}-test`;
},
};
} else {
return {
__root__() {
return 'tests';
},
__path__() {
return path.join('unit', 'transforms');
},
};
}
},

locals(options) {
return {
friendlyTestDescription: testInfo.description(options.entity.name, 'Unit', 'Transform'),
};
Expand Down
20 changes: 20 additions & 0 deletions blueprints/transform/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
const isModuleUnificationProject = require('../../lib/utilities/module-unification')
.isModuleUnificationProject;
const path = require('path');

module.exports = {
description: 'Generates an ember-data value transform.',

fileMapTokens(options) {
if (isModuleUnificationProject(this.project)) {
return {
__root__() {
return 'src';
},
__path__(options) {
return path.join('data', 'transforms');
},
__name__() {
return options.dasherizedModuleName;
},
};
}
},
};
168 changes: 127 additions & 41 deletions node-tests/blueprints/transform-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,152 @@ const fixture = require('../helpers/fixture');
describe('Acceptance: generate and destroy transform blueprints', function() {
setupTestHooks(this);

describe('in app', function() {
beforeEach(function() {
return emberNew();
});
describe('classic', function() {
describe('in app', function() {
beforeEach(function() {
return emberNew();
});

it('transform', function() {
let args = ['transform', 'foo'];
it('transform', function() {
let args = ['transform', 'foo'];

return emberGenerateDestroy(args, _file => {
expect(_file('app/transforms/foo.js'))
.to.contain("import DS from 'ember-data';")
.to.contain('export default DS.Transform.extend(')
.to.contain('deserialize(serialized) {')
.to.contain('serialize(deserialized) {');
return emberGenerateDestroy(args, _file => {
expect(_file('app/transforms/foo.js'))
.to.contain("import DS from 'ember-data';")
.to.contain('export default DS.Transform.extend(')
.to.contain('deserialize(serialized) {')
.to.contain('serialize(deserialized) {');

expect(_file('tests/unit/transforms/foo-test.js')).to.equal(
fixture('transform-test/default.js')
);
expect(_file('tests/unit/transforms/foo-test.js')).to.equal(
fixture('transform-test/default.js')
);
});
});
});

it('transform-test', function() {
let args = ['transform-test', 'foo'];
it('transform-test', function() {
let args = ['transform-test', 'foo'];

return emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/transforms/foo-test.js')).to.equal(
fixture('transform-test/default.js')
);
return emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/transforms/foo-test.js')).to.equal(
fixture('transform-test/default.js')
);
});
});
});

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

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

it('transform-test-test foo', function() {
return emberGenerateDestroy(['transform-test', 'foo'], _file => {
expect(_file('tests/unit/transforms/foo-test.js')).to.equal(
fixture('transform-test/rfc232.js')
);
describe('with ember-cli-mocha v0.12+', function() {
beforeEach(function() {
modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-cli-mocha', dev: true },
]);
generateFakePackageManifest('ember-cli-mocha', '0.12.0');
});

it('transform-test for mocha v0.12+', function() {
let args = ['transform-test', 'foo'];

return emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/transforms/foo-test.js')).to.equal(
fixture('transform-test/mocha-0.12.js')
);
});
});
});
});
});

describe('with ember-cli-mocha v0.12+', function() {
describe('module unification', function() {
describe('in app', function() {
beforeEach(function() {
modifyPackages([
{ name: 'ember-cli-qunit', delete: true },
{ name: 'ember-cli-mocha', dev: true },
]);
generateFakePackageManifest('ember-cli-mocha', '0.12.0');
return emberNew({ isModuleUnification: true });
});

it('transform-test for mocha v0.12+', function() {
it('transform', function() {
let args = ['transform', 'foo'];

return emberGenerateDestroy(
args,
_file => {
expect(_file('src/data/transforms/foo.js'))
.to.contain("import DS from 'ember-data';")
.to.contain('export default DS.Transform.extend(')
.to.contain('deserialize(serialized) {')
.to.contain('serialize(deserialized) {');

expect(_file('src/data/transforms/foo-test.js')).to.equal(
fixture('transform-test/default.js')
);
},
{ isModuleUnification: true }
);
});

it('transform-test', function() {
let args = ['transform-test', 'foo'];

return emberGenerateDestroy(args, _file => {
expect(_file('tests/unit/transforms/foo-test.js')).to.equal(
fixture('transform-test/mocha-0.12.js')
return emberGenerateDestroy(
args,
_file => {
expect(_file('src/data/transforms/foo-test.js')).to.equal(
fixture('transform-test/default.js')
);
},
{ isModuleUnification: true }
);
});

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

it('transform-test-test foo', function() {
return emberGenerateDestroy(
['transform-test', 'foo'],
_file => {
expect(_file('src/data/transforms/foo-test.js')).to.equal(
fixture('transform-test/rfc232.js')
);
},
{ isModuleUnification: true }
);
});
});

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

it('transform-test for mocha v0.12+', function() {
let args = ['transform-test', 'foo'];

return emberGenerateDestroy(
args,
_file => {
expect(_file('src/data/transforms/foo-test.js')).to.equal(
fixture('transform-test/mocha-0.12.js')
);
},
{ isModuleUnification: true }
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"common-tags": "^1.8.0",
"ember-cli": "^3.3.0",
"ember-cli-app-version": "^3.2.0",
"ember-cli-blueprint-test-helpers": "^0.18.3",
"ember-cli-blueprint-test-helpers": "^0.19.1",
"ember-cli-dependency-checker": "^3.0.0",
"ember-cli-htmlbars": "^3.0.0",
"ember-cli-htmlbars-inline-precompile": "^1.0.3",
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2372,16 +2372,16 @@ ember-cli-babel@^6.0.0, ember-cli-babel@^6.0.0-beta.4, ember-cli-babel@^6.0.0-be
ember-cli-version-checker "^2.1.2"
semver "^5.5.0"

ember-cli-blueprint-test-helpers@^0.18.3:
version "0.18.3"
resolved "https://registry.yarnpkg.com/ember-cli-blueprint-test-helpers/-/ember-cli-blueprint-test-helpers-0.18.3.tgz#945c606d855f0263f5e8c03522e4040a74f259cc"
ember-cli-blueprint-test-helpers@^0.19.1:
version "0.19.1"
resolved "https://registry.yarnpkg.com/ember-cli-blueprint-test-helpers/-/ember-cli-blueprint-test-helpers-0.19.1.tgz#26df9724a6cb48f7acfa391dec7ec772888b0929"
dependencies:
chai "^4.1.0"
chai-as-promised "^7.0.0"
chai-files "^1.0.0"
debug "^3.0.0"
ember-cli-internal-test-helpers "^0.9.1"
fs-extra "^4.0.0"
fs-extra "^5.0.0"
testdouble "^3.2.6"
tmp-sync "^1.0.0"

Expand Down Expand Up @@ -3540,7 +3540,7 @@ fs-extra@^0.30.0:
path-is-absolute "^1.0.0"
rimraf "^2.2.8"

fs-extra@^4.0.0, fs-extra@^4.0.2, fs-extra@^4.0.3:
fs-extra@^4.0.2, fs-extra@^4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.3.tgz#0d852122e5bc5beb453fb028e9c0c9bf36340c94"
dependencies:
Expand Down

0 comments on commit e349ec2

Please sign in to comment.