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

fix: resolve TypeScript and Jest test issues in transform tests #333

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@
"jscodeshift": "jscodeshift"
},
"dependencies": {
"@codemod.com/codemod-utils": "^1.0.0",
"@types/jscodeshift": "^0.12.0",
"chalk": "^2.4.2",
"eslint": "^6.6.0",
"execa": "^3.2.0",
"globby": "^10.0.1",
"inquirer": "^7.0.0",
"is-git-clean": "^1.1.0",
"jscodeshift": "^0.11.0",
"jscodeshift": "^17.3.0",
"meow": "^5.0.0"
},
"jest": {
"globals": {
"baseDir": "../"
"baseDir": "../",
"ts-jest": {
"tsconfig": "./tsconfig.codemod.json"
}
},
"testEnvironment": "node",
"roots": [
Expand All @@ -32,13 +37,21 @@
"transform": {
"^.+\\.jsx?$": "babel-jest",
"^.+\\.tsx?$": "ts-jest"
},
"transformIgnorePatterns": [
"/node_modules/(?!@codemod\\.com/codemod-utils)/.+\\.js$"
],
"moduleNameMapper": {
"^@codemod\\.com/codemod-utils$": "<rootDir>/node_modules/@codemod.com/codemod-utils/dist/index.cjs"
}
},
"devDependencies": {
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
"@babel/preset-env": "^7.6.3",
"@jest/globals": "^29.7.0",
"@types/jest": "^24.9.0",
"@types/node": "^22.12.0",
"@typescript-eslint/parser": "^7.8.0",
"babel-eslint": "^10.0.3",
"babel-jest": "^24.9.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ var React = require('react');

const render = () => {
return (
/*1*//*4*//*2*//*3*/<div
/*1*//*2*//*3*/<div
/*8*/className/*9*/=/*10*/"foo"/*11*/
/*12*/
/*13*///17
onClick/*14*/={/*15*/ this.handleClick}/*16*/>
{/*19*///25
<TodoList.Item />/*24*//*20*//*23*//*21*//*22*//*20*//*23*//*21*//*22*//*21*//*22*/}
<span {.../*26*/getProps()/*27*/} />
{/*18*//*19*/<TodoList.Item />/*24*//*20*//*23*//*21*//*22*//*20*//*23*//*21*//*22*//*21*//*22*/}
{//25
<span {.../*26*/getProps()/*27*/} />}
{<input /> /*28*//*29*/}
</div>
/*5*//*6*//*7*//*18*/
</div>/*4*/
/*5*//*6*//*7*/
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ function App({ url }: { url: string }) {
<Page />
</Context>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ function App({ url }: { url: string }) {

return (
<Context.Provider value={theme}>
<Page />
</Context.Provider>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ function App({ url }: { url: string }) {

return (
<Context value={theme}>
<Page />
</Context>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ function App({ url }: { url: string }) {
<Page />
</ThemeContext.Provider>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ function App({ url }: { url: string }) {
<Page />
</ThemeContext>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ function App() {

return (
<Context.Provider value={theme}>
<Page />
</Context.Provider>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ function App() {

return (
<Context value={theme}>
<Page />
</Context>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const MyComponent = function Component(
ref: myRef,
...myProps
}: { a: 1 } & {
ref: React.RefObject<unknown>
ref: React.RefObject<unknown>;
}
) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const MyComponent = function Component(
ref: myRef,
...myProps
}: Props & {
ref: React.RefObject<HTMLButtonElement>
ref: React.RefObject<HTMLButtonElement>;
}
) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const MyInput = (
ref,
...props
}: { a: string } & {
ref: React.RefObject<RefValueType>
ref: React.RefObject<RefValueType>;
}
) => {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const MyInput = (
ref,
...props
}: Props & {
ref: React.RefObject<HTMLInputElement>
ref: React.RefObject<HTMLInputElement>;
}
) => {
return null;
Expand Down
2 changes: 1 addition & 1 deletion transforms/__tests__/React-PropTypes-to-prop-types-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'use strict';

jest.mock('../React-PropTypes-to-prop-types', () => {
return Object.assign(require.requireActual('../React-PropTypes-to-prop-types'), {
return Object.assign(jest.requireActual('../React-PropTypes-to-prop-types'), {
parser: 'flow'
});
});
Expand Down
2 changes: 1 addition & 1 deletion transforms/__tests__/ReactNative-View-propTypes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'use strict';

jest.mock('../ReactNative-View-propTypes', () => {
return Object.assign(require.requireActual('../ReactNative-View-propTypes'), {
return Object.assign(jest.requireActual('../ReactNative-View-propTypes'), {
parser: 'flow'
});
});
Expand Down
2 changes: 1 addition & 1 deletion transforms/__tests__/create-element-to-jsx-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'use strict';

jest.mock('../create-element-to-jsx', () => {
return Object.assign(require.requireActual('../create-element-to-jsx'), {
return Object.assign(jest.requireActual('../create-element-to-jsx'), {
parser: 'flow'
});
});
Expand Down
2 changes: 1 addition & 1 deletion transforms/__tests__/manual-bind-to-arrow-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'use strict';

jest.mock('../manual-bind-to-arrow', () => {
return Object.assign(require.requireActual('../manual-bind-to-arrow'), {
return Object.assign(jest.requireActual('../manual-bind-to-arrow'), {
parser: 'flow'
});
});
Expand Down
2 changes: 1 addition & 1 deletion transforms/__tests__/pure-component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'use strict';

jest.mock('../pure-component', () => {
return Object.assign(require.requireActual('../pure-component'), {
return Object.assign(jest.requireActual('../pure-component'), {
parser: 'flow'
});
});
Expand Down
42 changes: 15 additions & 27 deletions transforms/__tests__/remove-context-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,39 @@
"use strict";

'use strict';
const tests = ["with-provider", "with-provider-2", "no-provider"];

const tests = [
'with-provider',
'with-provider-2',
'no-provider',
];
const defineTest = require("jscodeshift/dist/testUtils").defineTest;

const defineTest = require('jscodeshift/dist/testUtils').defineTest;

describe('remove-context-provider', () => {

tests.forEach(test =>
describe("remove-context-provider", () => {
tests.forEach((test) =>
defineTest(
__dirname,
'remove-context-provider',
"remove-context-provider",
null,
`remove-context-provider/${ test }`
`remove-context-provider/${test}`
)
);


describe('typescript', () => {

describe("typescript", () => {
beforeEach(() => {
jest.mock('../remove-context-provider', () => {
return Object.assign(
require.requireActual('../remove-context-provider'),
{
parser: 'tsx'
}
);
jest.mock("../remove-context-provider", () => {
return Object.assign(jest.requireActual("../remove-context-provider"), {
parser: "tsx",
});
});
});

afterEach(() => {
jest.resetModules();
});

tests.forEach(test => {
tests.forEach((test) => {
defineTest(
__dirname,
'remove-context-provider',
"remove-context-provider",
null,
`remove-context-provider/typescript/${ test }`
`remove-context-provider/typescript/${test}`
);
});

});
});
58 changes: 25 additions & 33 deletions transforms/__tests__/remove-forward-ref.test.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,54 @@

'use strict';
"use strict";

const jsTests = [
'function-expression',
'arrow-function-expression',
'forward-ref-import',
'forward-ref-import-2',
'props-identifier',
'props-object-pattern',
'callee-is-member-expression'
"function-expression",
"arrow-function-expression",
"forward-ref-import",
"forward-ref-import-2",
"props-identifier",
"props-object-pattern",
"callee-is-member-expression",
];

const tsTests = [
'type-arguments',
'type-arguments-custom-names',
'type-arguments-type-literals',
'props-type-literal'
"type-arguments",
"type-arguments-custom-names",
"type-arguments-type-literals",
"props-type-literal",
];

const defineTest = require('jscodeshift/dist/testUtils').defineTest;

describe('remove-forward-ref', () => {
const defineTest = require("jscodeshift/dist/testUtils").defineTest;

jsTests.forEach(test =>
describe("remove-forward-ref", () => {
jsTests.forEach((test) =>
defineTest(
__dirname,
'remove-forward-ref',
"remove-forward-ref",
null,
`remove-forward-ref/${ test }`
`remove-forward-ref/${test}`
)
);


describe('typescript', () => {

describe("typescript", () => {
beforeEach(() => {
jest.mock('../remove-forward-ref', () => {
return Object.assign(
require.requireActual('../remove-forward-ref'),
{
parser: 'tsx'
}
);
jest.mock("../remove-forward-ref", () => {
return Object.assign(jest.requireActual("../remove-forward-ref"), {
parser: "tsx",
});
});
});

afterEach(() => {
jest.resetModules();
});

tsTests.forEach(test => {
tsTests.forEach((test) => {
defineTest(
__dirname,
'remove-forward-ref',
"remove-forward-ref",
null,
`remove-forward-ref/typescript/${ test }`
`remove-forward-ref/typescript/${test}`
);
});

});
});
4 changes: 2 additions & 2 deletions transforms/__tests__/rename-unsafe-lifecycles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('rename-unsafe-lifecycles', () => {
beforeEach(() => {
jest.mock('../rename-unsafe-lifecycles', () => {
return Object.assign(
require.requireActual('../rename-unsafe-lifecycles'),
jest.requireActual('../rename-unsafe-lifecycles'),
{
parser: 'flow'
}
Expand All @@ -52,7 +52,7 @@ describe('rename-unsafe-lifecycles', () => {
beforeEach(() => {
jest.mock('../rename-unsafe-lifecycles', () => {
return Object.assign(
require.requireActual('../rename-unsafe-lifecycles'),
jest.requireActual('../rename-unsafe-lifecycles'),
{
parser: 'tsx'
}
Expand Down
Loading