mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
fix(runner): support fixture parsing of lowered async syntax (#6531)
This commit is contained in:
parent
fb79792dc9
commit
b553c7d6d5
@ -212,7 +212,14 @@ function resolveDeps(
|
||||
}
|
||||
|
||||
function getUsedProps(fn: Function) {
|
||||
const match = fn.toString().match(/[^(]*\(([^)]*)/)
|
||||
let fnString = fn.toString()
|
||||
// match lowered async function and strip it off
|
||||
// (_0) => __async(this, [_0], function* (x) { ... })
|
||||
// (_0, _1) => __async(this, [_0, _1], function* (x, y) { ... })
|
||||
if (/^\([_0-9, ]*\)\s*=>\s*__async\(this,/.test(fnString)) {
|
||||
fnString = fnString.split('__async(this,')[1]
|
||||
}
|
||||
const match = fnString.match(/[^(]*\(([^)]*)/)
|
||||
if (!match) {
|
||||
return []
|
||||
}
|
||||
|
||||
37
test/config/fixtures/fixture-no-async/basic.test.ts
Normal file
37
test/config/fixtures/fixture-no-async/basic.test.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { test as base, expect } from "vitest";
|
||||
|
||||
type Fixture = {
|
||||
simple: string,
|
||||
nested: string,
|
||||
}
|
||||
|
||||
const test = base.extend<Fixture>({
|
||||
simple: async ({}, use) => {
|
||||
await use("simple");
|
||||
},
|
||||
nested: async ({ simple }, use) => {
|
||||
await use("nested:" + simple);
|
||||
},
|
||||
});
|
||||
|
||||
test("test sync", ({ simple, nested }) => {
|
||||
expect(simple).toBe("simple");
|
||||
expect(nested).toBe("nested:simple")
|
||||
});
|
||||
|
||||
test("test async", async ({ simple, nested }) => {
|
||||
expect(simple).toBe("simple");
|
||||
expect(nested).toBe("nested:simple")
|
||||
});
|
||||
|
||||
test.for([1, 2])("test.for sync %i", (i, { expect, simple, nested }) => {
|
||||
expect(i).toBeTypeOf("number")
|
||||
expect(simple).toBe("simple");
|
||||
expect(nested).toBe("nested:simple")
|
||||
})
|
||||
|
||||
test.for([1, 2])("test.for async %i", async (i, { expect, simple, nested }) => {
|
||||
expect(i).toBeTypeOf("number")
|
||||
expect(simple).toBe("simple");
|
||||
expect(nested).toBe("nested:simple")
|
||||
})
|
||||
9
test/config/fixtures/fixture-no-async/vitest.config.ts
Normal file
9
test/config/fixtures/fixture-no-async/vitest.config.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
export default defineConfig({
|
||||
esbuild: {
|
||||
supported: {
|
||||
"async-await": false,
|
||||
},
|
||||
},
|
||||
});
|
||||
21
test/config/test/fixture-no-async.test.ts
Normal file
21
test/config/test/fixture-no-async.test.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import path from 'node:path'
|
||||
import { expect, test } from 'vitest'
|
||||
import { runVitest } from '../../test-utils'
|
||||
|
||||
test('fixture parsing works for lowered async syntax', async () => {
|
||||
const { stdout } = await runVitest({
|
||||
root: path.resolve('fixtures/fixture-no-async'),
|
||||
reporters: ['tap-flat'],
|
||||
})
|
||||
expect(stdout.replaceAll(/\s*# time=.*/g, '')).toMatchInlineSnapshot(`
|
||||
"TAP version 13
|
||||
1..6
|
||||
ok 1 - basic.test.ts > test sync
|
||||
ok 2 - basic.test.ts > test async
|
||||
ok 3 - basic.test.ts > test.for sync 1
|
||||
ok 4 - basic.test.ts > test.for sync 2
|
||||
ok 5 - basic.test.ts > test.for async 1
|
||||
ok 6 - basic.test.ts > test.for async 2
|
||||
"
|
||||
`)
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user