[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): fix fixture parsing of lowered async syntax for non arrow functions (#6575)

authored by

Hiroshi Ogawa and committed by
GitHub
(Oct 1, 2024, 1:36 PM +0200) 3de00ab6 e7f35214

+31 -14
+5 -3
packages/runner/src/fixture.ts
··· 214 214 function getUsedProps(fn: Function) { 215 215 let fnString = fn.toString() 216 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)) { 217 + // example code on esbuild-try https://esbuild.github.io/try/#YgAwLjI0LjAALS1zdXBwb3J0ZWQ6YXN5bmMtYXdhaXQ9ZmFsc2UAZQBlbnRyeS50cwBjb25zdCBvID0gewogIGYxOiBhc3luYyAoKSA9PiB7fSwKICBmMjogYXN5bmMgKGEpID0+IHt9LAogIGYzOiBhc3luYyAoYSwgYikgPT4ge30sCiAgZjQ6IGFzeW5jIGZ1bmN0aW9uKGEpIHt9LAogIGY1OiBhc3luYyBmdW5jdGlvbiBmZihhKSB7fSwKICBhc3luYyBmNihhKSB7fSwKCiAgZzE6IGFzeW5jICgpID0+IHt9LAogIGcyOiBhc3luYyAoeyBhIH0pID0+IHt9LAogIGczOiBhc3luYyAoeyBhIH0sIGIpID0+IHt9LAogIGc0OiBhc3luYyBmdW5jdGlvbiAoeyBhIH0pIHt9LAogIGc1OiBhc3luYyBmdW5jdGlvbiBnZyh7IGEgfSkge30sCiAgYXN5bmMgZzYoeyBhIH0pIHt9Cn0 218 + // __async(this, null, function* 219 + // __async(this, arguments, function* 220 + // __async(this, [_0, _1], function* 221 + if (/__async\(this, (?:null|arguments|\[[_0-9, ]*\]), function\*/.test(fnString)) { 220 222 fnString = fnString.split('__async(this,')[1] 221 223 } 222 224 const match = fnString.match(/[^(]*\(([^)]*)/)
+8 -11
test/config/test/fixture-no-async.test.ts
··· 3 3 import { runVitest } from '../../test-utils' 4 4 5 5 test('fixture parsing works for lowered async syntax', async () => { 6 - const { stdout } = await runVitest({ 6 + const { ctx } = await runVitest({ 7 7 root: path.resolve('fixtures/fixture-no-async'), 8 8 reporters: ['tap-flat'], 9 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 - " 10 + expect(ctx?.state.getFiles().map(f => [f.name, f.result?.state])).toMatchInlineSnapshot(` 11 + [ 12 + [ 13 + "basic.test.ts", 14 + "pass", 15 + ], 16 + ] 20 17 `) 21 18 })
+18
test/config/fixtures/fixture-no-async/basic.test.ts
··· 3 3 type Fixture = { 4 4 simple: string, 5 5 nested: string, 6 + notArrow1: string, 7 + notArrow2: string, 8 + notArrow3: string, 6 9 } 7 10 8 11 const test = base.extend<Fixture>({ ··· 12 15 nested: async ({ simple }, use) => { 13 16 await use("nested:" + simple); 14 17 }, 18 + async notArrow1({}, use) { 19 + await use("notArrow1"); 20 + }, 21 + notArrow2: async function({}, use) { 22 + await use("notArrow2"); 23 + }, 24 + notArrow3: async function notArrow3({}, use) { 25 + await use("notArrow3"); 26 + } 15 27 }); 16 28 17 29 test("test sync", ({ simple, nested }) => { ··· 35 47 expect(simple).toBe("simple"); 36 48 expect(nested).toBe("nested:simple") 37 49 }) 50 + 51 + test("test notArrow", async function ({ notArrow1, notArrow2, notArrow3 }) { 52 + expect(notArrow1).toMatchInlineSnapshot(`"notArrow1"`) 53 + expect(notArrow2).toMatchInlineSnapshot(`"notArrow2"`) 54 + expect(notArrow3).toMatchInlineSnapshot(`"notArrow3"`) 55 + });