Skip to content

Commit

Permalink
refactor: handle unwrap properly
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 27, 2024
1 parent 730505e commit bcd0624
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/vitest/src/typecheck/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { ancestor as walkAst } from 'acorn-walk'
import { relative } from 'pathe'
import { parseAstAsync } from 'vite'
import type { Node } from "estree"

Check failure on line 13 in packages/vitest/src/typecheck/collect.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Expected "estree" (type) to come before "vite" (external)

Check failure on line 13 in packages/vitest/src/typecheck/collect.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Strings must use singlequote

interface ParsedFile extends File {
start: number
Expand Down Expand Up @@ -51,8 +52,6 @@ export async function collectTests(
if (!request) {
return null
}
// unwrap (0,...) for Vite 6
request.code = request.code.replace(/\(0,(__vite_ssr_import_\d+__\.\w+)\)/g, '( $1)')
const ast = await parseAstAsync(request.code)
const testFilepath = relative(ctx.config.root, filepath)
const projectName = ctx.name
Expand All @@ -72,7 +71,7 @@ export async function collectTests(
}
file.file = file
const definitions: LocalCallDefinition[] = []
const getName = (callee: any): string | null => {
const getName = (callee: Node): string | null => {
if (!callee) {
return null
}
Expand All @@ -86,12 +85,20 @@ export async function collectTests(
return getName(callee.tag)
}
if (callee.type === 'MemberExpression') {
const object = callee.object as any;

Check failure on line 88 in packages/vitest/src/typecheck/collect.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Extra semicolon
// direct call as `__vite_ssr_exports_0__.test()`
if (callee.object?.name?.startsWith('__vite_ssr_')) {
if (object?.name?.startsWith('__vite_ssr_')) {
return getName(callee.property)
}
// call as `__vite_ssr__.test.skip()`
return getName(callee.object?.property)
return getName(object?.property)
}
// unwrap (0, ...)
if (callee.type === "SequenceExpression" && callee.expressions.length === 2) {

Check failure on line 97 in packages/vitest/src/typecheck/collect.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Strings must use singlequote
const [e0, e1] = callee.expressions;

Check failure on line 98 in packages/vitest/src/typecheck/collect.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Extra semicolon
if (e0.type === "Literal" && e0.value === 0) {

Check failure on line 99 in packages/vitest/src/typecheck/collect.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Strings must use singlequote
return getName(e1);

Check failure on line 100 in packages/vitest/src/typecheck/collect.ts

View workflow job for this annotation

GitHub Actions / Lint: node-latest, ubuntu-latest

Extra semicolon
}
}
return null
}
Expand Down

0 comments on commit bcd0624

Please sign in to comment.