|
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' |
7 | 8 |
|
8 |
| -export function runTransformTest( |
| 9 | +export const runTransformTest = ( |
9 | 10 | name: string,
|
10 | 11 | transform: Transform,
|
11 |
| - parser: string, |
| 12 | + parser: TestOptions['parser'], |
12 | 13 | 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 | + }) |
20 | 20 | .map((entry) => entry.slice(fixturePath.length))
|
21 | 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 |
| - }); |
| 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 | + ) |
34 | 33 |
|
35 |
| - afterEach(function () { |
36 |
| - process.env.CODEMOD_CLI_ARGS = ''; |
37 |
| - }); |
38 |
| - |
39 |
| - it('transforms correctly', function () { |
| 34 | + describe(testName, () => { |
| 35 | + it('transforms correctly', () => { |
40 | 36 | runInlineTest(
|
41 | 37 | transform,
|
42 | 38 | {},
|
43 |
| - { path: testInputPath, source: fs.readFileSync(inputPath, 'utf8') }, |
| 39 | + { |
| 40 | + path: testInputPath, |
| 41 | + source: fs.readFileSync(inputPath, 'utf8') |
| 42 | + }, |
44 | 43 | fs.readFileSync(outputPath, 'utf8'),
|
45 | 44 | { parser }
|
46 |
| - ); |
47 |
| - }); |
| 45 | + ) |
| 46 | + }) |
48 | 47 |
|
49 |
| - it('is idempotent', function () { |
| 48 | + it('is idempotent', () => { |
50 | 49 | runInlineTest(
|
51 | 50 | transform,
|
52 | 51 | {},
|
53 |
| - { path: testInputPath, source: fs.readFileSync(outputPath, 'utf8') }, |
| 52 | + { |
| 53 | + path: testInputPath, |
| 54 | + source: fs.readFileSync(outputPath, 'utf8') |
| 55 | + }, |
54 | 56 | fs.readFileSync(outputPath, 'utf8'),
|
55 | 57 | { parser }
|
56 |
| - ); |
57 |
| - }); |
58 |
| - }); |
59 |
| - }); |
60 |
| - }); |
| 58 | + ) |
| 59 | + }) |
| 60 | + }) |
| 61 | + }) |
| 62 | + }) |
61 | 63 | }
|
0 commit comments