Skip to content

Commit

Permalink
feat: show more details when no test files found (#1033)
Browse files Browse the repository at this point in the history
* chore: resolve conflict

* feat: show more details when test files not found

* chore: fix unit test

* chore: remove some dead code

* doc: fix example

* refactor: cleanup

* feat: show filters, if no files found and has filters

Co-authored-by: Vladimir Sheremet <sheremet.va@icloud.com>
  • Loading branch information
togami2864 and sheremet-va committed Apr 2, 2022
1 parent 978d37c commit 190b1c1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
21 changes: 21 additions & 0 deletions docs/config/index.md
Expand Up @@ -318,6 +318,27 @@ Isolate environment for each test file

Coverage options

### testNamePattern

- **Type** `string | RegExp`

Run tests with full names matching the pattern.
If you add `OnlyRunThis` to this property, tests containing the word `OnlyRunThis` in the test name will be skipped.

```js
import { expect, test } from 'vitest'

// run
test('OnlyRunThis', () => {
expect(true).toBe(true)
})

// skipped
test('doNotRun', () => {
expect(true).toBe(true)
})
```

### open

- **Type:** `boolean`
Expand Down
17 changes: 12 additions & 5 deletions packages/vitest/src/node/core.ts
Expand Up @@ -114,12 +114,19 @@ export class Vitest {
)

if (!files.length) {
if (this.config.passWithNoTests)
this.log('No test files found\n')
const exitCode = this.config.passWithNoTests ? 0 : 1
if (this.config.passWithNoTests) {
this.log(`No test files found, exiting code with ${exitCode}\n`)
}
else {
this.error(c.red(`No test files found, exiting code with ${exitCode}\nRun with \`--passWithNoTests\`to exit with code 0\n`))
console.error(`In ${c.bold(this.config.root)}`)
if (filters?.length) this.console.error(` filter: ${c.yellow(filters.join(', '))}`)
if (this.config.include) this.console.error(` include: ${c.yellow(this.config.include.join(', '))}`)
if (this.config.watchIgnore) this.console.error(` watchIgnore: ${c.yellow(this.config.watchIgnore.join(', '))}`)
}

else
this.error(c.red('No test files found\n'))
process.exit(this.config.passWithNoTests ? 0 : 1)
process.exit(exitCode)
}

await this.runFiles(files)
Expand Down

0 comments on commit 190b1c1

Please sign in to comment.