[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

fix(runner): support fixture parsing of lowered async syntax (#6531)

authored by

Hiroshi Ogawa and committed by
GitHub
(Sep 25, 2024, 10:32 AM +0200) b553c7d6 fb79792d

+75 -1
+8 -1
packages/runner/src/fixture.ts
··· 212 212 } 213 213 214 214 function getUsedProps(fn: Function) { 215 - const match = fn.toString().match(/[^(]*\(([^)]*)/) 215 + let fnString = fn.toString() 216 + // match lowered async function and strip it off 217 + // (_0) => __async(this, [_0], function* (x) { ... }) 218 + // (_0, _1) => __async(this, [_0, _1], function* (x, y) { ... }) 219 + if (/^\([_0-9, ]*\)\s*=>\s*__async\(this,/.test(fnString)) { 220 + fnString = fnString.split('__async(this,')[1] 221 + } 222 + const match = fnString.match(/[^(]*\(([^)]*)/) 216 223 if (!match) { 217 224 return [] 218 225 }
+21
test/config/test/fixture-no-async.test.ts
··· 1 + import path from 'node:path' 2 + import { expect, test } from 'vitest' 3 + import { runVitest } from '../../test-utils' 4 + 5 + test('fixture parsing works for lowered async syntax', async () => { 6 + const { stdout } = await runVitest({ 7 + root: path.resolve('fixtures/fixture-no-async'), 8 + reporters: ['tap-flat'], 9 + }) 10 + expect(stdout.replaceAll(/\s*# time=.*/g, '')).toMatchInlineSnapshot(` 11 + "TAP version 13 12 + 1..6 13 + ok 1 - basic.test.ts > test sync 14 + ok 2 - basic.test.ts > test async 15 + ok 3 - basic.test.ts > test.for sync 1 16 + ok 4 - basic.test.ts > test.for sync 2 17 + ok 5 - basic.test.ts > test.for async 1 18 + ok 6 - basic.test.ts > test.for async 2 19 + " 20 + `) 21 + })
+37
test/config/fixtures/fixture-no-async/basic.test.ts
··· 1 + import { test as base, expect } from "vitest"; 2 + 3 + type Fixture = { 4 + simple: string, 5 + nested: string, 6 + } 7 + 8 + const test = base.extend<Fixture>({ 9 + simple: async ({}, use) => { 10 + await use("simple"); 11 + }, 12 + nested: async ({ simple }, use) => { 13 + await use("nested:" + simple); 14 + }, 15 + }); 16 + 17 + test("test sync", ({ simple, nested }) => { 18 + expect(simple).toBe("simple"); 19 + expect(nested).toBe("nested:simple") 20 + }); 21 + 22 + test("test async", async ({ simple, nested }) => { 23 + expect(simple).toBe("simple"); 24 + expect(nested).toBe("nested:simple") 25 + }); 26 + 27 + test.for([1, 2])("test.for sync %i", (i, { expect, simple, nested }) => { 28 + expect(i).toBeTypeOf("number") 29 + expect(simple).toBe("simple"); 30 + expect(nested).toBe("nested:simple") 31 + }) 32 + 33 + test.for([1, 2])("test.for async %i", async (i, { expect, simple, nested }) => { 34 + expect(i).toBeTypeOf("number") 35 + expect(simple).toBe("simple"); 36 + expect(nested).toBe("nested:simple") 37 + })
+9
test/config/fixtures/fixture-no-async/vitest.config.ts
··· 1 + import { defineConfig } from "vitest/config"; 2 + 3 + export default defineConfig({ 4 + esbuild: { 5 + supported: { 6 + "async-await": false, 7 + }, 8 + }, 9 + });