Skip to content

Commit bb0d2d5

Browse files
committed
fixing lints and updating tests to be insensitive to non-semantic code changes
1 parent f6dd1ae commit bb0d2d5

11 files changed

+254
-254
lines changed

node-tests/assertions.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const { Assertion, expect } = require('chai');
2+
const { codeEqual } = require('code-equality-assertions');
3+
4+
// code-equality-assertions comes with integrations for qunit and jest. This
5+
// test suite was using a mix of chai and Node build-in assert.
6+
7+
function assertEqualCode(actual, expected, message = '') {
8+
let status = codeEqual(actual, expected);
9+
this.assert(status.result, message + status.diff);
10+
}
11+
12+
Assertion.addMethod('toEqualCode', function (expectedSrc) {
13+
assertEqualCode.call(this, this._obj, expectedSrc);
14+
});
15+
16+
// need this because there are tests for coffeescript 🙄
17+
function simpleNormalize(s) {
18+
return s.trim().replace(/\n\s+/g, '\n');
19+
}
20+
21+
function assertNonJSEqual(actual, expected, message) {
22+
actual = simpleNormalize(actual);
23+
expected = simpleNormalize(expected);
24+
this.assert(actual === expected, message, message, actual, expected);
25+
}
26+
27+
function deepEqualCode(actual, expected, message = '') {
28+
for (let [key, value] of Object.entries(expected)) {
29+
if (typeof value === 'string') {
30+
if (key.endsWith('.js') || key.endsWith('.ts')) {
31+
assertEqualCode.call(this, actual[key], value, `${message}->${key}`);
32+
} else {
33+
assertNonJSEqual.call(this, actual[key], value, `${message}->${key}`);
34+
}
35+
} else {
36+
deepEqualCode.call(this, actual[key], value, `${message}->${key}`);
37+
}
38+
}
39+
}
40+
41+
Assertion.addMethod('toDeepEqualCode', function (expectedTree) {
42+
deepEqualCode.call(this, this._obj, expectedTree);
43+
});
44+
45+
exports.expect = expect;

node-tests/colocated-babel-plugin-test.js

Lines changed: 37 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
'use strict';
22

3-
const assert = require('assert');
43
const babel = require('@babel/core');
5-
const { stripIndent } = require('common-tags');
64
const ColocatedBabelPlugin = require('../lib/colocated-babel-plugin');
5+
const { expect } = require('./assertions');
76
const DecoratorsPlugin = [
87
require.resolve('@babel/plugin-proposal-decorators'),
98
{ legacy: true },
@@ -35,7 +34,7 @@ describe('ColocatedBabelPlugin', function () {
3534

3635
it('can be used with decorators', function () {
3736
let { code } = babel.transformSync(
38-
stripIndent`
37+
`
3938
import Component from '@glimmer/component';
4039
const __COLOCATED_TEMPLATE__ = 'ok';
4140
@@ -53,9 +52,8 @@ describe('ColocatedBabelPlugin', function () {
5352
},
5453
);
5554

56-
assert.strictEqual(
57-
code,
58-
stripIndent`
55+
expect(code).toEqualCode(
56+
`
5957
import _initializerDefineProperty from "@babel/runtime/helpers/esm/initializerDefineProperty";
6058
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
6159
import _initializerWarningHelper from "@babel/runtime/helpers/esm/initializerWarningHelper";
@@ -89,7 +87,7 @@ describe('ColocatedBabelPlugin', function () {
8987

9088
it('can be used with TypeScript merged declarations', function () {
9189
let { code } = babel.transformSync(
92-
stripIndent`
90+
`
9391
import Component from 'somewhere';
9492
const __COLOCATED_TEMPLATE__ = 'ok';
9593
type MyArgs = { required: string; optional?: number };
@@ -100,9 +98,8 @@ describe('ColocatedBabelPlugin', function () {
10098
{ plugins: [ColocatedBabelPluginOptions, TypeScriptPlugin] },
10199
);
102100

103-
assert.strictEqual(
104-
code,
105-
stripIndent`
101+
expect(code).toEqualCode(
102+
`
106103
import Component from 'somewhere';
107104
const __COLOCATED_TEMPLATE__ = 'ok';
108105
export default class MyComponent extends Component {}
@@ -114,17 +111,16 @@ describe('ColocatedBabelPlugin', function () {
114111

115112
it('sets the template for non-class default exports', function () {
116113
let { code } = babel.transformSync(
117-
stripIndent`
114+
`
118115
import MyComponent from 'other-module';
119116
const __COLOCATED_TEMPLATE__ = 'ok';
120117
export default MyComponent;
121118
`,
122119
{ plugins: [ColocatedBabelPluginOptions] },
123120
);
124121

125-
assert.strictEqual(
126-
code,
127-
stripIndent`
122+
expect(code).toEqualCode(
123+
`
128124
import MyComponent from 'other-module';
129125
const __COLOCATED_TEMPLATE__ = 'ok';
130126
export default Ember._setComponentTemplate(__COLOCATED_TEMPLATE__, MyComponent);
@@ -134,17 +130,16 @@ describe('ColocatedBabelPlugin', function () {
134130

135131
it('sets the template for named class default exports', function () {
136132
let { code } = babel.transformSync(
137-
stripIndent`
133+
`
138134
import Component from 'somewhere';
139135
const __COLOCATED_TEMPLATE__ = 'ok';
140136
export default class MyComponent extends Component {}
141137
`,
142138
{ plugins: [ColocatedBabelPluginOptions] },
143139
);
144140

145-
assert.strictEqual(
146-
code,
147-
stripIndent`
141+
expect(code).toEqualCode(
142+
`
148143
import Component from 'somewhere';
149144
const __COLOCATED_TEMPLATE__ = 'ok';
150145
export default class MyComponent extends Component {}
@@ -156,17 +151,16 @@ describe('ColocatedBabelPlugin', function () {
156151

157152
it('sets the template for anonymous class default exports', function () {
158153
let { code } = babel.transformSync(
159-
stripIndent`
154+
`
160155
import Component from 'somewhere';
161156
const __COLOCATED_TEMPLATE__ = 'ok';
162157
export default class extends Component {}
163158
`,
164159
{ plugins: [ColocatedBabelPluginOptions] },
165160
);
166161

167-
assert.strictEqual(
168-
code,
169-
stripIndent`
162+
expect(code).toEqualCode(
163+
`
170164
import Component from 'somewhere';
171165
const __COLOCATED_TEMPLATE__ = 'ok';
172166
export default Ember._setComponentTemplate(__COLOCATED_TEMPLATE__, class extends Component {});
@@ -176,7 +170,7 @@ describe('ColocatedBabelPlugin', function () {
176170

177171
it('sets the template for identifier `as default` exports', function () {
178172
let { code } = babel.transformSync(
179-
stripIndent`
173+
`
180174
import Component from 'somewhere';
181175
const __COLOCATED_TEMPLATE__ = 'ok';
182176
const MyComponent = class extends Component {};
@@ -185,9 +179,8 @@ describe('ColocatedBabelPlugin', function () {
185179
{ plugins: [ColocatedBabelPluginOptions] },
186180
);
187181

188-
assert.strictEqual(
189-
code,
190-
stripIndent`
182+
expect(code).toEqualCode(
183+
`
191184
import Component from 'somewhere';
192185
const __COLOCATED_TEMPLATE__ = 'ok';
193186
const MyComponent = class extends Component {};
@@ -207,7 +200,7 @@ describe('ColocatedBabelPlugin', function () {
207200

208201
it('can be used with decorators', function () {
209202
let { code } = babel.transformSync(
210-
stripIndent`
203+
`
211204
import Component from '@glimmer/component';
212205
const __COLOCATED_TEMPLATE__ = 'ok';
213206
@@ -225,9 +218,8 @@ describe('ColocatedBabelPlugin', function () {
225218
},
226219
);
227220

228-
assert.strictEqual(
229-
code,
230-
stripIndent`
221+
expect(code).toEqualCode(
222+
`
231223
import _initializerDefineProperty from "@babel/runtime/helpers/esm/initializerDefineProperty";
232224
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
233225
import _initializerWarningHelper from "@babel/runtime/helpers/esm/initializerWarningHelper";
@@ -262,7 +254,7 @@ describe('ColocatedBabelPlugin', function () {
262254

263255
it('can be used with TypeScript merged declarations', function () {
264256
let { code } = babel.transformSync(
265-
stripIndent`
257+
`
266258
import Component from 'somewhere';
267259
const __COLOCATED_TEMPLATE__ = 'ok';
268260
type MyArgs = { required: string; optional?: number };
@@ -273,9 +265,8 @@ describe('ColocatedBabelPlugin', function () {
273265
{ plugins: [ColocatedBabelPluginOptions, TypeScriptPlugin] },
274266
);
275267

276-
assert.strictEqual(
277-
code,
278-
stripIndent`
268+
expect(code).toEqualCode(
269+
`
279270
import { setComponentTemplate as _setComponentTemplate } from "@ember/component";
280271
import Component from 'somewhere';
281272
const __COLOCATED_TEMPLATE__ = 'ok';
@@ -288,17 +279,16 @@ describe('ColocatedBabelPlugin', function () {
288279

289280
it('sets the template for non-class default exports', function () {
290281
let { code } = babel.transformSync(
291-
stripIndent`
282+
`
292283
import MyComponent from 'other-module';
293284
const __COLOCATED_TEMPLATE__ = 'ok';
294285
export default MyComponent;
295286
`,
296287
{ plugins: [ColocatedBabelPluginOptions] },
297288
);
298289

299-
assert.strictEqual(
300-
code,
301-
stripIndent`
290+
expect(code).toEqualCode(
291+
`
302292
import { setComponentTemplate as _setComponentTemplate } from "@ember/component";
303293
import MyComponent from 'other-module';
304294
const __COLOCATED_TEMPLATE__ = 'ok';
@@ -309,17 +299,16 @@ describe('ColocatedBabelPlugin', function () {
309299

310300
it('sets the template for named class default exports', function () {
311301
let { code } = babel.transformSync(
312-
stripIndent`
302+
`
313303
import Component from 'somewhere';
314304
const __COLOCATED_TEMPLATE__ = 'ok';
315305
export default class MyComponent extends Component {}
316306
`,
317307
{ plugins: [ColocatedBabelPluginOptions] },
318308
);
319309

320-
assert.strictEqual(
321-
code,
322-
stripIndent`
310+
expect(code).toEqualCode(
311+
`
323312
import { setComponentTemplate as _setComponentTemplate } from "@ember/component";
324313
import Component from 'somewhere';
325314
const __COLOCATED_TEMPLATE__ = 'ok';
@@ -332,17 +321,16 @@ describe('ColocatedBabelPlugin', function () {
332321

333322
it('sets the template for anonymous class default exports', function () {
334323
let { code } = babel.transformSync(
335-
stripIndent`
324+
`
336325
import Component from 'somewhere';
337326
const __COLOCATED_TEMPLATE__ = 'ok';
338327
export default class extends Component {}
339328
`,
340329
{ plugins: [ColocatedBabelPluginOptions] },
341330
);
342331

343-
assert.strictEqual(
344-
code,
345-
stripIndent`
332+
expect(code).toEqualCode(
333+
`
346334
import { setComponentTemplate as _setComponentTemplate } from "@ember/component";
347335
import Component from 'somewhere';
348336
const __COLOCATED_TEMPLATE__ = 'ok';
@@ -353,7 +341,7 @@ describe('ColocatedBabelPlugin', function () {
353341

354342
it('sets the template for identifier `as default` exports', function () {
355343
let { code } = babel.transformSync(
356-
stripIndent`
344+
`
357345
import Component from 'somewhere';
358346
const __COLOCATED_TEMPLATE__ = 'ok';
359347
const MyComponent = class extends Component {};
@@ -362,9 +350,8 @@ describe('ColocatedBabelPlugin', function () {
362350
{ plugins: [ColocatedBabelPluginOptions] },
363351
);
364352

365-
assert.strictEqual(
366-
code,
367-
stripIndent`
353+
expect(code).toEqualCode(
354+
`
368355
import { setComponentTemplate as _setComponentTemplate } from "@ember/component";
369356
import Component from 'somewhere';
370357
const __COLOCATED_TEMPLATE__ = 'ok';

0 commit comments

Comments
 (0)