Skip to content

Commit 32a7dcf

Browse files
authored
Merge pull request #3764 from reduxjs/feature/rtk-codemods-vitest
2 parents b1c2381 + 644f757 commit 32a7dcf

File tree

10 files changed

+108
-83
lines changed

10 files changed

+108
-83
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.

packages/rtk-codemods/package.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.0.3",
44
"scripts": {
55
"lint": "eslint --cache .",
6-
"test": "codemod-cli test",
7-
"test:coverage": "codemod-cli test --coverage",
6+
"test": "vitest",
7+
"test:coverage": "vitest --coverage",
88
"update-docs": "codemod-cli update-docs"
99
},
1010
"bin": "./bin/cli.js",
@@ -22,23 +22,19 @@
2222
"codemod"
2323
],
2424
"dependencies": {
25-
"@types/jest": "^27",
2625
"@types/jscodeshift": "^0.11.5",
2726
"codemod-cli": "^3.2.0",
28-
"ts-node": "10.4.0",
2927
"typescript": "^4.8.0"
3028
},
3129
"devDependencies": {
3230
"eslint": "^7.25.0",
3331
"eslint-config-prettier": "^8.3.0",
3432
"eslint-plugin-node": "^11.1.0",
3533
"eslint-plugin-prettier": "^3.4.0",
36-
"jest": "^27",
37-
"prettier": "^2.2.1",
38-
"ts-jest": "^27"
34+
"prettier": "^2.2.1"
3935
},
4036
"engines": {
41-
"node": ">= 14"
37+
"node": ">= 16"
4238
},
4339
"publishConfig": {
4440
"access": "public"
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+
});

yarn.lock

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -6926,17 +6926,13 @@ __metadata:
69266926
version: 0.0.0-use.local
69276927
resolution: "@reduxjs/rtk-codemods@workspace:packages/rtk-codemods"
69286928
dependencies:
6929-
"@types/jest": ^27
69306929
"@types/jscodeshift": ^0.11.5
69316930
codemod-cli: ^3.2.0
69326931
eslint: ^7.25.0
69336932
eslint-config-prettier: ^8.3.0
69346933
eslint-plugin-node: ^11.1.0
69356934
eslint-plugin-prettier: ^3.4.0
6936-
jest: ^27
69376935
prettier: ^2.2.1
6938-
ts-jest: ^27
6939-
ts-node: 10.4.0
69406936
typescript: ^4.8.0
69416937
bin:
69426938
rtk-codemods: ./bin/cli.js
@@ -19107,7 +19103,7 @@ fsevents@^1.2.7:
1910719103
languageName: node
1910819104
linkType: hard
1910919105

19110-
"jest-util@npm:^27.0.0, jest-util@npm:^27.5.1":
19106+
"jest-util@npm:^27.5.1":
1911119107
version: 27.5.1
1911219108
resolution: "jest-util@npm:27.5.1"
1911319109
dependencies:
@@ -19275,7 +19271,7 @@ fsevents@^1.2.7:
1927519271
languageName: node
1927619272
linkType: hard
1927719273

19278-
"jest@npm:^27, jest@npm:^27.4.3":
19274+
"jest@npm:^27.4.3":
1927919275
version: 27.5.1
1928019276
resolution: "jest@npm:27.5.1"
1928119277
dependencies:
@@ -19593,15 +19589,6 @@ fsevents@^1.2.7:
1959319589
languageName: node
1959419590
linkType: hard
1959519591

19596-
"json5@npm:2.x, json5@npm:^2.1.2, json5@npm:^2.2.0, json5@npm:^2.2.1":
19597-
version: 2.2.1
19598-
resolution: "json5@npm:2.2.1"
19599-
bin:
19600-
json5: lib/cli.js
19601-
checksum: 74b8a23b102a6f2bf2d224797ae553a75488b5adbaee9c9b6e5ab8b510a2fc6e38f876d4c77dea672d4014a44b2399e15f2051ac2b37b87f74c0c7602003543b
19602-
languageName: node
19603-
linkType: hard
19604-
1960519592
"json5@npm:^1.0.1":
1960619593
version: 1.0.1
1960719594
resolution: "json5@npm:1.0.1"
@@ -19613,6 +19600,15 @@ fsevents@^1.2.7:
1961319600
languageName: node
1961419601
linkType: hard
1961519602

19603+
"json5@npm:^2.1.2, json5@npm:^2.2.0, json5@npm:^2.2.1":
19604+
version: 2.2.1
19605+
resolution: "json5@npm:2.2.1"
19606+
bin:
19607+
json5: lib/cli.js
19608+
checksum: 74b8a23b102a6f2bf2d224797ae553a75488b5adbaee9c9b6e5ab8b510a2fc6e38f876d4c77dea672d4014a44b2399e15f2051ac2b37b87f74c0c7602003543b
19609+
languageName: node
19610+
linkType: hard
19611+
1961619612
"json5@npm:^2.2.3":
1961719613
version: 2.2.3
1961819614
resolution: "json5@npm:2.2.3"
@@ -28222,39 +28218,6 @@ fsevents@^1.2.7:
2822228218
languageName: node
2822328219
linkType: hard
2822428220

28225-
"ts-jest@npm:^27":
28226-
version: 27.1.5
28227-
resolution: "ts-jest@npm:27.1.5"
28228-
dependencies:
28229-
bs-logger: 0.x
28230-
fast-json-stable-stringify: 2.x
28231-
jest-util: ^27.0.0
28232-
json5: 2.x
28233-
lodash.memoize: 4.x
28234-
make-error: 1.x
28235-
semver: 7.x
28236-
yargs-parser: 20.x
28237-
peerDependencies:
28238-
"@babel/core": ">=7.0.0-beta.0 <8"
28239-
"@types/jest": ^27.0.0
28240-
babel-jest: ">=27.0.0 <28"
28241-
jest: ^27.0.0
28242-
typescript: ">=3.8 <5.0"
28243-
peerDependenciesMeta:
28244-
"@babel/core":
28245-
optional: true
28246-
"@types/jest":
28247-
optional: true
28248-
babel-jest:
28249-
optional: true
28250-
esbuild:
28251-
optional: true
28252-
bin:
28253-
ts-jest: cli.js
28254-
checksum: 3ef51c538b82f49b3f529331c1a017871a2f90e7a9a6e69333304755036d121818c6b120e2ce32dd161ff8bb2487efec0c790753ecd39b46a9ed1ce0d241464c
28255-
languageName: node
28256-
linkType: hard
28257-
2825828221
"ts-jest@npm:^29":
2825928222
version: 29.0.5
2826028223
resolution: "ts-jest@npm:29.0.5"
@@ -30675,7 +30638,7 @@ fsevents@^1.2.7:
3067530638
languageName: node
3067630639
linkType: hard
3067730640

30678-
"yargs-parser@npm:20.2.9, yargs-parser@npm:20.x, yargs-parser@npm:^20.2.2":
30641+
"yargs-parser@npm:20.2.9, yargs-parser@npm:^20.2.2":
3067930642
version: 20.2.9
3068030643
resolution: "yargs-parser@npm:20.2.9"
3068130644
checksum: 8bb69015f2b0ff9e17b2c8e6bfe224ab463dd00ca211eece72a4cd8a906224d2703fb8a326d36fdd0e68701e201b2a60ed7cf81ce0fd9b3799f9fe7745977ae3

0 commit comments

Comments
 (0)