Skip to content

Commit

Permalink
fix: describe async support (#750)
Browse files Browse the repository at this point in the history
* Revert "fix: remove `describe` async support (#746)"

This reverts commit f9b52c1.

* fix: collect nested suite serially
  • Loading branch information
antfu committed Feb 14, 2022
1 parent e72b881 commit d4415fe
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/lit/test/basic.test.ts
Expand Up @@ -7,7 +7,7 @@ declare global {
interface Window extends IWindow {}
}

describe('Button with increment', () => {
describe('Button with increment', async() => {
beforeEach(async() => {
document.body.innerHTML = '<my-button name="World"></my-button>'
await window.happyDOM.whenAsyncComplete()
Expand Down
2 changes: 1 addition & 1 deletion examples/puppeteer/test/basic.test.ts
Expand Up @@ -4,7 +4,7 @@ import type { PreviewServer } from 'vite'
import puppeteer from 'puppeteer'
import type { Browser, Page } from 'puppeteer'

describe('basic', () => {
describe('basic', async() => {
let server: PreviewServer
let browser: Browser
let page: Page
Expand Down
2 changes: 1 addition & 1 deletion examples/react-testing-lib/src/components/input.test.tsx
Expand Up @@ -2,7 +2,7 @@ import '@testing-library/jest-dom'
import { render, screen, userEvent } from '../utils/test-utils'
import { Input } from './Input'

describe('Input', () => {
describe('Input', async() => {
it('should render the input', () => {
render(
<Input
Expand Down
10 changes: 5 additions & 5 deletions packages/vitest/src/runtime/suite.ts
@@ -1,5 +1,5 @@
import { format } from 'util'
import type { File, MutableArray, RunMode, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Test, TestAPI, TestFunction } from '../types'
import type { File, MutableArray, RunMode, Suite, SuiteAPI, SuiteCollector, SuiteFactory, SuiteHooks, Task, Test, TestAPI, TestFunction } from '../types'
import { isObject, noop, toArray } from '../utils'
import { createChainable } from './chain'
import { collectTask, context, normalizeTest, runWithSuite } from './context'
Expand Down Expand Up @@ -114,10 +114,10 @@ function createSuiteCollector(name: string, factory: SuiteFactory = () => { }, m
if (factory)
await runWithSuite(collector, () => factory(test))

const allChildren = await Promise.all(
[...factoryQueue, ...tasks]
.map(i => i.type === 'collector' ? i.collect(file) : i),
)
const allChildren: Task[] = []

for (const i of [...factoryQueue, ...tasks])
allChildren.push(i.type === 'collector' ? await i.collect(file) : i)

suite.file = file
suite.tasks = allChildren
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/types/tasks.ts
Expand Up @@ -78,7 +78,7 @@ export interface SuiteCollector {
on: <T extends keyof SuiteHooks>(name: T, ...fn: SuiteHooks[T]) => void
}

export type SuiteFactory = (test: (name: string, fn: TestFunction) => void) => void
export type SuiteFactory = (test: (name: string, fn: TestFunction) => void) => Awaitable<void>

export interface RuntimeContext {
tasks: (SuiteCollector | Test)[]
Expand Down
4 changes: 2 additions & 2 deletions test/fails/test/runner.test.ts
Expand Up @@ -3,9 +3,9 @@ import fg from 'fast-glob'
import { execa } from 'execa'
import { describe, expect, it } from 'vitest'

describe('should fails', () => {
describe('should fails', async() => {
const root = resolve(__dirname, '../fixtures')
const files = fg.sync('*.test.ts', { cwd: root })
const files = await fg('*.test.ts', { cwd: root })

for (const file of files) {
it(file, async() => {
Expand Down

0 comments on commit d4415fe

Please sign in to comment.