できない.dev

Vitest で「No test files found, exiting with code 1」が出てテストを実行できない

No test files found, exiting with code 1 は、テストファイルが 0 件だと出る。
ファイル名に .test か .spec を付けるか、include や絞り込みの文字列を直せば直る。

公開: 更新:

症状できない · exit 1
npx vitest run
 RUN  v5.0.5 /tmp/tmp.NsxdnrYI1e

No test files found, exiting with code 1

include: **/*.{test,spec}.?(c|m)[jt]s?(x)
exclude:  **/node_modules/**, **/.git/**
解決後できた · exit 0
npx vitest run
…
 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  01:11:09
   Duration  85ms (transform 57%, import 27%, worker 10%, tests 6%)

2026-10-30 に node:22(Vitest 5.0.5 / Node.js 22.23.4) で実際に打って取った出力。検証環境の詳細

要約

vitest run を実行すると、テストが 1 本も動かずに終わる(終了コード 1)。

No test files found, exiting with code 1
 
include: **/*.{test,spec}.?(c|m)[jt]s?(x)
exclude:  **/node_modules/**, **/.git/**

Vitest は include のパターンに合い、exclude に合わないファイルだけをテストとして集める。
表示の下 2 行がそのとき使ったパターンなので、まずここを読む。
既定の include は名前に .test か .spec を含む JavaScript / TypeScript のファイルで、sum.check.js や sumspec.js のような名前は拾われない。
上の表示は Vitest 5.0.3・Node.js 22 で、テストを tests/sum.check.js と tests/sumspec.js という名前で置いて実行したものだ。

実行例

node:22 のコンテナで Vitest 5.0.5 を使うと、sum.check.js だけがあるディレクトリでは npx vitest run が No test files found で終了コード 1 になった。
ファイル名を sum.test.js に変えると、同じコマンドは終了コード 0 で通った。

$ npx vitest run
 RUN  v5.0.5 /tmp/tmp.NsxdnrYI1e
 
No test files found, exiting with code 1
 
include: **/*.{test,spec}.?(c|m)[jt]s?(x)
exclude:  **/node_modules/**, **/.git/**
$ echo $?
1
$ mv tests/sum.check.js tests/sum.test.js
$ npx vitest run
 RUN  v5.0.5 /tmp/tmp.NsxdnrYI1e
 
 ✓ tests/sum.test.js (1 test) 1ms
 
 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  01:11:09
   Duration  85ms (transform 57%, import 27%, worker 10%, tests 6%)
$ echo $?
0
$ cat vitest.config.js
import { defineConfig } from "vitest/config";
 
export default defineConfig({
  test: {
    include: ["src/**/*.test.js"],
  },
});
$ npx vitest run
 RUN  v5.0.5 /tmp/tmp.NsxdnrYI1e
 
No test files found, exiting with code 1
 
include: src/**/*.test.js
exclude:  **/node_modules/**, **/.git/**
$ echo $?
1
$ cat vitest.config.js
import { defineConfig, configDefaults } from "vitest/config";
 
export default defineConfig({
  test: {
    include: [...configDefaults.include, "tests/**/*.check.js"],
  },
});
$ npx vitest run
 RUN  v5.0.5 /tmp/tmp.NsxdnrYI1e
 
 ✓ tests/sum.check.js (1 test) 2ms
 ✓ tests/sum.spec.js (1 test) 2ms
 
 Test Files  2 passed (2)
      Tests  2 passed (2)
   Start at  01:11:09
   Duration  89ms (transform 58%, import 26%, worker 9%, tests 7%)
$ echo $?
0
$ npx vitest run foo
 RUN  v5.0.5 /tmp/tmp.NsxdnrYI1e
 
No test files found, exiting with code 1
 
filter: foo
include: **/*.{test,spec}.?(c|m)[jt]s?(x), tests/**/*.check.js
exclude:  **/node_modules/**, **/.git/**
$ echo $?
1
$ npx vitest run sum.spec
 RUN  v5.0.5 /tmp/tmp.NsxdnrYI1e
 
 ✓ tests/sum.spec.js (1 test) 1ms
 
 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  01:11:10
   Duration  70ms (import 41%, transform 31%, worker 16%, tests 11%, environment 1%)
$ echo $?
0
$ npx vitest run
 RUN  v5.0.5 /tmp/tmp.NsxdnrYI1e
 
No test files found, exiting with code 1
 
include: **/*.{test,spec}.?(c|m)[jt]s?(x)
exclude:  **/node_modules/**, **/.git/**
$ echo $?
1
$ npx vitest run --passWithNoTests
 RUN  v5.0.5 /tmp/tmp.NsxdnrYI1e
 
No test files found, exiting with code 0
 
include: **/*.{test,spec}.?(c|m)[jt]s?(x)
exclude:  **/node_modules/**, **/.git/**
$ echo $?
0

— 2026-10-30 時点の出力

検証環境Node.js 22.23.4 / npm 10.9.9 / Python 3.11.2 / 2026-10-30 検証(ほか 2 件)
検証日
実行環境
node:22 Debian GNU/Linux 12 (bookworm)
バージョン
  • Node.js 22.23.4
  • npm 10.9.9
  • Python 3.11.2
  • Git 2.39.5
  • Vitest 5.0.5

この記事の「実行例」は、上記の環境で実際にコマンドを実行して得られた出力をそのまま掲載しています。 再現手順はリポジトリの検証スクリプトとして管理し、定期的に再実行して出力を更新しています。

解決策

1. ファイル名をそろえる

mv tests/sum.check.js tests/sum.test.js

2. 既定のパターンに足す

独自の名前も拾いたいときは、configDefaults.include を展開して既定を残したまま追加する。

// vitest.config.ts
import { defineConfig, configDefaults } from "vitest/config";
 
export default defineConfig({
  test: {
    include: [...configDefaults.include, "tests/**/*.check.js"],
  },
});

この設定で sum.spec.js と sum.check.js の 2 ファイルがどちらも実行された。

3. 絞り込みはパスの一部を渡す

CLI のドキュメント(新しいタブで開く)によると、この絞り込みは部分一致だけで、glob や正規表現は使えない。
sum.spec.js なら vitest run sum で 1 ファイルだけ実行できた。

4. テストが無いことを許すなら --passWithNoTests

vitest run --passWithNoTests

表示は No test files found, exiting with code 0 に変わり、終了コード 0 で終わる。
ただしテストの置き場所の誤りまで隠れるので、テストが揃ったら外す。

よくある原因

  1. ファイル名が既定のパターンに合わない。
    .test / .spec の前のドットが抜けていたり、別の語を使っていたりすると 0 件になる。
  2. include を上書きした。
    公式ドキュメント(新しいタブで開く)のとおり、include を書くと既定値は置き換わる。
    include: ['src/**/*.test.js'] と書いた状態では、tests/ にある sum.spec.js は拾われなくなった。
    パターンは root(既定はカレントディレクトリ)からの相対で解釈される。
  3. 絞り込みの文字列が合わない。
    vitest run foo の foo は、テストファイルのパスに含まれるかどうかで判定される(Test Filtering(新しいタブで開く))。
    合うものが無いと、表示に filter: foo の行が加わって同じく終了コード 1 になる。
  4. テストがまだ無い。
    プロジェクトを作った直後に CI へ vitest run を入れると、最初の実行で落ちる。