/
codemods.test.ts
30 lines (27 loc) · 1.12 KB
/
codemods.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import path from 'path';
import fs from 'fs';
import 'jest-specific-snapshot';
import { applyTransform } from 'jscodeshift/dist/testUtils';
jest.mock('@storybook/node-logger');
const inputRegExp = /\.input\.js$/;
const fixturesDir = path.resolve(__dirname, './__testfixtures__');
fs.readdirSync(fixturesDir).forEach((transformName) => {
const transformFixturesDir = path.join(fixturesDir, transformName);
describe(transformName, () =>
fs
.readdirSync(transformFixturesDir)
.filter((fileName) => inputRegExp.test(fileName))
.forEach((fileName) => {
const inputPath = path.join(transformFixturesDir, fileName);
it(`transforms correctly using "${fileName}" data`, () =>
expect(
applyTransform(
// eslint-disable-next-line global-require,import/no-dynamic-require
require(path.join(__dirname, '__testtransforms__', transformName)),
null,
{ path: inputPath, source: fs.readFileSync(inputPath, 'utf8') }
)
).toMatchSpecificSnapshot(inputPath.replace(inputRegExp, '.output.snapshot')));
})
);
});