Skip to content

Commit 40f27ca

Browse files
committed
fix(lib): [matchesGlob] remove options?.basename default
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent b2832ca commit 40f27ca

File tree

4 files changed

+51
-43
lines changed

4 files changed

+51
-43
lines changed

__tests__/reporters/verbose.mts

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,9 @@
77
import type { Task, TaskResultPack } from '@vitest/runner'
88
import { getNames, getTests } from '@vitest/runner/utils'
99
import colors, { type Colors } from 'tinyrainbow'
10-
import type { RunnerTask } from 'vitest'
10+
import type { RunnerTask, RunnerTestFile } from 'vitest'
1111
import { DefaultReporter, type Reporter } from 'vitest/reporters'
1212

13-
/**
14-
* Verbose reporter options.
15-
*/
16-
interface Options {
17-
/**
18-
* Enable summary reporter?
19-
*
20-
* @default true
21-
*/
22-
summary?: boolean | null | undefined
23-
}
24-
2513
/**
2614
* Verbose reporter.
2715
*
@@ -43,13 +31,12 @@ class VerboseReporter extends DefaultReporter implements Reporter {
4331

4432
/**
4533
* Create a new verbose reporter.
46-
*
47-
* @param {Options | null | undefined} [options]
48-
* Reporter options
4934
*/
50-
constructor(options?: Options | null | undefined) {
51-
super({ summary: options?.summary ?? true })
35+
constructor() {
36+
super({ summary: true })
37+
5238
this.colors = colors
39+
this.renderSucceed = true
5340
this.verbose = true
5441
}
5542

@@ -113,6 +100,29 @@ class VerboseReporter extends DefaultReporter implements Reporter {
113100
/**
114101
* Print tasks.
115102
*
103+
* @see {@linkcode RunnerTestFile}
104+
*
105+
* @public
106+
* @override
107+
* @instance
108+
*
109+
* @param {RunnerTestFile[] | undefined} [files]
110+
* List of test files
111+
* @param {unknown[] | undefined} [errors]
112+
* List of unhandled errors
113+
* @return {undefined}
114+
*/
115+
public override onFinished(
116+
files?: RunnerTestFile[] | undefined,
117+
errors?: unknown[] | undefined
118+
): undefined {
119+
if (files) { for (const task of files) this.printTask(task, true) }
120+
return void super.onFinished(files, errors)
121+
}
122+
123+
/**
124+
* Handle task updates.
125+
*
116126
* @see {@linkcode TaskResultPack}
117127
*
118128
* @public
@@ -124,20 +134,7 @@ class VerboseReporter extends DefaultReporter implements Reporter {
124134
* @return {undefined}
125135
*/
126136
public override onTaskUpdate(packs: TaskResultPack[]): undefined {
127-
for (const pack of packs) {
128-
/**
129-
* Current task.
130-
*
131-
* @const {Task | undefined} task
132-
*/
133-
const task: Task | undefined = this.ctx.state.idMap.get(pack[0])
134-
135-
// print top-level suite task and recursively print tests
136-
if (task && task.type === 'suite' && 'filepath' in task) {
137-
void this.printTask(task)
138-
}
139-
}
140-
137+
this.isTTY && void super.onTaskUpdate(packs)
141138
return void packs
142139
}
143140

@@ -152,10 +149,20 @@ class VerboseReporter extends DefaultReporter implements Reporter {
152149
*
153150
* @param {Task | null | undefined} task
154151
* The task to handle
152+
* @param {boolean | null | undefined} [force]
153+
* Print `task` even when {@linkcode isTTY} is `false`?
155154
* @return {undefined}
156155
*/
157-
protected override printTask(task: Task | null | undefined): undefined {
158-
if (task && task.result?.state !== 'run') {
156+
protected override printTask(
157+
task: Task | null | undefined,
158+
force?: boolean | null | undefined
159+
): undefined {
160+
if (
161+
(!this.isTTY || force) &&
162+
task?.result?.state &&
163+
task.result.state !== 'queued' &&
164+
task.result.state !== 'run'
165+
) {
159166
/**
160167
* Task skipped?
161168
*
@@ -197,7 +204,10 @@ class VerboseReporter extends DefaultReporter implements Reporter {
197204
state += skip ? this.colors.blackBright(suite) : suite
198205

199206
this.log(state)
200-
if (!skip) { for (const tsk of task.tasks) void this.printTask(tsk) }
207+
208+
if (!skip) {
209+
for (const subtask of task.tasks) void this.printTask(subtask, force)
210+
}
201211
}
202212
}
203213

src/lib/__tests__/matches-glob.functional.spec.mts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @see https://github.com/nodejs/node/blob/v23.4.0/test/parallel/test-path-glob.js
55
*/
66

7-
import process from '#internal/process'
7+
import cwd from '#lib/cwd'
88
import testSubject from '#lib/matches-glob'
99
import toPosix from '#lib/to-posix'
1010
import micromatch from 'micromatch'
@@ -55,8 +55,7 @@ describe('functional:lib/matchesGlob', () => {
5555
expect(spy.mock.lastCall?.[1]).to.eq(toPosix(pattern))
5656
expect(spy.mock.lastCall?.[2]).to.eql({
5757
...options,
58-
basename: options?.basename ?? true,
59-
cwd: process.cwd(),
58+
cwd: cwd(),
6059
windows: false
6160
})
6261
})

src/lib/matches-glob.mts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* @module pathe/lib/matchesGlob
44
*/
55

6-
import process from '#internal/process'
76
import validateString from '#internal/validate-string'
87
import validateURLString from '#internal/validate-url-string'
8+
import cwd from '#lib/cwd'
99
import toPosix from '#lib/to-posix'
1010
import micromatch from 'micromatch'
1111

@@ -54,8 +54,7 @@ function matchesGlob(
5454

5555
return micromatch.isMatch(toPosix(String(input)), pattern, {
5656
...options,
57-
basename: options?.basename ?? true,
58-
cwd: options?.cwd ?? process.cwd(),
57+
cwd: options?.cwd ?? cwd(),
5958
windows: false
6059
})
6160
}

vitest.config.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ function config(env: ConfigEnv): ViteUserConfig {
119119
* @async
120120
*
121121
* @param {TestSpecification[]} specs
122-
* Workspace spec objects
122+
* List of test file specifications
123123
* @return {Promise<TestSpecification[]>}
124-
* Sorted `specs`
124+
* Sorted test files
125125
*/
126126
public override async sort(
127127
specs: TestSpecification[]

0 commit comments

Comments
 (0)