Skip to content

Commit

Permalink
fix(lib): [matchesGlob] remove options?.basename default
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Dec 24, 2024
1 parent b2832ca commit 40f27ca
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 43 deletions.
80 changes: 45 additions & 35 deletions __tests__/reporters/verbose.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@
import type { Task, TaskResultPack } from '@vitest/runner'
import { getNames, getTests } from '@vitest/runner/utils'
import colors, { type Colors } from 'tinyrainbow'
import type { RunnerTask } from 'vitest'
import type { RunnerTask, RunnerTestFile } from 'vitest'
import { DefaultReporter, type Reporter } from 'vitest/reporters'

/**
* Verbose reporter options.
*/
interface Options {
/**
* Enable summary reporter?
*
* @default true
*/
summary?: boolean | null | undefined
}

/**
* Verbose reporter.
*
Expand All @@ -43,13 +31,12 @@ class VerboseReporter extends DefaultReporter implements Reporter {

/**
* Create a new verbose reporter.
*
* @param {Options | null | undefined} [options]
* Reporter options
*/
constructor(options?: Options | null | undefined) {
super({ summary: options?.summary ?? true })
constructor() {
super({ summary: true })

this.colors = colors
this.renderSucceed = true
this.verbose = true
}

Expand Down Expand Up @@ -113,6 +100,29 @@ class VerboseReporter extends DefaultReporter implements Reporter {
/**
* Print tasks.
*
* @see {@linkcode RunnerTestFile}
*
* @public
* @override
* @instance
*
* @param {RunnerTestFile[] | undefined} [files]
* List of test files
* @param {unknown[] | undefined} [errors]
* List of unhandled errors
* @return {undefined}
*/
public override onFinished(
files?: RunnerTestFile[] | undefined,
errors?: unknown[] | undefined
): undefined {
if (files) { for (const task of files) this.printTask(task, true) }
return void super.onFinished(files, errors)
}

/**
* Handle task updates.
*
* @see {@linkcode TaskResultPack}
*
* @public
Expand All @@ -124,20 +134,7 @@ class VerboseReporter extends DefaultReporter implements Reporter {
* @return {undefined}
*/
public override onTaskUpdate(packs: TaskResultPack[]): undefined {
for (const pack of packs) {
/**
* Current task.
*
* @const {Task | undefined} task
*/
const task: Task | undefined = this.ctx.state.idMap.get(pack[0])

// print top-level suite task and recursively print tests
if (task && task.type === 'suite' && 'filepath' in task) {
void this.printTask(task)
}
}

this.isTTY && void super.onTaskUpdate(packs)
return void packs
}

Expand All @@ -152,10 +149,20 @@ class VerboseReporter extends DefaultReporter implements Reporter {
*
* @param {Task | null | undefined} task
* The task to handle
* @param {boolean | null | undefined} [force]
* Print `task` even when {@linkcode isTTY} is `false`?
* @return {undefined}
*/
protected override printTask(task: Task | null | undefined): undefined {
if (task && task.result?.state !== 'run') {
protected override printTask(
task: Task | null | undefined,
force?: boolean | null | undefined
): undefined {
if (
(!this.isTTY || force) &&
task?.result?.state &&
task.result.state !== 'queued' &&
task.result.state !== 'run'
) {
/**
* Task skipped?
*
Expand Down Expand Up @@ -197,7 +204,10 @@ class VerboseReporter extends DefaultReporter implements Reporter {
state += skip ? this.colors.blackBright(suite) : suite

this.log(state)
if (!skip) { for (const tsk of task.tasks) void this.printTask(tsk) }

if (!skip) {
for (const subtask of task.tasks) void this.printTask(subtask, force)
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/lib/__tests__/matches-glob.functional.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @see https://github.com/nodejs/node/blob/v23.4.0/test/parallel/test-path-glob.js
*/

import process from '#internal/process'
import cwd from '#lib/cwd'
import testSubject from '#lib/matches-glob'
import toPosix from '#lib/to-posix'
import micromatch from 'micromatch'
Expand Down Expand Up @@ -55,8 +55,7 @@ describe('functional:lib/matchesGlob', () => {
expect(spy.mock.lastCall?.[1]).to.eq(toPosix(pattern))
expect(spy.mock.lastCall?.[2]).to.eql({
...options,
basename: options?.basename ?? true,
cwd: process.cwd(),
cwd: cwd(),
windows: false
})
})
Expand Down
5 changes: 2 additions & 3 deletions src/lib/matches-glob.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
* @module pathe/lib/matchesGlob
*/

import process from '#internal/process'
import validateString from '#internal/validate-string'
import validateURLString from '#internal/validate-url-string'
import cwd from '#lib/cwd'
import toPosix from '#lib/to-posix'
import micromatch from 'micromatch'

Expand Down Expand Up @@ -54,8 +54,7 @@ function matchesGlob(

return micromatch.isMatch(toPosix(String(input)), pattern, {
...options,
basename: options?.basename ?? true,
cwd: options?.cwd ?? process.cwd(),
cwd: options?.cwd ?? cwd(),
windows: false
})
}
Expand Down
4 changes: 2 additions & 2 deletions vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ function config(env: ConfigEnv): ViteUserConfig {
* @async
*
* @param {TestSpecification[]} specs
* Workspace spec objects
* List of test file specifications
* @return {Promise<TestSpecification[]>}
* Sorted `specs`
* Sorted test files
*/
public override async sort(
specs: TestSpecification[]
Expand Down

0 comments on commit 40f27ca

Please sign in to comment.