Skip to content

Commit ed3a95b

Browse files
authored
Merge branch 'main' into fix-async-assertion-auto-await-inside-timeout
2 parents 13ed041 + 12e702b commit ed3a95b

File tree

13 files changed

+288
-17
lines changed

13 files changed

+288
-17
lines changed

docs/.vitepress/components.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export {}
77
/* prettier-ignore */
88
declare module 'vue' {
99
export interface GlobalComponents {
10+
AsideViteConf: typeof import('./components/AsideViteConf.vue')['default']
1011
Contributors: typeof import('./components/Contributors.vue')['default']
1112
CourseLink: typeof import('./components/CourseLink.vue')['default']
1213
FeaturesList: typeof import('./components/FeaturesList.vue')['default']
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<template>
2+
<a
3+
class="viteconf"
4+
href="https://viteconf.org/?utm=vitest-sidebar"
5+
target="_blank"
6+
>
7+
<img width="22" height="22" src="/viteconf.svg">
8+
<span>
9+
<p class="extra-info">Building Together</p>
10+
<p class="heading">ViteConf 24 - Oct 3</p>
11+
<p class="extra-info">Get your free ticket!</p>
12+
</span>
13+
</a>
14+
</template>
15+
16+
<style scoped>
17+
.viteconf {
18+
margin-top: 1rem;
19+
margin-bottom: 1rem;
20+
border-radius: 14px;
21+
padding-top: 0.4rem;
22+
padding-bottom: 0.4rem;
23+
position: relative;
24+
font-size: 0.9rem;
25+
font-weight: 700;
26+
line-height: 1.1rem;
27+
display: flex;
28+
align-items: center;
29+
justify-content: center;
30+
width: 100%;
31+
gap: 1rem;
32+
background-color: var(--vp-c-bg-soft);
33+
border: 2px solid var(--vp-c-bg-soft);
34+
transition: border-color 0.5s;
35+
filter: grayscale(1);
36+
}
37+
.viteconf:hover {
38+
border: 2px solid #9499ff;
39+
filter: none;
40+
}
41+
.viteconf img {
42+
transition: transform 0.5s;
43+
transform: scale(1.25);
44+
}
45+
.viteconf:hover img {
46+
transform: scale(1.75);
47+
}
48+
49+
.viteconf .heading {
50+
color: var(--vt-c-text-1);
51+
}
52+
.viteconf:hover .heading {
53+
background-image: linear-gradient(
54+
120deg,
55+
#b047ff 16%,
56+
#9499ff,
57+
#9499ff
58+
);
59+
background-clip: text;
60+
-webkit-background-clip: text;
61+
-webkit-text-fill-color: transparent;
62+
}
63+
.viteconf .extra-info {
64+
color: var(--vp-c-text-1);
65+
opacity: 0;
66+
font-size: 0.7rem;
67+
padding-left: 0.1rem;
68+
transition: opacity 0.5s;
69+
}
70+
.viteconf:hover .extra-info {
71+
opacity: 0.9;
72+
}
73+
</style>

docs/.vitepress/theme/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
99
import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
1010
import HomePage from '../components/HomePage.vue'
1111
import Version from '../components/Version.vue'
12+
import AsideViteConf from '../components/AsideViteConf.vue'
1213
import '@shikijs/vitepress-twoslash/style.css'
1314

1415
if (inBrowser) {
@@ -20,6 +21,7 @@ export default {
2021
Layout() {
2122
return h(DefaultTheme.Layout, null, {
2223
'home-features-after': () => h(HomePage),
24+
'aside-ads-before': () => h(AsideViteConf),
2325
})
2426
},
2527
enhanceApp({ app }) {

docs/guide/cli.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ vitest list filename.spec.ts -t="some-test" --json=./file.json
8686

8787
If `--json` flag doesn't receive a value, it will output the JSON into stdout.
8888

89+
You also can pass down `--filesOnly` flag to print the test files only:
90+
91+
```bash
92+
vitest list --filesOnly
93+
```
94+
95+
```txt
96+
tests/test1.test.ts
97+
tests/test2.test.ts
98+
```
99+
89100
## Options
90101

91102
::: tip

docs/public/viteconf.svg

Lines changed: 24 additions & 0 deletions
Loading

packages/vite-node/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@
8585
"cac": "^6.7.14",
8686
"debug": "^4.3.6",
8787
"pathe": "^1.1.2",
88-
"tinyrainbow": "^1.2.0",
8988
"vite": "^5.0.0"
9089
},
9190
"devDependencies": {
9291
"@jridgewell/trace-mapping": "^0.3.25",
93-
"@types/debug": "^4.1.12"
92+
"@types/debug": "^4.1.12",
93+
"tinyrainbow": "^1.2.0"
9494
}
9595
}

packages/vitest/LICENSE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,35 @@ Repository: sindresorhus/p-locate
12351235
12361236
---------------------------------------
12371237

1238+
## package-manager-detector
1239+
License: MIT
1240+
By: Anthony Fu
1241+
Repository: git+https://github.com/antfu-collective/package-manager-detector.git
1242+
1243+
> MIT License
1244+
>
1245+
> Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
1246+
>
1247+
> Permission is hereby granted, free of charge, to any person obtaining a copy
1248+
> of this software and associated documentation files (the "Software"), to deal
1249+
> in the Software without restriction, including without limitation the rights
1250+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1251+
> copies of the Software, and to permit persons to whom the Software is
1252+
> furnished to do so, subject to the following conditions:
1253+
>
1254+
> The above copyright notice and this permission notice shall be included in all
1255+
> copies or substantial portions of the Software.
1256+
>
1257+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1258+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1259+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1260+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1261+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1262+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1263+
> SOFTWARE.
1264+
1265+
---------------------------------------
1266+
12381267
## picomatch
12391268
License: MIT
12401269
By: Jon Schlinkert

packages/vitest/src/node/cli/cac.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -300,24 +300,30 @@ async function collect(mode: VitestRunMode, cliFilters: string[], options: CliOp
300300
catch {}
301301

302302
try {
303-
const { prepareVitest, processCollected } = await import('./cli-api')
303+
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api')
304304
const ctx = await prepareVitest(mode, {
305305
...normalizeCliOptions(options),
306306
watch: false,
307307
run: true,
308308
})
309+
if (!options.filesOnly) {
310+
const { tests, errors } = await ctx.collect(cliFilters.map(normalize))
311+
312+
if (errors.length) {
313+
console.error('\nThere were unhandled errors during test collection')
314+
errors.forEach(e => console.error(e))
315+
console.error('\n\n')
316+
await ctx.close()
317+
return
318+
}
309319

310-
const { tests, errors } = await ctx.collect(cliFilters.map(normalize))
311-
312-
if (errors.length) {
313-
console.error('\nThere were unhandled errors during test collection')
314-
errors.forEach(e => console.error(e))
315-
console.error('\n\n')
316-
await ctx.close()
317-
return
320+
processCollected(ctx, tests, options)
321+
}
322+
else {
323+
const files = await ctx.listFiles(cliFilters.map(normalize))
324+
outputFileList(files, options)
318325
}
319326

320-
processCollected(ctx, tests, options)
321327
await ctx.close()
322328
}
323329
catch (e) {

packages/vitest/src/node/cli/cli-api.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable no-console */
22

33
import { mkdirSync, writeFileSync } from 'node:fs'
4-
import { dirname, resolve } from 'pathe'
4+
import { dirname, relative, resolve } from 'pathe'
55
import type { UserConfig as ViteUserConfig } from 'vite'
66
import type { File, Suite, Task } from '@vitest/runner'
77
import { CoverageProviderMap } from '../../integrations/coverage'
@@ -12,6 +12,7 @@ import type { Vitest, VitestOptions } from '../core'
1212
import { FilesNotFoundError, GitNotFoundError } from '../errors'
1313
import { getNames, getTests } from '../../utils'
1414
import type { UserConfig, VitestEnvironment, VitestRunMode } from '../types/config'
15+
import type { WorkspaceSpec } from '../pool'
1516

1617
export interface CliOptions extends UserConfig {
1718
/**
@@ -26,6 +27,10 @@ export interface CliOptions extends UserConfig {
2627
* Output collected tests as JSON or to a file
2728
*/
2829
json?: string | boolean
30+
/**
31+
* Output collected test files only
32+
*/
33+
filesOnly?: boolean
2934
}
3035

3136
/**
@@ -184,6 +189,48 @@ export function processCollected(ctx: Vitest, files: File[], options: CliOptions
184189
return formatCollectedAsString(files).forEach(test => console.log(test))
185190
}
186191

192+
export function outputFileList(files: WorkspaceSpec[], options: CliOptions) {
193+
if (typeof options.json !== 'undefined') {
194+
return outputJsonFileList(files, options)
195+
}
196+
197+
return formatFilesAsString(files, options).map(file => console.log(file))
198+
}
199+
200+
function outputJsonFileList(files: WorkspaceSpec[], options: CliOptions) {
201+
if (typeof options.json === 'boolean') {
202+
return console.log(JSON.stringify(formatFilesAsJSON(files), null, 2))
203+
}
204+
if (typeof options.json === 'string') {
205+
const jsonPath = resolve(options.root || process.cwd(), options.json)
206+
mkdirSync(dirname(jsonPath), { recursive: true })
207+
writeFileSync(jsonPath, JSON.stringify(formatFilesAsJSON(files), null, 2))
208+
}
209+
}
210+
211+
function formatFilesAsJSON(files: WorkspaceSpec[]) {
212+
return files.map((file) => {
213+
const result: any = {
214+
file: file.moduleId,
215+
}
216+
217+
if (file.project.name) {
218+
result.projectName = file.project.name
219+
}
220+
return result
221+
})
222+
}
223+
224+
function formatFilesAsString(files: WorkspaceSpec[], options: CliOptions) {
225+
return files.map((file) => {
226+
let name = relative(options.root || process.cwd(), file.moduleId)
227+
if (file.project.name) {
228+
name = `[${file.project.name}] ${name}`
229+
}
230+
return name
231+
})
232+
}
233+
187234
function processJsonOutput(files: File[], options: CliOptions) {
188235
if (typeof options.json === 'boolean') {
189236
return console.log(JSON.stringify(formatCollectedAsJSON(files), null, 2))

packages/vitest/src/node/cli/cli-config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
795795
outputJson: null,
796796
json: null,
797797
provide: null,
798+
filesOnly: null,
798799
}
799800

800801
export const benchCliOptionsConfig: Pick<
@@ -813,10 +814,13 @@ export const benchCliOptionsConfig: Pick<
813814

814815
export const collectCliOptionsConfig: Pick<
815816
VitestCLIOptions,
816-
'json'
817+
'json' | 'filesOnly'
817818
> = {
818819
json: {
819820
description: 'Print collected tests as JSON or write to a file (Default: false)',
820821
argument: '[true/path]',
821822
},
823+
filesOnly: {
824+
description: 'Print only test files with out the test cases',
825+
},
822826
}

0 commit comments

Comments
 (0)