From d73b29114b6f2f65cd50ec6307537eb8ee0f5b93 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 28 Jan 2026 17:12:39 +0100 Subject: [PATCH] test: prettify tests (#9544) ### Description Adding `fails: true` to tests that are supposed to fail, so they are not printed again in CI ### Please don't delete this checklist! Before submitting the PR, please make sure you do the following: - [ ] It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed. - [ ] Ideally, include a test that fails without this PR but passes with it. - [ ] Please, don't make changes to `pnpm-lock.yaml` unless you introduce a new test example. - [ ] Please check [Allow edits by maintainers](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork) to make review process faster. Note that this option is not available for repositories that are owned by Github organizations. ### Tests - [ ] Run the tests with `pnpm test:ci`. ### Documentation - [ ] If you introduce new functionality, document it. You can run documentation with `pnpm run docs` command. ### Changesets - [ ] Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with `feat:`, `fix:`, `perf:`, `docs:`, or `chore:`. --- test/cli/test/config-loader.test.ts | 41 ++++++++++------------ test/cli/test/projects.test.ts | 4 +-- test/cli/test/unhandled-rejections.test.ts | 4 +-- test/core/test/on-failed.test.ts | 2 -- test/core/test/snapshot-file.test.ts | 7 ++-- test/core/test/tab-effect.spec.mjs | 3 +- test/core/test/wait.test.ts | 4 +-- test/core/vite.config.ts | 3 ++ test/test-utils/index.ts | 3 +- 9 files changed, 36 insertions(+), 35 deletions(-) diff --git a/test/cli/test/config-loader.test.ts b/test/cli/test/config-loader.test.ts index e5700e171..a7c86b124 100644 --- a/test/cli/test/config-loader.test.ts +++ b/test/cli/test/config-loader.test.ts @@ -1,33 +1,28 @@ import { expect, test } from 'vitest' -import { runVitestCli } from '../../test-utils' +import { runVitest } from '../../test-utils' const isTypeStrippingSupported = !!process.features.typescript -test('configLoader default', async () => { - const { vitest, exitCode } = await runVitestCli( - 'run', - '--root', - 'fixtures/config-loader', - ) - if (!isTypeStrippingSupported) { - expect(vitest.stderr).toContain('failed to load config') - expect(exitCode).not.toBe(0) - } - else { - expect(exitCode).toBe(0) - } +test.runIf(isTypeStrippingSupported)('configLoader native', async () => { + const { stderr, exitCode } = await runVitest({ + root: 'fixtures/config-loader', + $cliOptions: { + configLoader: 'native', + }, + }) + expect(stderr).toBe('') + expect(exitCode).toBe(0) }) test('configLoader runner', async () => { - const { vitest, exitCode } = await runVitestCli( - 'run', - '--root', - 'fixtures/config-loader', - '--configLoader', - 'runner', - ) + const { vitest, exitCode } = await runVitest({ + root: 'fixtures/config-loader', + $cliOptions: { + configLoader: 'runner', + }, + }) expect(vitest.stderr).toBe('') - expect(vitest.stdout).toContain('✓ node') - expect(vitest.stdout).toContain('✓ browser (chromium)') + expect(vitest.stdout).toContain('✓ |node|') + expect(vitest.stdout).toContain('✓ |browser (chromium)|') expect(exitCode).toBe(0) }) diff --git a/test/cli/test/projects.test.ts b/test/cli/test/projects.test.ts index a18ab39f9..4ca11b2e5 100644 --- a/test/cli/test/projects.test.ts +++ b/test/cli/test/projects.test.ts @@ -121,7 +121,7 @@ it('correctly inherits the root config', async () => { it('fails if workspace is empty', async () => { const { stderr } = await runVitest({ projects: [], - }) + }, [], { fails: true }) expect(stderr).toContain('No projects were found. Make sure your configuration is correct. The projects definition: [].') }) @@ -133,7 +133,7 @@ it('fails if workspace is filtered by the project', async () => { projects: [ './vitest.config.js', ], - }) + }, [], { fails: true }) expect(stderr).toContain(`No projects were found. Make sure your configuration is correct. The filter matched no projects: non-existing. The projects definition: [ "./vitest.config.js" ].`) diff --git a/test/cli/test/unhandled-rejections.test.ts b/test/cli/test/unhandled-rejections.test.ts index 27e5d3f22..891ba38e0 100644 --- a/test/cli/test/unhandled-rejections.test.ts +++ b/test/cli/test/unhandled-rejections.test.ts @@ -43,7 +43,7 @@ describe('dangerouslyIgnoreUnhandledErrors', () => { new Promise((_, reject) => reject(new Error("intentional unhandled error"))) `, - }, config) + }, config, { fails: true }) } }) @@ -59,7 +59,7 @@ test('unhandled rejections of main thread are reported even when no reporter is config: false, globalSetup: ['setup-unhandled-rejections.js'], reporters: [{ onInit: () => {} }], - }) + }, { fails: true }) expect(exitCode).toBe(1) expect(stderr).toContain('Unhandled Rejection') diff --git a/test/core/test/on-failed.test.ts b/test/core/test/on-failed.test.ts index 122811778..c674e6d12 100644 --- a/test/core/test/on-failed.test.ts +++ b/test/core/test/on-failed.test.ts @@ -7,8 +7,6 @@ it.fails('on-failed', () => { const square4 = 4 ** 2 onTestFailed(() => { - // eslint-disable-next-line no-console - console.log('Unexpected error encountered, internal states:', { square3, square4 }) collected.push({ square3, square4 }) }) diff --git a/test/core/test/snapshot-file.test.ts b/test/core/test/snapshot-file.test.ts index 5a852473d..f6e54c942 100644 --- a/test/core/test/snapshot-file.test.ts +++ b/test/core/test/snapshot-file.test.ts @@ -8,11 +8,14 @@ function objectToCSS(selector: string, obj: Record) { } describe('snapshots', () => { - const files = import.meta.glob('./fixtures/snapshots/**/input.json', { as: 'raw' }) + const files = import.meta.glob('./fixtures/snapshots/**/input.json', { + query: '?raw', + import: 'default', + }) for (const [path, file] of Object.entries(files)) { test(path, async () => { - const entries = JSON.parse(await file()) as any[] + const entries = JSON.parse(await file() as string) as any[] await expect(entries.map(i => objectToCSS(i[0], i[1])).join('\n')) .toMatchFileSnapshot(path.replace('input.json', 'output.css')) }) diff --git a/test/core/test/tab-effect.spec.mjs b/test/core/test/tab-effect.spec.mjs index 26718e1a7..af0a1b176 100644 --- a/test/core/test/tab-effect.spec.mjs +++ b/test/core/test/tab-effect.spec.mjs @@ -6,7 +6,6 @@ const helloWorld = () => { return joinPath('hello', 'world') } -test('Are you mocking me?', () => { // note there are NO indents in this file // except the next line // test pass with spaces, test fails with tab @@ -15,5 +14,7 @@ return { join: vi.fn().mockReturnValue('goodbye world') } }) + +test('Are you mocking me?', () => { expect(helloWorld()).toBe('goodbye world') }) diff --git a/test/core/test/wait.test.ts b/test/core/test/wait.test.ts index ee4cb456d..30cfe247c 100644 --- a/test/core/test/wait.test.ts +++ b/test/core/test/wait.test.ts @@ -143,8 +143,8 @@ describe('waitUntil', () => { await expect( vi.waitUntil(callback, { - timeout: 1000, - interval: 600, + timeout: 500, + interval: 400, }), ).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: Timed out in waitUntil!]`) diff --git a/test/core/vite.config.ts b/test/core/vite.config.ts index ff2ee56b3..92e17c3f3 100644 --- a/test/core/vite.config.ts +++ b/test/core/vite.config.ts @@ -158,6 +158,9 @@ export default defineConfig({ if (log.startsWith(`[vitest]`) && log.includes(`did not use 'function' or 'class' in its implementation`)) { return false } + if (log.startsWith('Importing from') && log.includes('is deprecated since Vitest 4.1')) { + return false + } }, projects: [ project('threads', 'red'), diff --git a/test/test-utils/index.ts b/test/test-utils/index.ts index ff69b11b9..41324254f 100644 --- a/test/test-utils/index.ts +++ b/test/test-utils/index.ts @@ -4,6 +4,7 @@ import type { SerializedConfig, WorkerGlobalState } from 'vitest' import type { TestProjectConfiguration } from 'vitest/config' import type { TestCase, + CliOptions as TestCliOptions, TestCollection, TestModule, TestSpecification, @@ -37,7 +38,7 @@ export interface VitestRunnerCLIOptions { export interface RunVitestConfig extends TestUserConfig { $viteConfig?: Omit - $cliOptions?: TestUserConfig + $cliOptions?: TestCliOptions } /** -- 2.51.2