Skip to content

Commit 8dd9609

Browse files
committed
Copy transformTestUtils.ts from Reselect codemod
1 parent a594239 commit 8dd9609

File tree

1 file changed

+44
-42
lines changed

1 file changed

+44
-42
lines changed
Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,63 @@
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';
1+
import { globbySync } from 'globby'
2+
import type { Transform } from 'jscodeshift'
3+
import type { TestOptions } from 'jscodeshift/src/testUtils'
4+
import { runInlineTest } from 'jscodeshift/src/testUtils'
5+
import fs from 'node:fs'
6+
import path from 'node:path'
7+
import { describe, it } from 'vitest'
78

8-
export function runTransformTest(
9+
export const runTransformTest = (
910
name: string,
1011
transform: Transform,
11-
parser: string,
12+
parser: TestOptions['parser'],
1213
fixturePath: string
13-
) {
14-
describe(name, function () {
15-
globby
16-
.sync('**/*.input.*', {
17-
cwd: fixturePath,
18-
absolute: true,
19-
})
14+
) => {
15+
describe(name, () => {
16+
globbySync('**/*.input.*', {
17+
cwd: fixturePath,
18+
absolute: true
19+
})
2020
.map((entry) => entry.slice(fixturePath.length))
2121
.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-
});
22+
const extension = path.extname(filename)
23+
const testName = filename.replace(`.input${extension}`, '')
24+
const testInputPath = path.join(fixturePath, `${testName}${extension}`)
25+
const inputPath = path.join(
26+
fixturePath,
27+
`${testName}.input${extension}`
28+
)
29+
const outputPath = path.join(
30+
fixturePath,
31+
`${testName}.output${extension}`
32+
)
3433

35-
afterEach(function () {
36-
process.env.CODEMOD_CLI_ARGS = '';
37-
});
38-
39-
it('transforms correctly', function () {
34+
describe(testName, () => {
35+
it('transforms correctly', () => {
4036
runInlineTest(
4137
transform,
4238
{},
43-
{ path: testInputPath, source: fs.readFileSync(inputPath, 'utf8') },
39+
{
40+
path: testInputPath,
41+
source: fs.readFileSync(inputPath, 'utf8')
42+
},
4443
fs.readFileSync(outputPath, 'utf8'),
4544
{ parser }
46-
);
47-
});
45+
)
46+
})
4847

49-
it('is idempotent', function () {
48+
it('is idempotent', () => {
5049
runInlineTest(
5150
transform,
5251
{},
53-
{ path: testInputPath, source: fs.readFileSync(outputPath, 'utf8') },
52+
{
53+
path: testInputPath,
54+
source: fs.readFileSync(outputPath, 'utf8')
55+
},
5456
fs.readFileSync(outputPath, 'utf8'),
5557
{ parser }
56-
);
57-
});
58-
});
59-
});
60-
});
58+
)
59+
})
60+
})
61+
})
62+
})
6163
}

0 commit comments

Comments
 (0)