Skip to content

Commit 7026e78

Browse files
committed
fix(@schematics/angular): add missing imports for focus and skip APIs in refactor-jasmine-vitest
`xdescribe`, `fdescribe`, `xit` and `fit` Vitest equivalents use a slightly different API. This change handles the `--add-imports` aspect where the appropriate functions are imported for these specific APIs. Fixes #33021
1 parent 0122398 commit 7026e78

2 files changed

Lines changed: 50 additions & 11 deletions

File tree

packages/schematics/angular/refactor/jasmine-vitest/test-file-transformer.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,20 @@ import { RefactorReporter } from './utils/refactor-reporter';
5959
const BLANK_LINE_PLACEHOLDER = '// __PRESERVE_BLANK_LINE__';
6060

6161
/**
62-
* Vitest function names that should be imported when using the --add-imports option.
62+
* Jasmine to Vitest imports map that should be employed when the --add-imports option is used.
6363
*/
64-
const VITEST_FUNCTION_NAMES = new Set([
65-
'describe',
66-
'it',
67-
'expect',
68-
'beforeEach',
69-
'afterEach',
70-
'beforeAll',
71-
'afterAll',
64+
const JASMINE_TO_VITEST_IMPORT = new Map<string, string>([
65+
['describe', 'describe'],
66+
['fdescribe', 'describe'],
67+
['xdescribe', 'describe'],
68+
['it', 'it'],
69+
['fit', 'it'],
70+
['xit', 'it'],
71+
['expect', 'expect'],
72+
['beforeEach', 'beforeEach'],
73+
['afterEach', 'afterEach'],
74+
['beforeAll', 'beforeAll'],
75+
['afterAll', 'afterAll'],
7276
]);
7377

7478
/**
@@ -200,8 +204,9 @@ export function transformJasmineToVitest(
200204
if (ts.isCallExpression(transformedNode)) {
201205
if (options.addImports && ts.isIdentifier(transformedNode.expression)) {
202206
const name = transformedNode.expression.text;
203-
if (VITEST_FUNCTION_NAMES.has(name)) {
204-
addVitestValueImport(pendingVitestValueImports, name);
207+
const importSpecifierName = JASMINE_TO_VITEST_IMPORT.get(name);
208+
if (importSpecifierName) {
209+
addVitestValueImport(pendingVitestValueImports, importSpecifierName);
205210
}
206211
}
207212

packages/schematics/angular/refactor/jasmine-vitest/test-file-transformer_add-imports_spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,38 @@ describe('Jasmine to Vitest Transformer - addImports option', () => {
116116
`;
117117
await expectTransformation(input, expected, true);
118118
});
119+
120+
it('should add imports for transformed global functions with different Vitest names', async () => {
121+
await expectTransformation(
122+
`
123+
fdescribe('My Suite', () => {
124+
xit('should skip', () => {});
125+
});
126+
`,
127+
`
128+
import { describe, it } from 'vitest';
129+
130+
describe.only('My Suite', () => {
131+
it.skip('should skip', () => {});
132+
});
133+
`,
134+
true,
135+
);
136+
137+
await expectTransformation(
138+
`
139+
xdescribe('My Suite', () => {
140+
fit('should focus', () => {});
141+
});
142+
`,
143+
`
144+
import { describe, it } from 'vitest';
145+
146+
describe.skip('My Suite', () => {
147+
it.only('should focus', () => {});
148+
});
149+
`,
150+
true,
151+
);
152+
});
119153
});

0 commit comments

Comments
 (0)