Skip to content

Commit 585921b

Browse files
committed
feat(interfaces): ParseConfigHost
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent ec04171 commit 585921b

File tree

6 files changed

+157
-38
lines changed

6 files changed

+157
-38
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ This package is fully typed with [TypeScript][].
100100
- [`FileSystem`](./src/interfaces/file-system.mts)
101101
- [`LoadTsconfigOptions`](./src/interfaces/options-load-tsconfig.mts)
102102
- [`ModuleResolutionHost`](./src/interfaces/host-module-resolution.mts)
103+
- [`ParseConfigHost`](./src/interfaces/host-parse-config.mts)
103104
- [`ReadTsconfigOptions`](./src/interfaces/options-read-tsconfig.mts)
104105
- [`ResolvePathOptions`](./src/interfaces/options-resolve-path.mts)
105106
- [`ResolvedTsconfig`](./src/interfaces/options-resolve-path.mts)

__tests__/reporters/verbose.mts

Lines changed: 45 additions & 36 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,21 +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-
141-
return void packs
137+
return void (this.isTTY && void super.onTaskUpdate(packs))
142138
}
143139

144140
/**
@@ -152,10 +148,20 @@ class VerboseReporter extends DefaultReporter implements Reporter {
152148
*
153149
* @param {Task | null | undefined} task
154150
* The task to handle
151+
* @param {boolean | null | undefined} [force]
152+
* Print `task` even when {@linkcode isTTY} is `false`?
155153
* @return {undefined}
156154
*/
157-
protected override printTask(task: Task | null | undefined): undefined {
158-
if (task && task.result?.state !== 'run') {
155+
protected override printTask(
156+
task: Task | null | undefined,
157+
force?: boolean | null | undefined
158+
): undefined {
159+
if (
160+
(!this.isTTY || force) &&
161+
task?.result?.state &&
162+
task.result.state !== 'queued' &&
163+
task.result.state !== 'run'
164+
) {
159165
/**
160166
* Task skipped?
161167
*
@@ -197,7 +203,10 @@ class VerboseReporter extends DefaultReporter implements Reporter {
197203
state += skip ? this.colors.blackBright(suite) : suite
198204

199205
this.log(state)
200-
if (!skip) { for (const tsk of task.tasks) void this.printTask(tsk) }
206+
207+
if (!skip) {
208+
for (const subtask of task.tasks) void this.printTask(subtask, force)
209+
}
201210
}
202211
}
203212

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @file Type Tests - ParseConfigHost
3+
* @module tsconfig-utils/interfaces/tests/unit-d/ParseConfigHost
4+
*/
5+
6+
import type TestSubject from '#interfaces/host-parse-config'
7+
import type { ModuleId } from '@flex-development/mlly'
8+
import type { ModuleResolutionHost } from '@flex-development/tsconfig-utils'
9+
import type ts from 'typescript'
10+
11+
describe('unit-d:interfaces/ParseConfigHost', () => {
12+
it('should extend ModuleResolutionHost', () => {
13+
expectTypeOf<TestSubject>().toMatchTypeOf<ModuleResolutionHost>()
14+
})
15+
16+
it('should match [useCaseSensitiveFileNames: boolean]', () => {
17+
expectTypeOf<TestSubject>()
18+
.toHaveProperty('useCaseSensitiveFileNames')
19+
.toEqualTypeOf<boolean>
20+
})
21+
22+
it('should match Required<Omit<ts.ParseConfigHost, "trace">>', () => {
23+
expectTypeOf<TestSubject>()
24+
.toMatchTypeOf<Required<Omit<ts.ParseConfigHost, 'trace'>>>()
25+
})
26+
27+
describe('readDirectory', () => {
28+
type Subject = TestSubject['readDirectory']
29+
30+
it('should match [this: void]', () => {
31+
expectTypeOf<Subject>().thisParameter.toEqualTypeOf<void>()
32+
})
33+
34+
describe('parameters', () => {
35+
it('should be callable with [ModuleId, Set<string> | readonly string[] | undefined, Set<string> | readonly string[] | undefined, Set<string> | readonly string[] | undefined, number | null | undefined]', () => {
36+
expectTypeOf<Subject>().parameters.toEqualTypeOf<[
37+
ModuleId,
38+
(Set<string> | readonly string[] | undefined)?,
39+
(Set<string> | readonly string[] | undefined)?,
40+
(Set<string> | readonly string[] | undefined)?,
41+
(number | null | undefined)?
42+
]>()
43+
})
44+
})
45+
46+
describe('returns', () => {
47+
it('should return readonly string[]', () => {
48+
expectTypeOf<Subject>().returns.toEqualTypeOf<readonly string[]>()
49+
})
50+
})
51+
})
52+
})
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @file Interfaces - ModuleResolutionHost
3+
* @module tsconfig-utils/interfaces/ModuleResolutionHost
4+
*/
5+
6+
import type { ModuleId } from '@flex-development/mlly'
7+
import type { ModuleResolutionHost } from '@flex-development/tsconfig-utils'
8+
9+
/**
10+
* Configuration parser host API.
11+
*
12+
* Provides methods for accessing the file system and resolving module paths.
13+
*
14+
* @see {@linkcode ModuleResolutionHost}
15+
*
16+
* @extends {ModuleResolutionHost}
17+
*/
18+
interface ParseConfigHost extends ModuleResolutionHost {
19+
/**
20+
* Get a list of files in a directory.
21+
*
22+
* @see {@linkcode ModuleId}
23+
*
24+
* @this {void}
25+
*
26+
* @param {ModuleId} id
27+
* The directory path or URL to read
28+
* @param {Set<string> | ReadonlyArray<string> | undefined} [extensions]
29+
* List of file extensions to filter for
30+
* @param {Set<string> | ReadonlyArray<string> | undefined} [exclude]
31+
* List of of glob patterns matching files to exclude
32+
* @param {Set<string> | ReadonlyArray<string> | undefined} [include]
33+
* List of of glob patterns matching files to include
34+
* @param {number | null | undefined} [depth]
35+
* Maximum search depth (inclusive)
36+
* @return {ReadonlyArray<string>}
37+
* List of files under directory at `id`
38+
*/
39+
readDirectory(
40+
this: void,
41+
id: ModuleId,
42+
extensions?: Set<string> | readonly string[] | undefined,
43+
exclude?: Set<string> | readonly string[] | undefined,
44+
include?: Set<string> | readonly string[] | undefined,
45+
depth?: number | null | undefined
46+
): readonly string[]
47+
48+
/**
49+
* Treat filenames as case-sensitive?
50+
*
51+
* @override
52+
*/
53+
useCaseSensitiveFileNames: boolean
54+
}
55+
56+
export type { ParseConfigHost as default }

src/interfaces/index.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type { default as FileSystem } from '#interfaces/file-system'
77
export type {
88
default as ModuleResolutionHost
99
} from '#interfaces/host-module-resolution'
10+
export type { default as ParseConfigHost } from '#interfaces/host-parse-config'
1011
export type {
1112
default as LoadTsconfigOptions
1213
} from '#interfaces/options-load-tsconfig'

vitest.config.mts

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

0 commit comments

Comments
 (0)