Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilize jscodeshift CLI results output #525

Merged
merged 15 commits into from
Apr 25, 2023
Prev Previous commit
Next Next commit
Fix tests
gitKrystan committed Apr 24, 2023
commit b250e7a3b14cb654a65109807bc2d56c5b43500c
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@
"lint:prettier:fix": "prettier --write .",
"lint:ts": "tsc --noEmit",
"test": "yarn build && codemod-cli test && node ./test/run-test.js && yarn clean",
"fixme": "rm codemods.log; yarn build && codemod-cli test -t string-boolean; yarn clean",
"fixme": "rm codemods.log; yarn build && codemod-cli test; yarn clean",
"dogfood": "rm codemods.log && yarn jscodeshift --transform ./transforms/ember-object/index.ts --verbose=2 ./transforms/ember-object/__testfixtures__/*.input.js",
"update-docs": "codemod-cli update-docs"
},
254 changes: 95 additions & 159 deletions test/options.test.ts
Original file line number Diff line number Diff line change
@@ -1,92 +1,70 @@
import { describe, expect, test } from '@jest/globals';
import { DEFAULT_OPTIONS, parseConfig } from '../transforms/helpers/options';
import { expectLogs, makeLogMatcher } from './helpers/expect-logs';
import { makeLogMatcher } from './helpers/expect-logs';

describe('options', () => {
describe('parseConfig', () => {
test('it parses an empty config', () => {
expectLogs(() => {
const config = parseConfig('test', {});
expect(config).toStrictEqual({});
});
const config = parseConfig('test', {});
expect(config).toStrictEqual({});
});

test('it parses the DEFAULT_OPTIONS', () => {
expectLogs(() => {
const config = parseConfig('test', DEFAULT_OPTIONS);
expect(config).toStrictEqual(DEFAULT_OPTIONS);
});
const config = parseConfig('test', DEFAULT_OPTIONS);
expect(config).toStrictEqual(DEFAULT_OPTIONS);
});

describe('decorators', () => {
test('it parses `{ decorators: true }`', () => {
expectLogs(() => {
const config = parseConfig('test', { decorators: true });
expect(config).toStrictEqual({
decorators: { inObjectLiterals: [] },
});
const config = parseConfig('test', { decorators: true });
expect(config).toStrictEqual({
decorators: { inObjectLiterals: [] },
});
});

test('it parses `{ decorators: "true" }`', () => {
expectLogs(() => {
const config = parseConfig('test', { decorators: 'true' });
expect(config).toStrictEqual({
decorators: { inObjectLiterals: [] },
});
const config = parseConfig('test', { decorators: 'true' });
expect(config).toStrictEqual({
decorators: { inObjectLiterals: [] },
});
});

test('it parses `{ decorators: false }`', () => {
expectLogs(() => {
const config = parseConfig('test', { decorators: false });
expect(config).toStrictEqual({ decorators: false });
});
const config = parseConfig('test', { decorators: false });
expect(config).toStrictEqual({ decorators: false });
});

test('it parses `{ decorators: "false" }`', () => {
expectLogs(() => {
const config = parseConfig('test', { decorators: 'false' });
expect(config).toStrictEqual({ decorators: false });
});
const config = parseConfig('test', { decorators: 'false' });
expect(config).toStrictEqual({ decorators: false });
});

test('it parses DecoratorOptions.inObjectLiterals with array of strings', () => {
expectLogs(() => {
const config = parseConfig('test', {
decorators: { inObjectLiterals: ['one', 'two', 'three'] },
});
expect(config).toStrictEqual({
decorators: { inObjectLiterals: ['one', 'two', 'three'] },
});
const config = parseConfig('test', {
decorators: { inObjectLiterals: ['one', 'two', 'three'] },
});
expect(config).toStrictEqual({
decorators: { inObjectLiterals: ['one', 'two', 'three'] },
});
});

test('it parses DecoratorOptions.inObjectLiterals with string of strings', () => {
expectLogs(() => {
const config = parseConfig('test', {
decorators: { inObjectLiterals: 'one,two , three' },
});
expect(config).toStrictEqual({
decorators: { inObjectLiterals: ['one', 'two', 'three'] },
});
const config = parseConfig('test', {
decorators: { inObjectLiterals: 'one,two , three' },
});
expect(config).toStrictEqual({
decorators: { inObjectLiterals: ['one', 'two', 'three'] },
});
});

test('it logs an error for invalid `decorators` config', () => {
expectLogs(
() => {
const config = parseConfig('test', { decorators: 'oops' });
expect(config).toStrictEqual({});
},
{
error: [
makeLogMatcher(
'[test]: CONFIG ERROR:',
"[decorators] Expected DecoratorOptions object or boolean, received 'oops'"
),
],
}
test('it errors for invalid `decorators` config', () => {
expect(() => parseConfig('test', { decorators: 'oops' })).toThrow(
new RegExp(
makeLogMatcher(
'test Config Error',
"[decorators] Expected DecoratorOptions object or boolean, received 'oops'"
)
)
);
});
});
@@ -95,129 +73,95 @@ describe('options', () => {
'%s (StringBooleanSchema)',
(fieldName) => {
test(`it parses \`{ ${fieldName}: true }\``, () => {
expectLogs(() => {
const config = parseConfig('test', { [fieldName]: true });
expect(config).toStrictEqual({ [fieldName]: true });
});
const config = parseConfig('test', { [fieldName]: true });
expect(config).toStrictEqual({ [fieldName]: true });
});

test(`it parses \`{ ${fieldName}: "true" }\``, () => {
expectLogs(() => {
const config = parseConfig('test', { [fieldName]: 'true' });
expect(config).toStrictEqual({ [fieldName]: true });
});
const config = parseConfig('test', { [fieldName]: 'true' });
expect(config).toStrictEqual({ [fieldName]: true });
});

test(`it parses \`{ ${fieldName}: false }\``, () => {
expectLogs(() => {
const config = parseConfig('test', { [fieldName]: false });
expect(config).toStrictEqual({ [fieldName]: false });
});
const config = parseConfig('test', { [fieldName]: false });
expect(config).toStrictEqual({ [fieldName]: false });
});

test(`it parses \`{ ${fieldName}: "false" }\``, () => {
expectLogs(() => {
const config = parseConfig('test', { [fieldName]: 'false' });
expect(config).toStrictEqual({ [fieldName]: false });
});
const config = parseConfig('test', { [fieldName]: 'false' });
expect(config).toStrictEqual({ [fieldName]: false });
});

test(`it logs an error for invalid \`${fieldName}\` config`, () => {
expectLogs(
() => {
const config = parseConfig('test', { [fieldName]: 'oops' });
expect(config).toStrictEqual({});
},
{
error: [
makeLogMatcher(
'[test]: CONFIG ERROR:',
`[${fieldName}] Expected boolean, received string`
),
],
}
test(`it errors for invalid \`${fieldName}\` config`, () => {
expect(() => parseConfig('test', { [fieldName]: 'oops' })).toThrow(
new RegExp(
makeLogMatcher(
'test Config Error',
`[${fieldName}] Expected boolean, received string`
)
)
);
});
}
);

describe('quote', () => {
test('it parses `{ quote: "single" }`', () => {
expectLogs(() => {
const config = parseConfig('test', { quote: 'single' });
expect(config).toStrictEqual({ quote: 'single' });
});
const config = parseConfig('test', { quote: 'single' });
expect(config).toStrictEqual({ quote: 'single' });
});

test('it parses `{ quote: "double" }`', () => {
expectLogs(() => {
const config = parseConfig('test', { quote: 'double' });
expect(config).toStrictEqual({ quote: 'double' });
});
});

test('it logs an error for invalid `quote` config', () => {
expectLogs(
() => {
const config = parseConfig('test', { quote: 'oops' });
expect(config).toStrictEqual({});
},
{
error: [
makeLogMatcher(
'[test]: CONFIG ERROR:',
"[quote] Expected 'single' or 'double', received 'oops"
),
],
}
const config = parseConfig('test', { quote: 'double' });
expect(config).toStrictEqual({ quote: 'double' });
});

test('it errors for invalid `quote` config', () => {
expect(() => parseConfig('test', { quote: 'oops' })).toThrow(
new RegExp(
makeLogMatcher(
'test Config Error',
"[quote] Expected 'single' or 'double', received 'oops"
)
)
);
});
});

describe('ignoreLeakingState', () => {
test('it parses `ignoreLeakingState` with an empty array', () => {
expectLogs(() => {
const config = parseConfig('test', { ignoreLeakingState: [] });
expect(config).toStrictEqual({ ignoreLeakingState: [] });
});
const config = parseConfig('test', { ignoreLeakingState: [] });
expect(config).toStrictEqual({ ignoreLeakingState: [] });
});

test('it parses `ignoreLeakingState` with array of strings', () => {
expectLogs(() => {
const config = parseConfig('test', {
ignoreLeakingState: ['one', 'two', 'three'],
});
expect(config).toStrictEqual({
ignoreLeakingState: ['one', 'two', 'three'],
});
const config = parseConfig('test', {
ignoreLeakingState: ['one', 'two', 'three'],
});
expect(config).toStrictEqual({
ignoreLeakingState: ['one', 'two', 'three'],
});
});

test('it parses `ignoreLeakingState` with string of strings', () => {
expectLogs(() => {
const config = parseConfig('test', {
ignoreLeakingState: 'one,two , three',
});
expect(config).toStrictEqual({
ignoreLeakingState: ['one', 'two', 'three'],
});
const config = parseConfig('test', {
ignoreLeakingState: 'one,two , three',
});
expect(config).toStrictEqual({
ignoreLeakingState: ['one', 'two', 'three'],
});
});

test('it logs an error for invalid `ignoreLeakingState` config', () => {
expectLogs(
() => {
const config = parseConfig('test', { ignoreLeakingState: false });
expect(config).toStrictEqual({});
},
{
error: [
makeLogMatcher(
'[test]: CONFIG ERROR:',
'[ignoreLeakingState] Expected array of strings or comma-separated string, received false'
),
],
}
test('it errors for invalid `ignoreLeakingState` config', () => {
expect(() =>
parseConfig('test', { ignoreLeakingState: false })
).toThrow(
new RegExp(
makeLogMatcher(
'test Config Error',
'[ignoreLeakingState] Expected array of strings or comma-separated string, received false'
)
)
);
});
});
@@ -226,27 +170,19 @@ describe('options', () => {
test.each(['services', 'routes', 'components', 'controllers'])(
'it parses `{ type: "%s" }`',
(type) => {
expectLogs(() => {
const config = parseConfig('test', { type });
expect(config).toStrictEqual({ type });
});
const config = parseConfig('test', { type });
expect(config).toStrictEqual({ type });
}
);

test('it logs an error for invalid `type` config', () => {
expectLogs(
() => {
const config = parseConfig('test', { type: 'oops' });
expect(config).toStrictEqual({});
},
{
error: [
makeLogMatcher(
'[test]: CONFIG ERROR:',
"[type] Expected 'services', 'routes', 'components', or 'controllers', received 'oops"
),
],
}
test('it errors for invalid `type` config', () => {
expect(() => parseConfig('test', { type: 'oops' })).toThrow(
new RegExp(
makeLogMatcher(
'test Config Error',
"[type] Expected 'services', 'routes', 'components', or 'controllers', received 'oops"
)
)
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Foo1 = EmberObject.extend({
actions: {
bar() {
this._super(...arguments);
this.get('bar')();
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Expect error:
ValidationError: Validation errors for class 'Foo1':
[actions]: Transform not supported - [bar]: calling the passed action would cause an infinite loop. See https://github.com/scalvert/eslint-plugin-ember-es6-class/pull/2 for more details
*/

const Foo1 = EmberObject.extend({
actions: {
bar() {
this._super(...arguments);
this.get('bar')();
},
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Foo2 = EmberObject.extend({
actions: {
biz() {
this._super(...arguments);
get(this, 'biz')();
},
},
});
Loading