-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreplaceTestApiFailing.ts
31 lines (28 loc) · 1.14 KB
/
replaceTestApiFailing.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
import type { Collection, Identifier, JSCodeshift } from 'jscodeshift'
const jestFailsApisName = 'failing'
const vitestFailsApisName = 'fails'
export const replaceTestApiFailing = (j: JSCodeshift, source: Collection<any>): void => {
for (const testApiName of ['it', 'test']) {
// Replace `(it|test).failing` with `(it|test).fails`
source.find(j.MemberExpression, {
object: { type: 'Identifier', name: testApiName },
property: { type: 'Identifier', name: jestFailsApisName },
}).forEach((path) => {
(path.node.property as Identifier).name = vitestFailsApisName
return path
})
// Replace `(it|test).(only|skip).failing` with `(it|test).(only|skip).fails`
for (const testApiModifierName of ['only', 'skip']) {
source.find(j.MemberExpression, {
object: {
object: { type: 'Identifier', name: testApiName },
property: { type: 'Identifier', name: testApiModifierName },
},
property: { type: 'Identifier', name: jestFailsApisName },
}).forEach((path) => {
(path.node.property as Identifier).name = vitestFailsApisName
return path
})
}
}
}