Skip to content

Commit 644f757

Browse files
committed
Switch from Jest to Vitest in rtk-codemods
1 parent 925c221 commit 644f757

File tree

8 files changed

+92
-26
lines changed

8 files changed

+92
-26
lines changed

packages/rtk-codemods/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
},
55

66
plugins: ['prettier', 'node'],
7-
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'plugin:node/recommended'],
7+
extends: ['eslint:recommended', 'plugin:prettier/recommended'],
88
env: {
99
node: true,
1010
},

packages/rtk-codemods/jest.config.js

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { describe, vi } from 'vitest';
2+
import type { Transform } from 'jscodeshift';
3+
import globby from 'globby';
4+
import fs from 'fs-extra';
5+
import path from 'path';
6+
import { runInlineTest } from 'jscodeshift/dist/testUtils';
7+
8+
export function runTransformTest(
9+
name: string,
10+
transform: Transform,
11+
parser: string,
12+
fixturePath: string
13+
) {
14+
describe(name, function () {
15+
globby
16+
.sync('**/*.input.*', {
17+
cwd: fixturePath,
18+
absolute: true,
19+
})
20+
.map((entry) => entry.slice(fixturePath.length))
21+
.forEach((filename) => {
22+
let extension = path.extname(filename);
23+
let testName = filename.replace(`.input${extension}`, '');
24+
let testInputPath = path.join(fixturePath, `${testName}${extension}`);
25+
let inputPath = path.join(fixturePath, `${testName}.input${extension}`);
26+
let outputPath = path.join(fixturePath, `${testName}.output${extension}`);
27+
let optionsPath = path.join(fixturePath, `${testName}.options.json`);
28+
let options = fs.pathExistsSync(optionsPath) ? fs.readFileSync(optionsPath) : '{}';
29+
30+
describe(testName, function () {
31+
beforeEach(function () {
32+
process.env.CODEMOD_CLI_ARGS = options;
33+
});
34+
35+
afterEach(function () {
36+
process.env.CODEMOD_CLI_ARGS = '';
37+
});
38+
39+
it('transforms correctly', function () {
40+
runInlineTest(
41+
transform,
42+
{},
43+
{ path: testInputPath, source: fs.readFileSync(inputPath, 'utf8') },
44+
fs.readFileSync(outputPath, 'utf8'),
45+
{ parser }
46+
);
47+
});
48+
49+
it('is idempotent', function () {
50+
runInlineTest(
51+
transform,
52+
{},
53+
{ path: testInputPath, source: fs.readFileSync(outputPath, 'utf8') },
54+
fs.readFileSync(outputPath, 'utf8'),
55+
{ parser }
56+
);
57+
});
58+
});
59+
});
60+
});
61+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import path from 'path';
2+
import transform, { parser } from './index';
3+
4+
import { runTransformTest } from '../../transformTestUtils';
5+
6+
runTransformTest(
7+
'createReducerBuilder',
8+
transform,
9+
parser,
10+
path.join(__dirname, '__testfixtures__')
11+
);

packages/rtk-codemods/transforms/createReducerBuilder/test.js

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import path from 'path';
2+
import transform, { parser } from './index';
3+
4+
import { runTransformTest } from '../../transformTestUtils';
5+
6+
runTransformTest('createSliceBuilder', transform, parser, path.join(__dirname, '__testfixtures__'));

packages/rtk-codemods/transforms/createSliceBuilder/test.js

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from 'vitest/config';
2+
3+
export default defineConfig({
4+
test: {
5+
globals: true,
6+
setupFiles: [],
7+
include: ['./transforms/**/*.(spec|test).[jt]s?(x)'],
8+
alias: {},
9+
deps: {
10+
interopDefault: true,
11+
},
12+
},
13+
});

0 commit comments

Comments
 (0)