diff --git a/packages/runner/src/fixture.ts b/packages/runner/src/fixture.ts index e67fd26e8694..6faa14457958 100644 --- a/packages/runner/src/fixture.ts +++ b/packages/runner/src/fixture.ts @@ -214,9 +214,11 @@ function resolveDeps( function getUsedProps(fn: Function) { 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)) { + // example code on esbuild-try https://esbuild.github.io/try/#YgAwLjI0LjAALS1zdXBwb3J0ZWQ6YXN5bmMtYXdhaXQ9ZmFsc2UAZQBlbnRyeS50cwBjb25zdCBvID0gewogIGYxOiBhc3luYyAoKSA9PiB7fSwKICBmMjogYXN5bmMgKGEpID0+IHt9LAogIGYzOiBhc3luYyAoYSwgYikgPT4ge30sCiAgZjQ6IGFzeW5jIGZ1bmN0aW9uKGEpIHt9LAogIGY1OiBhc3luYyBmdW5jdGlvbiBmZihhKSB7fSwKICBhc3luYyBmNihhKSB7fSwKCiAgZzE6IGFzeW5jICgpID0+IHt9LAogIGcyOiBhc3luYyAoeyBhIH0pID0+IHt9LAogIGczOiBhc3luYyAoeyBhIH0sIGIpID0+IHt9LAogIGc0OiBhc3luYyBmdW5jdGlvbiAoeyBhIH0pIHt9LAogIGc1OiBhc3luYyBmdW5jdGlvbiBnZyh7IGEgfSkge30sCiAgYXN5bmMgZzYoeyBhIH0pIHt9Cn0 + // __async(this, null, function* + // __async(this, arguments, function* + // __async(this, [_0, _1], function* + if (/__async\(this, (?:null|arguments|\[[_0-9, ]*\]), function\*/.test(fnString)) { fnString = fnString.split('__async(this,')[1] } const match = fnString.match(/[^(]*\(([^)]*)/) diff --git a/test/config/fixtures/fixture-no-async/basic.test.ts b/test/config/fixtures/fixture-no-async/basic.test.ts index 3448328f0b47..71d8847994f0 100644 --- a/test/config/fixtures/fixture-no-async/basic.test.ts +++ b/test/config/fixtures/fixture-no-async/basic.test.ts @@ -3,6 +3,9 @@ import { test as base, expect } from "vitest"; type Fixture = { simple: string, nested: string, + notArrow1: string, + notArrow2: string, + notArrow3: string, } const test = base.extend({ @@ -12,6 +15,15 @@ const test = base.extend({ nested: async ({ simple }, use) => { await use("nested:" + simple); }, + async notArrow1({}, use) { + await use("notArrow1"); + }, + notArrow2: async function({}, use) { + await use("notArrow2"); + }, + notArrow3: async function notArrow3({}, use) { + await use("notArrow3"); + } }); test("test sync", ({ simple, nested }) => { @@ -24,6 +36,12 @@ test("test async", async ({ simple, nested }) => { expect(nested).toBe("nested:simple") }); +test("test notArrow", async function ({ notArrow1, notArrow2, notArrow3 }) { + expect(notArrow1).toMatchInlineSnapshot(`"notArrow1"`) + expect(notArrow2).toMatchInlineSnapshot(`"notArrow2"`) + expect(notArrow3).toMatchInlineSnapshot(`"notArrow3"`) +}); + test.for([1, 2])("test.for sync %i", (i, { expect, simple, nested }) => { expect(i).toBeTypeOf("number") expect(simple).toBe("simple");