Skip to content

Commit

Permalink
fix: testNamePattern matches against full name (fix #838) (#839)
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Feb 23, 2022
1 parent 4c9dbd0 commit e753493
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ You can specify additional CLI options like `--port` or `--https`. For a full li
| `-c, --config <path>` | Path to config file |
| `-u, --update` | Update snapshots |
| `-w, --watch` | Smart & instant watch mode |
| `-t, --testNamePattern <pattern>` | Run tests with names matching the pattern |
| `-t, --testNamePattern <pattern>` | Run tests with full names matching the pattern |
| `--ui` | Enable UI |
| `--open` | Open the UI automatically if enabled (default: `true`) |
| `--api [api]` | Serve API, available options: `--api.port <port>`, `--api.host [host]` and `--api.strictPort` |
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cli
.option('-c, --config <path>', 'path to config file')
.option('-u, --update', 'update snapshot')
.option('-w, --watch', 'watch mode')
.option('-t, --testNamePattern <pattern>', 'run test names with the specified pattern')
.option('-t, --testNamePattern <pattern>', 'run tests with full names matching the specified pattern')
.option('--ui', 'enable UI')
.option('--open', 'open UI automatically (default: !process.env.CI))')
.option('--api [api]', 'serve API, available options: --api.port <port>, --api.host [host] and --api.strictPort')
Expand Down
6 changes: 5 additions & 1 deletion packages/vitest/src/runtime/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function interpretTaskModes(suite: Suite, namePattern?: string | RegExp, onlyMod
}
}
if (t.type === 'test') {
if (namePattern && !t.name.match(namePattern))
if (namePattern && !getTaskFullName(t).match(namePattern))
t.mode = 'skip'
}
else if (t.type === 'suite') {
Expand All @@ -115,6 +115,10 @@ function interpretTaskModes(suite: Suite, namePattern?: string | RegExp, onlyMod
}
}

function getTaskFullName(task: TaskBase): string {
return `${task.suite ? `${getTaskFullName(task.suite)} ` : ''}${task.name}`
}

function someTasksAreOnly(suite: Suite): boolean {
return suite.tasks.some(t => t.mode === 'only' || (t.type === 'suite' && someTasksAreOnly(t)))
}
Expand Down

0 comments on commit e753493

Please sign in to comment.