Skip to content

Commit 7206ab2

Browse files
committed
Ember Data: transform and transform-test generators.
1 parent c950845 commit 7206ab2

File tree

10 files changed

+125
-13
lines changed

10 files changed

+125
-13
lines changed

blueprints/transform-test/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-env node */
2+
3+
var testInfo = require('ember-cli-test-info');
4+
var useTestFrameworkDetector = require('../test-framework-detector');
5+
6+
module.exports = useTestFrameworkDetector({
7+
description: 'Generates a transform unit test.',
8+
9+
locals: function(options) {
10+
return {
11+
friendlyTestDescription: testInfo.description(options.entity.name, "Unit", "Transform")
12+
};
13+
}
14+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupTest } from 'ember-mocha';
4+
5+
describe('<%= friendlyTestDescription %>', function() {
6+
setupTest('transform:<%= dasherizedModuleName %>', {
7+
// Specify the other units that are required for this test.
8+
// needs: ['transform:foo']
9+
});
10+
11+
// Replace this with your real tests.
12+
it('exists', function() {
13+
let transform = this.subject();
14+
expect(transform).to.be.ok;
15+
});
16+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { moduleFor, test } from 'ember-qunit';
2+
3+
moduleFor('transform:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', {
4+
// Specify the other units that are required for this test.
5+
// needs: ['serializer:foo']
6+
});
7+
8+
// Replace this with your real tests.
9+
test('it exists', function(assert) {
10+
let transform = this.subject();
11+
assert.ok(transform);
12+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('transform:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', function(hooks) {
5+
setupTest(hooks);
6+
7+
// Replace this with your real tests.
8+
test('it exists', function(assert) {
9+
let transform = this.owner.lookup('transform:<%= dasherizedModuleName %>');
10+
assert.ok(transform);
11+
});
12+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import DS from 'ember-data';
2+
3+
export default DS.Transform.extend({
4+
deserialize(serialized) {
5+
return serialized;
6+
},
7+
8+
serialize(deserialized) {
9+
return deserialized;
10+
}
11+
});

blueprints/transform/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* eslint-env node */
2+
3+
module.exports = {
4+
description: 'Generates an ember-data value transform.'
5+
};

node-tests/blueprints/transform-test.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,29 @@ describe('Acceptance: generate and destroy transform blueprints', function() {
2020
return emberNew();
2121
});
2222

23-
2423
it('transform', function() {
2524
let args = ['transform', 'foo'];
2625

2726
return emberGenerateDestroy(args, _file => {
28-
expect(_file('app/transforms/foo.js'))
29-
.to.contain('import DS from \'ember-data\';')
27+
expect(_file('app/transforms/foo.ts'))
28+
.to.contain("import DS from 'ember-data';")
3029
.to.contain('export default DS.Transform.extend(')
3130
.to.contain('deserialize(serialized) {')
3231
.to.contain('serialize(deserialized) {');
3332

34-
expect(_file('tests/unit/transforms/foo-test.js'))
35-
.to.equal(fixture('transform-test/default.js'));
33+
expect(_file('tests/unit/transforms/foo-test.ts')).to.equal(
34+
fixture('transform-test/default.ts')
35+
);
3636
});
3737
});
3838

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

4242
return emberGenerateDestroy(args, _file => {
43-
expect(_file('tests/unit/transforms/foo-test.js'))
44-
.to.equal(fixture('transform-test/default.js'));
43+
expect(_file('tests/unit/transforms/foo-test.ts')).to.equal(
44+
fixture('transform-test/default.ts')
45+
);
4546
});
4647
});
4748

@@ -52,18 +53,18 @@ describe('Acceptance: generate and destroy transform blueprints', function() {
5253

5354
it('transform-test-test foo', function() {
5455
return emberGenerateDestroy(['transform-test', 'foo'], _file => {
55-
expect(_file('tests/unit/transforms/foo-test.js'))
56-
.to.equal(fixture('transform-test/rfc232.js'));
56+
expect(_file('tests/unit/transforms/foo-test.ts')).to.equal(
57+
fixture('transform-test/rfc232.ts')
58+
);
5759
});
5860
});
5961
});
6062

61-
6263
describe('with ember-cli-mocha v0.12+', function() {
6364
beforeEach(function() {
6465
modifyPackages([
6566
{ name: 'ember-cli-qunit', delete: true },
66-
{ name: 'ember-cli-mocha', dev: true }
67+
{ name: 'ember-cli-mocha', dev: true },
6768
]);
6869
generateFakePackageManifest('ember-cli-mocha', '0.12.0');
6970
});
@@ -72,8 +73,9 @@ describe('Acceptance: generate and destroy transform blueprints', function() {
7273
let args = ['transform-test', 'foo'];
7374

7475
return emberGenerateDestroy(args, _file => {
75-
expect(_file('tests/unit/transforms/foo-test.js'))
76-
.to.equal(fixture('transform-test/mocha-0.12.js'));
76+
expect(_file('tests/unit/transforms/foo-test.ts')).to.equal(
77+
fixture('transform-test/mocha-0.12.ts')
78+
);
7779
});
7880
});
7981
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { moduleFor, test } from 'ember-qunit';
2+
3+
moduleFor('transform:foo', 'Unit | Transform | foo', {
4+
// Specify the other units that are required for this test.
5+
// needs: ['serializer:foo']
6+
});
7+
8+
// Replace this with your real tests.
9+
test('it exists', function(assert) {
10+
let transform = this.subject();
11+
assert.ok(transform);
12+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupTest } from 'ember-mocha';
4+
5+
describe('Unit | Transform | foo', function() {
6+
setupTest('transform:foo', {
7+
// Specify the other units that are required for this test.
8+
// needs: ['transform:foo']
9+
});
10+
11+
// Replace this with your real tests.
12+
it('exists', function() {
13+
let transform = this.subject();
14+
expect(transform).to.be.ok;
15+
});
16+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('transform:foo', 'Unit | Transform | foo', function(hooks) {
5+
setupTest(hooks);
6+
7+
// Replace this with your real tests.
8+
test('it exists', function(assert) {
9+
let transform = this.owner.lookup('transform:foo');
10+
assert.ok(transform);
11+
});
12+
});

0 commit comments

Comments
 (0)