Skip to content

Commit d73b291

Browse files
authored
test: prettify tests (#9544)
### Description <!-- Please insert your description here and provide especially info about the "what" this PR is solving --> Adding `fails: true` to tests that are supposed to fail, so they are not printed again in CI <!-- You can also add additional context here --> ### 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:`.
1 parent a5acf28 commit d73b291

9 files changed

Lines changed: 36 additions & 35 deletions

File tree

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
import { expect, test } from 'vitest'
2-
import { runVitestCli } from '../../test-utils'
2+
import { runVitest } from '../../test-utils'
33

44
const isTypeStrippingSupported = !!process.features.typescript
55

6-
test('configLoader default', async () => {
7-
const { vitest, exitCode } = await runVitestCli(
8-
'run',
9-
'--root',
10-
'fixtures/config-loader',
11-
)
12-
if (!isTypeStrippingSupported) {
13-
expect(vitest.stderr).toContain('failed to load config')
14-
expect(exitCode).not.toBe(0)
15-
}
16-
else {
17-
expect(exitCode).toBe(0)
18-
}
6+
test.runIf(isTypeStrippingSupported)('configLoader native', async () => {
7+
const { stderr, exitCode } = await runVitest({
8+
root: 'fixtures/config-loader',
9+
$cliOptions: {
10+
configLoader: 'native',
11+
},
12+
})
13+
expect(stderr).toBe('')
14+
expect(exitCode).toBe(0)
1915
})
2016

2117
test('configLoader runner', async () => {
22-
const { vitest, exitCode } = await runVitestCli(
23-
'run',
24-
'--root',
25-
'fixtures/config-loader',
26-
'--configLoader',
27-
'runner',
28-
)
18+
const { vitest, exitCode } = await runVitest({
19+
root: 'fixtures/config-loader',
20+
$cliOptions: {
21+
configLoader: 'runner',
22+
},
23+
})
2924
expect(vitest.stderr).toBe('')
30-
expect(vitest.stdout).toContain('✓ node')
31-
expect(vitest.stdout).toContain('✓ browser (chromium)')
25+
expect(vitest.stdout).toContain('✓ |node|')
26+
expect(vitest.stdout).toContain('✓ |browser (chromium)|')
3227
expect(exitCode).toBe(0)
3328
})

test/cli/test/projects.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ it('correctly inherits the root config', async () => {
121121
it('fails if workspace is empty', async () => {
122122
const { stderr } = await runVitest({
123123
projects: [],
124-
})
124+
}, [], { fails: true })
125125
expect(stderr).toContain('No projects were found. Make sure your configuration is correct. The projects definition: [].')
126126
})
127127

@@ -133,7 +133,7 @@ it('fails if workspace is filtered by the project', async () => {
133133
projects: [
134134
'./vitest.config.js',
135135
],
136-
})
136+
}, [], { fails: true })
137137
expect(stderr).toContain(`No projects were found. Make sure your configuration is correct. The filter matched no projects: non-existing. The projects definition: [
138138
"./vitest.config.js"
139139
].`)

test/cli/test/unhandled-rejections.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('dangerouslyIgnoreUnhandledErrors', () => {
4343
4444
new Promise((_, reject) => reject(new Error("intentional unhandled error")))
4545
`,
46-
}, config)
46+
}, config, { fails: true })
4747
}
4848
})
4949

@@ -59,7 +59,7 @@ test('unhandled rejections of main thread are reported even when no reporter is
5959
config: false,
6060
globalSetup: ['setup-unhandled-rejections.js'],
6161
reporters: [{ onInit: () => {} }],
62-
})
62+
}, { fails: true })
6363

6464
expect(exitCode).toBe(1)
6565
expect(stderr).toContain('Unhandled Rejection')

test/core/test/on-failed.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ it.fails('on-failed', () => {
77
const square4 = 4 ** 2
88

99
onTestFailed(() => {
10-
// eslint-disable-next-line no-console
11-
console.log('Unexpected error encountered, internal states:', { square3, square4 })
1210
collected.push({ square3, square4 })
1311
})
1412

test/core/test/snapshot-file.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ function objectToCSS(selector: string, obj: Record<string, string>) {
88
}
99

1010
describe('snapshots', () => {
11-
const files = import.meta.glob('./fixtures/snapshots/**/input.json', { as: 'raw' })
11+
const files = import.meta.glob('./fixtures/snapshots/**/input.json', {
12+
query: '?raw',
13+
import: 'default',
14+
})
1215

1316
for (const [path, file] of Object.entries(files)) {
1417
test(path, async () => {
15-
const entries = JSON.parse(await file()) as any[]
18+
const entries = JSON.parse(await file() as string) as any[]
1619
await expect(entries.map(i => objectToCSS(i[0], i[1])).join('\n'))
1720
.toMatchFileSnapshot(path.replace('input.json', 'output.css'))
1821
})

test/core/test/tab-effect.spec.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const helloWorld = () => {
66
return joinPath('hello', 'world')
77
}
88

9-
test('Are you mocking me?', () => {
109
// note there are NO indents in this file
1110
// except the next line
1211
// test pass with spaces, test fails with tab
@@ -15,5 +14,7 @@ return {
1514
join: vi.fn().mockReturnValue('goodbye world')
1615
}
1716
})
17+
18+
test('Are you mocking me?', () => {
1819
expect(helloWorld()).toBe('goodbye world')
1920
})

test/core/test/wait.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ describe('waitUntil', () => {
143143

144144
await expect(
145145
vi.waitUntil(callback, {
146-
timeout: 1000,
147-
interval: 600,
146+
timeout: 500,
147+
interval: 400,
148148
}),
149149
).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: Timed out in waitUntil!]`)
150150

test/core/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ export default defineConfig({
158158
if (log.startsWith(`[vitest]`) && log.includes(`did not use 'function' or 'class' in its implementation`)) {
159159
return false
160160
}
161+
if (log.startsWith('Importing from') && log.includes('is deprecated since Vitest 4.1')) {
162+
return false
163+
}
161164
},
162165
projects: [
163166
project('threads', 'red'),

test/test-utils/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { SerializedConfig, WorkerGlobalState } from 'vitest'
44
import type { TestProjectConfiguration } from 'vitest/config'
55
import type {
66
TestCase,
7+
CliOptions as TestCliOptions,
78
TestCollection,
89
TestModule,
910
TestSpecification,
@@ -37,7 +38,7 @@ export interface VitestRunnerCLIOptions {
3738

3839
export interface RunVitestConfig extends TestUserConfig {
3940
$viteConfig?: Omit<ViteUserConfig, 'test'>
40-
$cliOptions?: TestUserConfig
41+
$cliOptions?: TestCliOptions
4142
}
4243

4344
/**

0 commit comments

Comments
 (0)