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

[code-infra] Import Pickers preset-safe into global codemod config #15659

Merged
merged 1 commit into from
Dec 2, 2024
Merged
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
12 changes: 12 additions & 0 deletions packages/x-codemod/src/v8.0.0/pickers/preset-safe/actual.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @ts-nocheck
import { FieldValueType } from '@mui/x-date-pickers/models';

interface DumbComponentProps {
valueType: FieldValueType;
foo: string;
bar: number;
}

const myFunction = (param: FieldValueType) => {
console.log('Hello World!');
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @ts-nocheck
import { PickerValueType } from '@mui/x-date-pickers/models';

interface DumbComponentProps {
valueType: PickerValueType;
foo: string;
bar: number;
}

const myFunction = (param: PickerValueType) => {
console.log('Hello World!');
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import path from 'path';
import { expect } from 'chai';
import jscodeshift from 'jscodeshift';
import transform from './index';
import readFile from '../../../util/readFile';

function read(fileName) {
return readFile(path.join(__dirname, fileName));
}

describe('v8.0.0/pickers', () => {
describe('preset-safe', () => {
it('transforms code as needed', () => {
const actual = transform(
{
source: read('./actual.spec.tsx'),
path: require.resolve('./actual.spec.tsx'),
},
{ jscodeshift: jscodeshift.withParser('tsx') },
{},
);

const expected = read('./expected.spec.tsx');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});

it('should be idempotent for expression', () => {
const actual = transform(
{
source: read('./expected.spec.tsx'),
path: require.resolve('./expected.spec.tsx'),
},
{ jscodeshift: jscodeshift.withParser('tsx') },
{},
);

const expected = read('./expected.spec.tsx');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
});
});
15 changes: 0 additions & 15 deletions packages/x-codemod/src/v8.0.0/preset-safe/actual.spec.js

This file was deleted.

18 changes: 0 additions & 18 deletions packages/x-codemod/src/v8.0.0/preset-safe/expected.spec.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/x-codemod/src/v8.0.0/preset-safe/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import transformTreeView from '../tree-view/preset-safe';
import transformPickers from '../pickers/preset-safe';
import transformCharts from '../charts/preset-safe';
import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../types';

export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) {
file.source = transformTreeView(file, api, options);
file.source = transformPickers(file, api, options);
file.source = transformCharts(file, api, options);

return file.source;
Expand Down
53 changes: 42 additions & 11 deletions packages/x-codemod/src/v8.0.0/preset-safe/preset-safe.test.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,58 @@
import path from 'path';
import { expect } from 'chai';
import jscodeshift from 'jscodeshift';
import fs from 'fs';
import transform from '.';
import readFile from '../../util/readFile';

function read(fileName) {
return readFile(path.join(__dirname, fileName));
return readFile(fileName);
}

function getAllDirs() {
return fs
.readdirSync(path.resolve(__dirname, '..'))
.filter(
(file) =>
fs.statSync(path.resolve(__dirname, '..', file)).isDirectory() && file !== 'preset-safe',
);
}

describe('v8.0.0', () => {
describe('preset-safe', () => {
it('transforms code as needed', () => {
const actual = transform({ source: read('./actual.spec.js') }, { jscodeshift }, {});
const MOD_DIRS = getAllDirs();

const expected = read('./expected.spec.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
describe('preset-safe', () => {
MOD_DIRS.forEach((testDir) => {
const actualPath = path.resolve(__dirname, '..', testDir, 'preset-safe', 'actual.spec.tsx');
const expectedPath = path.resolve(
__dirname,
'..',
testDir,
'preset-safe',
'expected.spec.tsx',
);

it('should be idempotent', () => {
const actual = transform({ source: read('./expected.spec.js') }, { jscodeshift }, {});
describe(`${testDir.replace(/-/g, ' ')}`, () => {
it('transforms code as needed', () => {
const actual = transform(
{ source: read(actualPath) },
{ jscodeshift: jscodeshift.withParser('tsx') },
{},
);
const expected = read(expectedPath);
expect(actual).to.equal(expected, 'The transformed version should be correct');
});

const expected = read('./expected.spec.js');
expect(actual).to.equal(expected, 'The transformed version should be correct');
it('should be idempotent', () => {
const actual = transform(
{ source: read(expectedPath) },
{ jscodeshift: jscodeshift.withParser('tsx') },
{},
);
const expected = read(expectedPath);
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
});
});
});
});