test(linter/plugins): replace assert with vitest's expect#16016
test(linter/plugins): replace assert with vitest's expect#16016overlookmotel merged 2 commits intooxc-project:mainfrom
assert with vitest's expect#16016Conversation
There was a problem hiding this comment.
Pull request overview
This pull request migrates test assertions from Node.js's assert module to vitest's expect API in the linter plugin tests. While the intent is good, the conversion contains critical bugs that will cause test failures.
Key Changes:
- Removed
assertimport and addedexpectto vitest imports - Converted
assert.deepStrictEqual()calls toexpect().toEqual() - Converted
assert.strictEqual()calls toexpect().toBe() - Attempted conversion of
assert.fail()toexpect.fail()
Critical Issues Found:
- 15 instances where
expect()calls are missing the matcher function (e.g.,.toBe()), with the expected value incorrectly passed as a second argument toexpect()instead - 1 instance of invalid API usage:
expect.fail()does not exist in vitest
Comments suppressed due to low confidence (15)
apps/oxlint/test/tokens.test.ts:356
- Missing
.toBe()matcher on theexpect()call. The second argument'C'should be part of.toBe('C')instead of being a separate argument toexpect().
This should be:
expect(
getTokenAfter(VariableDeclaratorIdentifier, {
includeComments: true,
skip: 2,
})!.value,
).toBe('C'); expect(
getTokenAfter(VariableDeclaratorIdentifier, {
includeComments: true,
skip: 2,
})!.value,
'C',
);
apps/oxlint/test/tokens.test.ts:268
- Missing
.toBe()matcher on theexpect()call. The second argument'='should be part of.toBe('=')instead of being a separate argument toexpect().
This should be:
expect(
getTokenBefore(BinaryExpression, {
includeComments: true,
skip: 1,
})!.value,
).toBe('='); expect(
getTokenBefore(BinaryExpression, {
includeComments: true,
skip: 1,
})!.value,
'=',
);
apps/oxlint/test/tokens.test.ts:337
- Missing
.toBe()matcher on theexpect()call. The second argument'b'should be part of.toBe('b')instead of being a separate argument toexpect().
This should be:
expect(
getTokenAfter(VariableDeclaratorIdentifier, {
skip: 1,
filter: (t) => t.type === 'Identifier',
})!.value,
).toBe('b'); expect(
getTokenAfter(VariableDeclaratorIdentifier, {
skip: 1,
filter: (t) => t.type === 'Identifier',
})!.value,
'b',
);
apps/oxlint/test/tokens.test.ts:566
- Missing
.toBe()matcher on theexpect()call. The second argument'a'should be part of.toBe('a')instead of being a separate argument toexpect().
This should be:
expect(
getFirstToken(BinaryExpression, {
filter: (t) => t.type === 'Identifier',
})!.value,
).toBe('a'); expect(
getFirstToken(BinaryExpression, {
filter: (t) => t.type === 'Identifier',
})!.value,
'a',
);
apps/oxlint/test/tokens.test.ts:590
- Missing
.toBe()matcher on theexpect()call. The second argument'D'should be part of.toBe('D')instead of being a separate argument toexpect().
This should be:
expect(
getFirstToken(BinaryExpression, {
includeComments: true,
skip: 1,
})!.value,
).toBe('D'); expect(
getFirstToken(BinaryExpression, {
includeComments: true,
skip: 1,
})!.value,
'D',
);
apps/oxlint/test/tokens.test.ts:617
- Missing
.toBe()matcher on theexpect()call. The second argument'comment'should be part of.toBe('comment')instead of being a separate argument toexpect().
This should be:
expect(
getFirstToken(
{ range: [6, 23] } as Node,
{ includeComments: true },
)!.value,
).toBe('comment'); expect(
getFirstToken(
// TODO: this verbatim range should be replaced with `[ast.comments[0].range[0], ast.tokens[5].range[1]]`
{ range: [6, 23] } as Node,
{ includeComments: true },
)!.value,
'comment',
);
apps/oxlint/test/tokens.test.ts:258
- Missing
.toBe()matcher on theexpect()call. The second argument'C'should be part of.toBe('C')instead of being a separate argument toexpect().
This should be:
expect(
getTokenBefore(BinaryExpression, {
includeComments: true,
})!.value,
).toBe('C'); expect(
getTokenBefore(BinaryExpression, {
includeComments: true,
})!.value,
'C',
);
apps/oxlint/test/tokens.test.ts:279
- Missing
.toBe()matcher on theexpect()call. The second argument'B'should be part of.toBe('B')instead of being a separate argument toexpect().
This should be:
expect(
getTokenBefore(BinaryExpression, {
includeComments: true,
skip: 1,
filter: (t) => t.type.startsWith('Block'),
})!.value,
).toBe('B'); expect(
getTokenBefore(BinaryExpression, {
includeComments: true,
skip: 1,
filter: (t) => t.type.startsWith('Block'),
})!.value,
'B',
);
apps/oxlint/test/tokens.test.ts:576
- Missing
.toBe()matcher on theexpect()call. The second argument'b'should be part of.toBe('b')instead of being a separate argument toexpect().
This should be:
expect(
getFirstToken(BinaryExpression, {
skip: 1,
filter: (t) => t.type === 'Identifier',
})!.value,
).toBe('b'); expect(
getFirstToken(BinaryExpression, {
skip: 1,
filter: (t) => t.type === 'Identifier',
})!.value,
'b',
);
apps/oxlint/test/tokens.test.ts:601
- Missing
.toBe()matcher on theexpect()call. The second argument'*'should be part of.toBe('*')instead of being a separate argument toexpect().
This should be:
expect(
getFirstToken(BinaryExpression, {
includeComments: true,
skip: 1,
filter: (t) => t.value !== 'a',
})!.value,
).toBe('*'); expect(
getFirstToken(BinaryExpression, {
includeComments: true,
skip: 1,
filter: (t) => t.value !== 'a',
})!.value,
'*',
);
apps/oxlint/test/tokens.test.ts:632
- Missing
.toBe()matcher on theexpect()call. The second argument'c'should be part of.toBe('c')instead of being a separate argument toexpect().
This should be:
expect(
getFirstToken({
range: [6, 23],
} as Node)!.value,
).toBe('c'); expect(
getFirstToken({
// TODO: this verbatim range should be replaced with `[ast.comments[0].range[0], ast.tokens[5].range[1]]`
range: [6, 23],
} as Node)!.value,
'c',
);
apps/oxlint/test/tokens.test.ts:249
- Missing
.toBe()matcher on theexpect()call. The second argument'var'should be part of.toBe('var')instead of being a separate argument toexpect().
This should be:
expect(
getTokenBefore(BinaryExpression, {
skip: 1,
filter: (t) => t.value !== '=',
})!.value,
).toBe('var'); expect(
getTokenBefore(BinaryExpression, {
skip: 1,
filter: (t) => t.value !== '=',
})!.value,
'var',
);
apps/oxlint/test/tokens.test.ts:327
- Missing
.toBe()matcher on theexpect()call. The second argument'a'should be part of.toBe('a')instead of being a separate argument toexpect().
This should be:
expect(
getTokenAfter(VariableDeclaratorIdentifier, {
filter: (t) => t.type === 'Identifier',
})!.value,
).toBe('a'); expect(
getTokenAfter(VariableDeclaratorIdentifier, {
filter: (t) => t.type === 'Identifier',
})!.value,
'a',
);
apps/oxlint/test/tokens.test.ts:346
- Missing
.toBe()matcher on theexpect()call. The second argument'B'should be part of.toBe('B')instead of being a separate argument toexpect().
This should be:
expect(
getTokenAfter(VariableDeclaratorIdentifier, {
includeComments: true,
})!.value,
).toBe('B'); expect(
getTokenAfter(VariableDeclaratorIdentifier, {
includeComments: true,
})!.value,
'B',
);
apps/oxlint/test/tokens.test.ts:367
- Missing
.toBe()matcher on theexpect()call. The second argument'D'should be part of.toBe('D')instead of being a separate argument toexpect().
This should be:
expect(
getTokenAfter(VariableDeclaratorIdentifier, {
includeComments: true,
skip: 2,
filter: (t) => t.type.startsWith('Block'),
})!.value,
).toBe('D'); expect(
getTokenAfter(VariableDeclaratorIdentifier, {
includeComments: true,
skip: 2,
filter: (t) => t.type.startsWith('Block'),
})!.value,
'D',
);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
2d78570 to
8fde60f
Compare
8fde60f to
b941034
Compare
overlookmotel
left a comment
There was a problem hiding this comment.
Thank you! I hope you used AI for this...
|
Yes, but |
|
I've replaced Will merge as soon as CI passes. |
…oject#16016) - Follow up to review comment in oxc-project#16002 (comment). - We were originally using `assert` because it was a direct analogue to `eslint` testing, made migrating their tests slightly easier. --------- Co-authored-by: overlookmotel <[email protected]>
SourceCode#getFirstToken()#16002 (comment).assertbecause it was a direct analogue toeslinttesting, made migrating their tests slightly easier.