diff --git a/package.json b/package.json index f7b1a0616bf6..58e823cc265d 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,9 @@ "test": "vitest --api -r test/core", "test:run": "vitest run -r test/core", "test:all": "CI=true pnpm -r --stream run test --allowOnly", - "test:ci": "CI=true pnpm -r --stream --filter !test-fails --filter !test-browser --filter !test-esm --filter !test-browser run test --allowOnly", - "test:ci:vm-threads": "CI=true pnpm -r --stream --filter !test-fails --filter !test-coverage --filter !test-single-thread --filter !test-browser --filter !test-esm --filter !test-browser --filter !example-react-testing-lib-msw run test --allowOnly --pool vmThreads", - "test:ci:no-threads": "CI=true pnpm -r --stream --filter !test-fails --filter !test-vm-threads --filter !test-coverage --filter !test-watch --filter !test-bail --filter !test-esm --filter !test-browser run test --allowOnly --pool forks", + "test:ci": "CI=true pnpm -r --stream --filter !test-browser --filter !test-esm --filter !test-browser run test --allowOnly", + "test:ci:vm-threads": "CI=true pnpm -r --stream --filter !test-coverage --filter !test-single-thread --filter !test-browser --filter !test-esm --filter !test-browser --filter !example-react-testing-lib-msw run test --allowOnly --pool vmThreads", + "test:ci:no-threads": "CI=true pnpm -r --stream --filter !test-vm-threads --filter !test-coverage --filter !test-watch --filter !test-bail --filter !test-esm --filter !test-browser run test --allowOnly --pool forks", "typecheck": "tsc -p tsconfig.check.json --noEmit", "typecheck:why": "tsc -p tsconfig.check.json --noEmit --explainFiles > explainTypes.txt", "ui:build": "vite build packages/ui", diff --git a/packages/runner/src/fixture.ts b/packages/runner/src/fixture.ts index d85cd6e3fbd7..026cdf4f19ab 100644 --- a/packages/runner/src/fixture.ts +++ b/packages/runner/src/fixture.ts @@ -133,7 +133,7 @@ function resolveDeps(fixtures: FixtureItem[], depSet = new Set(), p return } if (depSet.has(fixture)) - throw new Error('circular fixture dependency') + throw new Error(`Circular fixture dependency detected: ${fixture.prop} <- ${[...depSet].reverse().map(d => d.prop).join(' <- ')}`) depSet.add(fixture) resolveDeps(fixture.deps, depSet, pendingFixtures) @@ -155,7 +155,7 @@ function getUsedProps(fn: Function) { const first = args[0] if (!(first.startsWith('{') && first.endsWith('}'))) - throw new Error('the first argument must use object destructuring pattern') + throw new Error(`The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "${first}".`) const _first = first.slice(1, -1).replace(/\s/g, '') const props = splitByComma(_first).map((prop) => { @@ -164,7 +164,7 @@ function getUsedProps(fn: Function) { const last = props.at(-1) if (last && last.startsWith('...')) - throw new Error('Rest parameters are not supported') + throw new Error(`Rest parameters are not supported in fixtures, received "${last}".`) return props } diff --git a/test/fails/fixtures/test-extend/fixture-error.test.ts b/test/fails/fixtures/test-extend/fixture-error.test.ts index 70fd35d436c6..f02431a627b4 100644 --- a/test/fails/fixtures/test-extend/fixture-error.test.ts +++ b/test/fails/fixtures/test-extend/fixture-error.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expectTypeOf, test } from 'vitest' +import { afterEach, beforeEach, describe, expectTypeOf, test, expect } from 'vitest' describe('error thrown in beforeEach fixtures', () => { const myTest = test.extend<{ a: never }>({ @@ -38,3 +38,16 @@ describe('error thrown in test fixtures', () => { // eslint-disable-next-line unused-imports/no-unused-vars myTest('fixture errors', ({ a }) => {}) }) + +// TODO: enable when #4669 is fixed +describe.skip('correctly fails when test times out', () => { + const myTest = test.extend<{ a: number }>({ + a: async ({}, use) => { + await use(2) + }, + }) + myTest('test times out', async ({ a }) => { + await new Promise((resolve) => setTimeout(resolve, 1000)) + expect(a).toBe(2) + }, 20) +}) diff --git a/test/fails/test/__snapshots__/runner.test.ts.snap b/test/fails/test/__snapshots__/runner.test.ts.snap index 7c060bad49dc..23b1824e9134 100644 --- a/test/fails/test/__snapshots__/runner.test.ts.snap +++ b/test/fails/test/__snapshots__/runner.test.ts.snap @@ -40,7 +40,7 @@ TypeError: failure TypeError: failure" `; -exports[`should fail test-extend/circular-dependency.test.ts > test-extend/circular-dependency.test.ts 1`] = `"Error: circular fixture dependency"`; +exports[`should fail test-extend/circular-dependency.test.ts > test-extend/circular-dependency.test.ts 1`] = `"Error: Circular fixture dependency detected: a <- b <- a"`; exports[`should fail test-extend/fixture-error.test.ts > test-extend/fixture-error.test.ts 1`] = ` "Error: Error thrown in test fixture @@ -48,17 +48,17 @@ Error: Error thrown in afterEach fixture Error: Error thrown in beforeEach fixture" `; -exports[`should fail test-extend/fixture-rest-params.test.ts > test-extend/fixture-rest-params.test.ts 1`] = `"Error: the first argument must use object destructuring pattern"`; +exports[`should fail test-extend/fixture-rest-params.test.ts > test-extend/fixture-rest-params.test.ts 1`] = `"Error: The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "...rest"."`; -exports[`should fail test-extend/fixture-rest-props.test.ts > test-extend/fixture-rest-props.test.ts 1`] = `"Error: Rest parameters are not supported"`; +exports[`should fail test-extend/fixture-rest-props.test.ts > test-extend/fixture-rest-props.test.ts 1`] = `"Error: Rest parameters are not supported in fixtures, received "...rest"."`; -exports[`should fail test-extend/fixture-without-destructuring.test.ts > test-extend/fixture-without-destructuring.test.ts 1`] = `"Error: the first argument must use object destructuring pattern"`; +exports[`should fail test-extend/fixture-without-destructuring.test.ts > test-extend/fixture-without-destructuring.test.ts 1`] = `"Error: The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "context"."`; -exports[`should fail test-extend/test-rest-params.test.ts > test-extend/test-rest-params.test.ts 1`] = `"Error: the first argument must use object destructuring pattern"`; +exports[`should fail test-extend/test-rest-params.test.ts > test-extend/test-rest-params.test.ts 1`] = `"Error: The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "...rest"."`; -exports[`should fail test-extend/test-rest-props.test.ts > test-extend/test-rest-props.test.ts 1`] = `"Error: Rest parameters are not supported"`; +exports[`should fail test-extend/test-rest-props.test.ts > test-extend/test-rest-props.test.ts 1`] = `"Error: Rest parameters are not supported in fixtures, received "...rest"."`; -exports[`should fail test-extend/test-without-destructuring.test.ts > test-extend/test-without-destructuring.test.ts 1`] = `"Error: the first argument must use object destructuring pattern"`; +exports[`should fail test-extend/test-without-destructuring.test.ts > test-extend/test-without-destructuring.test.ts 1`] = `"Error: The first argument inside a fixture must use object destructuring pattern, e.g. ({ test } => {}). Instead, received "context"."`; exports[`should fail test-timeout.test.ts > test-timeout.test.ts 1`] = ` "Error: Test timed out in 200ms.