forked from umijs/umi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testCodemod.ts
37 lines (32 loc) · 1.07 KB
/
testCodemod.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
31
32
33
34
35
36
37
import { logger, rimraf } from '@umijs/utils';
import assert from 'assert';
import 'zx/globals';
const fixtureDir = path.join(__dirname, '../codemod/fixtures');
const tmpDir = path.join(fixtureDir, 'tmp');
(async () => {
// 1、copy fixtures/origin > fixtures/tmp
logger.info('copy fixtures/origin > fixtures/tmp');
rimraf.sync(tmpDir);
fs.copySync(path.join(fixtureDir, 'origin'), tmpDir);
// 2、run codemod script
logger.info('run codemod script');
// enable color for kleur
// ref: https://github.com/lukeed/kleur/blob/86a7db8/index.mjs#L5
process.env.FORCE_COLOR = '1';
await $`npm run codemod:run`;
// 3、test
assert(
getContent('src/useRouteMatch.ts').includes(`useMatch as useRouteMatch`),
`src/useRouteMatch.ts`,
);
assert(
getContent('.eslintrc.js').includes(`require.resolve('umi/eslint')`) &&
getContent('.eslintrc.js').includes(
`"@typescript-eslint/naming-convention": 0`,
),
`.eslintrc.js`,
);
})();
function getContent(filePath: string) {
return fs.readFileSync(path.join(tmpDir, filePath), 'utf-8');
}