Skip to content

Commit d03ba9a

Browse files
author
Robert Jackson
authored
Merge pull request #19 from ember-codemods/fixup-tests
2 parents a747699 + 86c3cc2 commit d03ba9a

File tree

4 files changed

+165
-115
lines changed

4 files changed

+165
-115
lines changed

test/fixtures/addon/example-js/classic-to-nested.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ module.exports = {
6565
'layout-property-classic': {
6666
'index.js': [
6767
'import Component from "@ember/component";',
68-
'export default Component.extend({});',
68+
'import SomeMixin from "my-addon/mixins/whatever";',
69+
'export default Component.extend(SomeMixin, {});',
6970
].join('\n'),
7071
'index.hbs': '{{!-- layout-property-classic.hbs --}}',
7172
},
@@ -87,16 +88,17 @@ module.exports = {
8788
},
8889

8990
// A template imported into multiple component classes
90-
'first-repeated-import': [
91-
'// first-repeated-import.ts',
91+
'first-repeated-import.js': [
92+
'// first-repeated-import.js',
9293
'import Component from "@ember/component"',
9394
'import { layout } from "@ember-decorators/component";',
9495
'import template from "my-addon/templates/components/repeatedly-imported";',
9596
'@layout(template)',
9697
'export default class FirstRepeatedImport extends Component {}',
9798
].join('\n'),
98-
'second-repeated-import': [
99-
'// second-repeated-import.ts',
99+
100+
'second-repeated-import.js': [
101+
'// second-repeated-import.js',
100102
'import Component from "@ember/component"',
101103
'import { layout } from "@ember-decorators/component";',
102104
'import template from "my-addon/templates/components/repeatedly-imported";',

test/fixtures/addon/example-ts/classic-to-nested.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,49 @@ module.exports = {
5050
].join('\n'),
5151
},
5252

53+
'layout-decorator': {
54+
'index.hbs': '{{!-- layout-decorator-template.hbs --}}',
55+
'index.ts': [
56+
'import Component from "@ember/component";',
57+
'export default class LayoutDecorator extends Component {}',
58+
].join('\n'),
59+
},
60+
61+
'layout-property-classic': {
62+
'index.hbs': '{{!-- layout-property-classic.hbs --}}',
63+
'index.ts': [
64+
'import Component from "@ember/component";',
65+
'import SomeMixin from "my-addon/mixins/whatever";',
66+
'export default Component.extend(SomeMixin, {});',
67+
].join('\n'),
68+
},
69+
70+
'layout-property-native': {
71+
'index.hbs': '{{!-- layout-property-native.hbs --}}',
72+
'index.ts': [
73+
'import Component from "@ember/component";',
74+
'export default class NativeProperty extends Component {}',
75+
].join('\n'),
76+
},
77+
78+
// A template imported into multiple component classes
79+
'first-repeated-import.ts': [
80+
'// first-repeated-import.ts',
81+
'import Component from "@ember/component"',
82+
'import { layout } from "@ember-decorators/component";',
83+
'import template from "my-addon/templates/components/repeatedly-imported";',
84+
'@layout(template)',
85+
'export default class FirstRepeatedImport extends Component {}',
86+
].join('\n'),
87+
'second-repeated-import.ts': [
88+
'// second-repeated-import.ts',
89+
'import Component from "@ember/component"',
90+
'import { layout } from "@ember-decorators/component";',
91+
'import template from "my-addon/templates/components/repeatedly-imported";',
92+
'@layout(template)',
93+
'export default class SecondRepeatedImport extends Component {}',
94+
].join('\n'),
95+
5396
// A component with partial
5497
partials: {
5598
'with-partial': {
@@ -78,6 +121,7 @@ module.exports = {
78121
'partial-two-template.hbs': '{{!-- partial-two-template.hbs --}}',
79122
'-partial-three-template.hbs': '{{!-- partial-three-template.hbs --}}',
80123
},
124+
'repeatedly-imported.hbs': '{{!-- repeatedly-imported.hbs --}}',
81125
},
82126
},
83127
},

test/fixtures/app/example-js/classic-to-nested.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ module.exports = {
9696
'partial-two-template.hbs': '{{!-- partial-two-template.hbs --}}',
9797
'-partial-three-template.hbs': '{{!-- partial-three-template.hbs --}}',
9898
},
99-
},
10099

101-
'repeatedly-imported.hbs': '{{!-- repeatedly-imported.hbs --}}',
100+
'repeatedly-imported.hbs': '{{!-- repeatedly-imported.hbs --}}',
101+
},
102102
},
103103
},
104104
};
Lines changed: 112 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,165 @@
1-
//const assertDiff = require('assert-diff');
1+
const assertDiff = require('assert-diff');
22
const fse = require('fs-extra');
3-
//const path = require('path');
4-
//const Migrator = require('../../../lib/migrator');
3+
const fixturify = require('fixturify');
4+
const path = require('path');
5+
const Migrator = require('../../../lib/migrator');
6+
const { setupConsole, resetConsole } = require('../../helpers');
57

6-
//assertDiff.options.strict = true;
8+
assertDiff.options.strict = true;
79

810
describe('structure = nested', function () {
911
beforeEach(function () {
1012
this.tmpPath = 'tmp/process-files';
1113
fse.mkdirsSync(this.tmpPath);
14+
setupConsole();
1215
});
1316

1417
afterEach(function () {
1518
fse.removeSync(this.tmpPath);
19+
resetConsole();
1620
});
1721

18-
// describe('For an app with component classes written in JavaScript', function() {
19-
// beforeEach(function() {
20-
// const fixturePath = path.resolve(__dirname, '../../fixtures/app/example-js');
22+
describe('For an app with component classes written in JavaScript', function () {
23+
beforeEach(function () {
24+
const fixturePath = path.resolve(__dirname, '../../fixtures/app/example-js');
2125

22-
// // Find input and output files
23-
// const input = require(`${fixturePath}/input`);
24-
// this.expectedOutput = require(`${fixturePath}/classic-to-nested`);
26+
// Find input and output files
27+
const input = require(`${fixturePath}/input`);
28+
this.expectedOutput = require(`${fixturePath}/classic-to-nested`);
2529

26-
// // Copy the input file to the temporary folder
27-
// fixturify.writeSync(this.tmpPath, input);
30+
// Copy the input file to the temporary folder
31+
fixturify.writeSync(this.tmpPath, input);
2832

29-
// // Create an instance of the Migrator class
30-
// this.migrator = new Migrator({
31-
// projectRoot: this.tmpPath,
32-
// structure: 'nested'
33-
// });
34-
// });
33+
// Create an instance of the Migrator class
34+
this.migrator = new Migrator({
35+
projectRoot: this.tmpPath,
36+
structure: 'nested',
37+
});
38+
});
3539

36-
// it('Codemod works as expected', async function() {
37-
// await this.migrator.execute();
40+
it('Codemod works as expected', async function () {
41+
await this.migrator.execute();
3842

39-
// const actualOutput = fixturify.readSync(this.tmpPath);
43+
const actualOutput = fixturify.readSync(this.tmpPath);
4044

41-
// assertDiff.deepEqual(actualOutput, this.expectedOutput);
42-
// });
45+
assertDiff.deepEqual(actualOutput, this.expectedOutput);
46+
});
4347

44-
// it('Codemod is idempotent', async function() {
45-
// await this.migrator.execute();
46-
// await this.migrator.execute();
48+
it('Codemod is idempotent', async function () {
49+
await this.migrator.execute();
50+
await this.migrator.execute();
4751

48-
// const actualOutput = fixturify.readSync(this.tmpPath);
52+
const actualOutput = fixturify.readSync(this.tmpPath);
4953

50-
// assertDiff.deepEqual(actualOutput, this.expectedOutput);
51-
// });
52-
// });
54+
assertDiff.deepEqual(actualOutput, this.expectedOutput);
55+
});
56+
});
5357

54-
// describe('For an app with component classes written in TypeScript', function() {
55-
// beforeEach(function() {
56-
// const fixturePath = path.resolve(__dirname, '../../fixtures/app/example-ts');
58+
describe('For an app with component classes written in TypeScript', function () {
59+
beforeEach(function () {
60+
const fixturePath = path.resolve(__dirname, '../../fixtures/app/example-ts');
5761

58-
// // Find input and output files
59-
// const input = require(`${fixturePath}/input`);
60-
// this.expectedOutput = require(`${fixturePath}/classic-to-nested`);
62+
// Find input and output files
63+
const input = require(`${fixturePath}/input`);
64+
this.expectedOutput = require(`${fixturePath}/classic-to-nested`);
6165

62-
// // Copy the input file to the temporary folder
63-
// fixturify.writeSync(this.tmpPath, input);
66+
// Copy the input file to the temporary folder
67+
fixturify.writeSync(this.tmpPath, input);
6468

65-
// // Create an instance of the Migrator class
66-
// this.migrator = new Migrator({
67-
// projectRoot: this.tmpPath,
68-
// structure: 'nested'
69-
// });
70-
// });
69+
// Create an instance of the Migrator class
70+
this.migrator = new Migrator({
71+
projectRoot: this.tmpPath,
72+
structure: 'nested',
73+
});
74+
});
7175

72-
// it('Codemod works as expected', async function() {
73-
// await this.migrator.execute();
76+
it('Codemod works as expected', async function () {
77+
await this.migrator.execute();
7478

75-
// const actualOutput = fixturify.readSync(this.tmpPath);
79+
const actualOutput = fixturify.readSync(this.tmpPath);
7680

77-
// assertDiff.deepEqual(actualOutput, this.expectedOutput);
78-
// });
81+
assertDiff.deepEqual(actualOutput, this.expectedOutput);
82+
});
7983

80-
// it('Codemod is idempotent', async function() {
81-
// await this.migrator.execute();
82-
// await this.migrator.execute();
84+
it('Codemod is idempotent', async function () {
85+
await this.migrator.execute();
86+
await this.migrator.execute();
8387

84-
// const actualOutput = fixturify.readSync(this.tmpPath);
88+
const actualOutput = fixturify.readSync(this.tmpPath);
8589

86-
// assertDiff.deepEqual(actualOutput, this.expectedOutput);
87-
// });
88-
// });
90+
assertDiff.deepEqual(actualOutput, this.expectedOutput);
91+
});
92+
});
8993

90-
// describe('For an addon with component classes written in JavaScript', function() {
91-
// beforeEach(function() {
92-
// const fixturePath = path.resolve(__dirname, '../../fixtures/addon/example-js');
94+
describe('For an addon with component classes written in JavaScript', function () {
95+
beforeEach(function () {
96+
const fixturePath = path.resolve(__dirname, '../../fixtures/addon/example-js');
9397

94-
// // Find input and output files
95-
// const input = require(`${fixturePath}/input`);
96-
// this.expectedOutput = require(`${fixturePath}/classic-to-nested`);
98+
// Find input and output files
99+
const input = require(`${fixturePath}/input`);
100+
this.expectedOutput = require(`${fixturePath}/classic-to-nested`);
97101

98-
// // Copy the input file to the temporary folder
99-
// fixturify.writeSync(this.tmpPath, input);
102+
// Copy the input file to the temporary folder
103+
fixturify.writeSync(this.tmpPath, input);
100104

101-
// // Create an instance of the Migrator class
102-
// this.migrator = new Migrator({
103-
// projectRoot: this.tmpPath,
104-
// structure: 'nested'
105-
// });
106-
// });
105+
// Create an instance of the Migrator class
106+
this.migrator = new Migrator({
107+
projectRoot: this.tmpPath,
108+
structure: 'nested',
109+
});
110+
});
107111

108-
// it('Codemod works as expected', async function() {
109-
// await this.migrator.execute();
112+
it('Codemod works as expected', async function () {
113+
await this.migrator.execute();
110114

111-
// const actualOutput = fixturify.readSync(this.tmpPath);
115+
const actualOutput = fixturify.readSync(this.tmpPath);
112116

113-
// assertDiff.deepEqual(actualOutput, this.expectedOutput);
114-
// });
117+
assertDiff.deepEqual(actualOutput, this.expectedOutput);
118+
});
115119

116-
// it('Codemod is idempotent', async function() {
117-
// await this.migrator.execute();
118-
// await this.migrator.execute();
120+
it('Codemod is idempotent', async function () {
121+
await this.migrator.execute();
122+
await this.migrator.execute();
119123

120-
// const actualOutput = fixturify.readSync(this.tmpPath);
124+
const actualOutput = fixturify.readSync(this.tmpPath);
121125

122-
// assertDiff.deepEqual(actualOutput, this.expectedOutput);
123-
// });
124-
// });
126+
assertDiff.deepEqual(actualOutput, this.expectedOutput);
127+
});
128+
});
125129

126-
// describe('For an addon with component classes written in TypeScript', function() {
127-
// beforeEach(function() {
128-
// const fixturePath = path.resolve(__dirname, '../../fixtures/addon/example-ts');
130+
describe('For an addon with component classes written in TypeScript', function () {
131+
beforeEach(function () {
132+
const fixturePath = path.resolve(__dirname, '../../fixtures/addon/example-ts');
129133

130-
// // Find input and output files
131-
// const input = require(`${fixturePath}/input`);
132-
// this.expectedOutput = require(`${fixturePath}/classic-to-nested`);
134+
// Find input and output files
135+
const input = require(`${fixturePath}/input`);
136+
this.expectedOutput = require(`${fixturePath}/classic-to-nested`);
133137

134-
// // Copy the input file to the temporary folder
135-
// fixturify.writeSync(this.tmpPath, input);
138+
// Copy the input file to the temporary folder
139+
fixturify.writeSync(this.tmpPath, input);
136140

137-
// // Create an instance of the Migrator class
138-
// this.migrator = new Migrator({
139-
// projectRoot: this.tmpPath,
140-
// structure: 'nested'
141-
// });
142-
// });
141+
// Create an instance of the Migrator class
142+
this.migrator = new Migrator({
143+
projectRoot: this.tmpPath,
144+
structure: 'nested',
145+
});
146+
});
143147

144-
// it('Codemod works as expected', async function() {
145-
// await this.migrator.execute();
148+
it('Codemod works as expected', async function () {
149+
await this.migrator.execute();
146150

147-
// const actualOutput = fixturify.readSync(this.tmpPath);
151+
const actualOutput = fixturify.readSync(this.tmpPath);
148152

149-
// assertDiff.deepEqual(actualOutput, this.expectedOutput);
150-
// });
153+
assertDiff.deepEqual(actualOutput, this.expectedOutput);
154+
});
151155

152-
// it('Codemod is idempotent', async function() {
153-
// await this.migrator.execute();
154-
// await this.migrator.execute();
156+
it('Codemod is idempotent', async function () {
157+
await this.migrator.execute();
158+
await this.migrator.execute();
155159

156-
// const actualOutput = fixturify.readSync(this.tmpPath);
160+
const actualOutput = fixturify.readSync(this.tmpPath);
157161

158-
// assertDiff.deepEqual(actualOutput, this.expectedOutput);
159-
// });
160-
// });
162+
assertDiff.deepEqual(actualOutput, this.expectedOutput);
163+
});
164+
});
161165
});

0 commit comments

Comments
 (0)