Skip to content

Commit

Permalink
Merge branch 'main' into fix-async-assertion-auto-await-inside-timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Aug 30, 2024
2 parents 13ed041 + 12e702b commit ed3a95b
Show file tree
Hide file tree
Showing 13 changed files with 288 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/.vitepress/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {}
/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
AsideViteConf: typeof import('./components/AsideViteConf.vue')['default']
Contributors: typeof import('./components/Contributors.vue')['default']
CourseLink: typeof import('./components/CourseLink.vue')['default']
FeaturesList: typeof import('./components/FeaturesList.vue')['default']
Expand Down
73 changes: 73 additions & 0 deletions docs/.vitepress/components/AsideViteConf.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<template>
<a
class="viteconf"
href="https://viteconf.org/?utm=vitest-sidebar"
target="_blank"
>
<img width="22" height="22" src="/viteconf.svg">
<span>
<p class="extra-info">Building Together</p>
<p class="heading">ViteConf 24 - Oct 3</p>
<p class="extra-info">Get your free ticket!</p>
</span>
</a>
</template>

<style scoped>
.viteconf {
margin-top: 1rem;
margin-bottom: 1rem;
border-radius: 14px;
padding-top: 0.4rem;
padding-bottom: 0.4rem;
position: relative;
font-size: 0.9rem;
font-weight: 700;
line-height: 1.1rem;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
gap: 1rem;
background-color: var(--vp-c-bg-soft);
border: 2px solid var(--vp-c-bg-soft);
transition: border-color 0.5s;
filter: grayscale(1);
}
.viteconf:hover {
border: 2px solid #9499ff;
filter: none;
}
.viteconf img {
transition: transform 0.5s;
transform: scale(1.25);
}
.viteconf:hover img {
transform: scale(1.75);
}
.viteconf .heading {
color: var(--vt-c-text-1);
}
.viteconf:hover .heading {
background-image: linear-gradient(
120deg,
#b047ff 16%,
#9499ff,
#9499ff
);
background-clip: text;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
.viteconf .extra-info {
color: var(--vp-c-text-1);
opacity: 0;
font-size: 0.7rem;
padding-left: 0.1rem;
transition: opacity 0.5s;
}
.viteconf:hover .extra-info {
opacity: 0.9;
}
</style>
2 changes: 2 additions & 0 deletions docs/.vitepress/theme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
import HomePage from '../components/HomePage.vue'
import Version from '../components/Version.vue'
import AsideViteConf from '../components/AsideViteConf.vue'
import '@shikijs/vitepress-twoslash/style.css'

if (inBrowser) {
Expand All @@ -20,6 +21,7 @@ export default {
Layout() {
return h(DefaultTheme.Layout, null, {
'home-features-after': () => h(HomePage),
'aside-ads-before': () => h(AsideViteConf),
})
},
enhanceApp({ app }) {
Expand Down
11 changes: 11 additions & 0 deletions docs/guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ vitest list filename.spec.ts -t="some-test" --json=./file.json

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

You also can pass down `--filesOnly` flag to print the test files only:

```bash
vitest list --filesOnly
```

```txt
tests/test1.test.ts
tests/test2.test.ts
```

## Options

::: tip
Expand Down
24 changes: 24 additions & 0 deletions docs/public/viteconf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/vite-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@
"cac": "^6.7.14",
"debug": "^4.3.6",
"pathe": "^1.1.2",
"tinyrainbow": "^1.2.0",
"vite": "^5.0.0"
},
"devDependencies": {
"@jridgewell/trace-mapping": "^0.3.25",
"@types/debug": "^4.1.12"
"@types/debug": "^4.1.12",
"tinyrainbow": "^1.2.0"
}
}
29 changes: 29 additions & 0 deletions packages/vitest/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,35 @@ Repository: sindresorhus/p-locate
---------------------------------------

## package-manager-detector
License: MIT
By: Anthony Fu
Repository: git+https://github.com/antfu-collective/package-manager-detector.git

> MIT License
>
> Copyright (c) 2020-PRESENT Anthony Fu <https://github.com/antfu>
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
---------------------------------------

## picomatch
License: MIT
By: Jon Schlinkert
Expand Down
26 changes: 16 additions & 10 deletions packages/vitest/src/node/cli/cac.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,30 @@ async function collect(mode: VitestRunMode, cliFilters: string[], options: CliOp
catch {}

try {
const { prepareVitest, processCollected } = await import('./cli-api')
const { prepareVitest, processCollected, outputFileList } = await import('./cli-api')
const ctx = await prepareVitest(mode, {
...normalizeCliOptions(options),
watch: false,
run: true,
})
if (!options.filesOnly) {
const { tests, errors } = await ctx.collect(cliFilters.map(normalize))

if (errors.length) {
console.error('\nThere were unhandled errors during test collection')
errors.forEach(e => console.error(e))
console.error('\n\n')
await ctx.close()
return
}

const { tests, errors } = await ctx.collect(cliFilters.map(normalize))

if (errors.length) {
console.error('\nThere were unhandled errors during test collection')
errors.forEach(e => console.error(e))
console.error('\n\n')
await ctx.close()
return
processCollected(ctx, tests, options)
}
else {
const files = await ctx.listFiles(cliFilters.map(normalize))
outputFileList(files, options)
}

processCollected(ctx, tests, options)
await ctx.close()
}
catch (e) {
Expand Down
49 changes: 48 additions & 1 deletion packages/vitest/src/node/cli/cli-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-console */

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

export interface CliOptions extends UserConfig {
/**
Expand All @@ -26,6 +27,10 @@ export interface CliOptions extends UserConfig {
* Output collected tests as JSON or to a file
*/
json?: string | boolean
/**
* Output collected test files only
*/
filesOnly?: boolean
}

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

export function outputFileList(files: WorkspaceSpec[], options: CliOptions) {
if (typeof options.json !== 'undefined') {
return outputJsonFileList(files, options)
}

return formatFilesAsString(files, options).map(file => console.log(file))
}

function outputJsonFileList(files: WorkspaceSpec[], options: CliOptions) {
if (typeof options.json === 'boolean') {
return console.log(JSON.stringify(formatFilesAsJSON(files), null, 2))
}
if (typeof options.json === 'string') {
const jsonPath = resolve(options.root || process.cwd(), options.json)
mkdirSync(dirname(jsonPath), { recursive: true })
writeFileSync(jsonPath, JSON.stringify(formatFilesAsJSON(files), null, 2))
}
}

function formatFilesAsJSON(files: WorkspaceSpec[]) {
return files.map((file) => {
const result: any = {
file: file.moduleId,
}

if (file.project.name) {
result.projectName = file.project.name
}
return result
})
}

function formatFilesAsString(files: WorkspaceSpec[], options: CliOptions) {
return files.map((file) => {
let name = relative(options.root || process.cwd(), file.moduleId)
if (file.project.name) {
name = `[${file.project.name}] ${name}`
}
return name
})
}

function processJsonOutput(files: File[], options: CliOptions) {
if (typeof options.json === 'boolean') {
return console.log(JSON.stringify(formatCollectedAsJSON(files), null, 2))
Expand Down
6 changes: 5 additions & 1 deletion packages/vitest/src/node/cli/cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ export const cliOptionsConfig: VitestCLIOptions = {
outputJson: null,
json: null,
provide: null,
filesOnly: null,
}

export const benchCliOptionsConfig: Pick<
Expand All @@ -813,10 +814,13 @@ export const benchCliOptionsConfig: Pick<

export const collectCliOptionsConfig: Pick<
VitestCLIOptions,
'json'
'json' | 'filesOnly'
> = {
json: {
description: 'Print collected tests as JSON or write to a file (Default: false)',
argument: '[true/path]',
},
filesOnly: {
description: 'Print only test files with out the test cases',
},
}
8 changes: 8 additions & 0 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,14 @@ export class Vitest {
}
}

async listFiles(filters?: string[]) {
const files = await this.filterTestsBySource(
await this.globTestFiles(filters),
)

return files
}

async start(filters?: string[]) {
this._onClose = []

Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ed3a95b

Please sign in to comment.