Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ export function transformPending(
node: ts.Node,
{ sourceFile, reporter, tsContext }: RefactorContext,
): ts.Node {
if (
!ts.isCallExpression(node) ||
!ts.isIdentifier(node.expression) ||
node.expression.text !== 'it'
) {
if (!ts.isCallExpression(node)) {
return node;
}

// `fit`/`xit` have already become `it.only`/`it.skip` when this transformer runs,
// as `transformFocusedAndSkippedTests` is applied earlier in the pipeline.
const isBareIt = ts.isIdentifier(node.expression) && node.expression.text === 'it';
const isFocusedOrSkippedIt =
ts.isPropertyAccessExpression(node.expression) &&
ts.isIdentifier(node.expression.expression) &&
node.expression.expression.text === 'it' &&
(node.expression.name.text === 'only' || node.expression.name.text === 'skip');
if (!isBareIt && !isFocusedOrSkippedIt) {
return node;
}

Expand Down Expand Up @@ -100,7 +108,9 @@ export function transformPending(
return node;
}

const newExpression = createPropertyAccess(node.expression, 'skip');
// A pending spec never runs its body in Jasmine, even when focused, so `it.only`
// also becomes `it.skip`.
const newExpression = createPropertyAccess('it', 'skip');
const newTestFn = ts.isArrowFunction(testFn)
? ts.factory.updateArrowFunction(
testFn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,34 @@ describe('transformPending', () => {
});
`,
},
{
description: 'should transform a focused test (fit) with pending() to it.skip()',
input: `
fit('is a work in progress', () => {
pending('Not yet implemented');
});
`,
expected: `
it.skip('is a work in progress', () => {
// TODO: vitest-migration: The pending() function was converted to a skipped test (\`it.skip\`). See: https://vitest.dev/api/vi.html#it-skip
// pending('Not yet implemented');
});
`,
},
{
description: 'should comment out pending() in a skipped test (xit)',
input: `
xit('is a work in progress', () => {
pending('Not yet implemented');
});
`,
expected: `
it.skip('is a work in progress', () => {
// TODO: vitest-migration: The pending() function was converted to a skipped test (\`it.skip\`). See: https://vitest.dev/api/vi.html#it-skip
// pending('Not yet implemented');
});
`,
},
];

testCases.forEach(({ description, input, expected }) => {
Expand Down