Skip to content

Commit e7abeb5

Browse files
hawkgsalan-agius4
authored andcommitted
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 angular#33021 (cherry picked from commit b47dfba)
1 parent 46c98ea commit e7abeb5

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
@@ -57,16 +57,20 @@ import { RefactorReporter } from './utils/refactor-reporter';
5757
const BLANK_LINE_PLACEHOLDER = '// __PRESERVE_BLANK_LINE__';
5858

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

7276
/**
@@ -196,8 +200,9 @@ export function transformJasmineToVitest(
196200
if (ts.isCallExpression(transformedNode)) {
197201
if (options.addImports && ts.isIdentifier(transformedNode.expression)) {
198202
const name = transformedNode.expression.text;
199-
if (VITEST_FUNCTION_NAMES.has(name)) {
200-
addVitestValueImport(pendingVitestValueImports, name);
203+
const importSpecifierName = JASMINE_TO_VITEST_IMPORT.get(name);
204+
if (importSpecifierName) {
205+
addVitestValueImport(pendingVitestValueImports, importSpecifierName);
201206
}
202207
}
203208

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
@@ -118,4 +118,38 @@ describe('Jasmine to Vitest Transformer', () => {
118118
await expectTransformation(input, expected, true);
119119
});
120120
});
121+
122+
it('should add imports for transformed global functions with different Vitest names', async () => {
123+
await expectTransformation(
124+
`
125+
fdescribe('My Suite', () => {
126+
xit('should skip', () => {});
127+
});
128+
`,
129+
`
130+
import { describe, it } from 'vitest';
131+
132+
describe.only('My Suite', () => {
133+
it.skip('should skip', () => {});
134+
});
135+
`,
136+
true,
137+
);
138+
139+
await expectTransformation(
140+
`
141+
xdescribe('My Suite', () => {
142+
fit('should focus', () => {});
143+
});
144+
`,
145+
`
146+
import { describe, it } from 'vitest';
147+
148+
describe.skip('My Suite', () => {
149+
it.only('should focus', () => {});
150+
});
151+
`,
152+
true,
153+
);
154+
});
121155
});

0 commit comments

Comments
 (0)