Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: describe async support #750

Merged
merged 2 commits into from Feb 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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