Files
how2ice 005cf56baf
Some checks failed
No response / noResponse (push) Has been cancelled
CI / Continuous releases (push) Has been cancelled
CI / test-dev (macos-latest) (push) Has been cancelled
CI / test-dev (ubuntu-latest) (push) Has been cancelled
CI / test-dev (windows-latest) (push) Has been cancelled
Maintenance / main (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
init project
2025-12-12 14:26:25 +09:00

53 lines
1.5 KiB
JavaScript

/* eslint-disable no-undef */
import j from 'jscodeshift';
import { EOL } from 'os';
import path from 'path';
import { expect } from 'chai';
import readFile from '../src/util/readFile';
export const jscodeshift = j.withParser('tsx');
function read(dirname, fileName) {
return readFile(path.join(dirname, fileName));
}
export function describeJscodeshiftTransform({ transformName, transform, testCases, dirname }) {
describe(transformName, () => {
testCases.forEach((testCase) => {
it('transforms as needed', () => {
const actual = transform(
{ source: read(dirname, testCase.actual) },
{ jscodeshift },
{
...testCase.options,
printOptions: {
...testCase.options?.printOptions,
lineTerminator: EOL,
},
},
);
const expected = read(dirname, testCase.expected);
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
it('should be idempotent', () => {
const actual = transform(
{ source: read(dirname, testCase.expected) },
{ jscodeshift },
{
...testCase.options,
printOptions: {
...testCase.options?.printOptions,
lineTerminator: EOL,
},
},
);
const expected = read(dirname, testCase.expected);
expect(actual).to.equal(expected, 'The transformed version should be correct');
});
});
});
}