Skip to content

Commit

Permalink
feat(reporters): BaseReporter, FancyReporter
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Feb 7, 2025
1 parent b477834 commit 194e988
Show file tree
Hide file tree
Showing 46 changed files with 2,005 additions and 201 deletions.
9 changes: 7 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@
"patches/",
"yarn.lock"
],
"ignoreRegExpList": [],
"ignoreRegExpList": ["ansi"],
"ignoreWords": [],
"language": "en-US",
"patterns": [],
"patterns": [
{
"name": "ansi",
"pattern": "/(\\\\u001b)(8|7|H|>|\\[(\\?\\d+(h|l)|[0-2]?(K|J)|\\d*(A|B|C|D\\D|E|F|G|g|i|m|n|S|s|T|u)|1000D\\d+|\\d*;\\d*(f|H|r|m)|\\d+;\\d+;\\d+m))/gi"
}
],
"readonly": true,
"useGitignore": true,
"usePnP": false,
Expand Down
13 changes: 13 additions & 0 deletions __fixtures__/date.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* @file Fixtures - date
* @module fixtures/date
*/

/**
* Fixture date.
*
* @const {Date} date
*/
const date: Date = new Date(2025, 1, 2)

export default date
37 changes: 37 additions & 0 deletions __fixtures__/error.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file Fixtures - error
* @module fixtures/error
*/

import pathe from '@flex-development/pathe'
import { dedent } from 'ts-dedent'

/**
* URL of current working directory.
*
* @const {URL} cwd
*/
const cwd: URL = pathe.pathToFileURL(pathe.cwd())

/**
* Fixture error.
*
* @const {Error} error
*/
const error: Error = new Error('This is an example error. Everything is fine!')

error.stack = dedent`
${error.name}: ${error.message}
at ${cwd.pathname}/__fixtures__/error.mts:21:22
at VitestExecutor.runModule (${cwd.href}/node_modules/vite-node/dist/client.mjs:399:5)
at VitestExecutor.directRequest (${cwd.href}/node_modules/vite-node/dist/client.mjs:381:5)
at VitestExecutor.cachedRequest (${cwd.href}/node_modules/vite-node/dist/client.mjs:206:14)
at VitestExecutor.dependencyRequest (${cwd.href}/node_modules/vite-node/dist/client.mjs:259:12)
at ${cwd.pathname}/src/reporters/__tests__/fancy.reporter.functional.spec.mts:9:1
at VitestExecutor.runModule (${cwd.href}/node_modules/vite-node/dist/client.mjs:399:5)
at VitestExecutor.directRequest (${cwd.href}/node_modules/vite-node/dist/client.mjs:381:5)
at VitestExecutor.cachedRequest (${cwd.href}/node_modules/vite-node/dist/client.mjs:206:14)
at VitestExecutor.executeId (${cwd.href}/node_modules/vite-node/dist/client.mjs:173:12)
`

export default error
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@
"./reporters": {
"log": "./src/reporters/index.mts",
"default": "./dist/reporters/index.mjs"
},
"./utils": {
"log": "./src/utils/index.mts",
"default": "./dist/utils/index.mjs"
}
},
"imports": {
"#enums/*": {
"log": "./src/enums/*.mts",
"default": "./dist/enums/*.mjs"
},
"#fixtures/*": "./__fixtures__/*.mts",
"#interfaces/*": {
"log": "./src/interfaces/*.mts",
"default": "./dist/interfaces/*.d.mts"
Expand Down Expand Up @@ -133,10 +130,12 @@
},
"dependencies": {
"@flex-development/colors": "1.0.1",
"@flex-development/pathe": "4.0.1",
"@flex-development/tutils": "6.0.0-alpha.25",
"devlop": "1.1.0",
"is-unicode-supported": "2.1.0",
"node-inspect-extracted": "3.0.2"
"node-inspect-extracted": "3.0.2",
"string-width": "7.2.0"
},
"devDependencies": {
"@arethetypeswrong/cli": "0.17.3",
Expand All @@ -145,20 +144,20 @@
"@eslint/js": "9.19.0",
"@flex-development/commitlint-config": "1.0.1",
"@flex-development/grease": "3.0.0-alpha.9",
"@flex-development/pathe": "4.0.1",
"@stylistic/eslint-plugin": "3.0.1",
"@tsconfig/strictest": "2.0.5",
"@types/eslint": "9.6.1",
"@types/eslint__js": "8.42.3",
"@types/is-ci": "3.0.4",
"@types/node": "22.10.10",
"@types/node": "22.13.1",
"@types/node-notifier": "8.0.5",
"@types/unist": "3.0.3",
"@typescript-eslint/eslint-plugin": "8.23.0",
"@typescript-eslint/parser": "8.23.0",
"@vates/toggle-scripts": "1.0.0",
"@vitest/coverage-v8": "3.0.5",
"@vitest/ui": "3.0.5",
"consola": "3.4.0",
"cross-env": "7.0.3",
"cspell": "8.17.3",
"dprint": "0.49.0",
Expand Down Expand Up @@ -258,7 +257,6 @@
"typescript": "5.7.3",
"typescript-eslint": "8.23.0",
"unified": "11.0.5",
"unist-util-size": "4.0.0",
"vfile": "6.0.3",
"vitest": "3.0.5",
"yaml-eslint-parser": "1.2.3"
Expand Down
7 changes: 5 additions & 2 deletions src/__tests__/logger.spec.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ describe('unit:logger', () => {
let types: string[]

beforeAll(() => {
types = Object.keys(logTypes).filter(k => k !== logTypes.inspect)
types = Object.keys(logTypes).filter(k => {
return k !== logTypes.inspect && k !== logTypes.silent
})
})

it('should be logger object', () => {
Expand All @@ -26,7 +28,8 @@ describe('unit:logger', () => {
expect(subject).to.have.property('format').satisfy(isObjectPlain)
expect(subject).to.have.property('level', logLevels.info)
expect(subject).to.have.property('levels', logLevels)
expect(subject).to.have.property('reporters').be.instanceof(Set).and.empty
expect(subject).to.have.property('reporters').be.instanceof(Set)
expect(subject).to.have.nested.property('reporters.size', 1)
expect(subject).to.have.property('stderr', process.stderr)
expect(subject).to.have.property('stdout', process.stdout)
expect(subject).to.have.property('types').with.keys(types)
Expand Down
5 changes: 5 additions & 0 deletions src/enums/log-levels.mts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ import type { LogLevel } from '@flex-development/log'
const logLevels = Object.freeze({
silent: -1,
error: 0,
fatal: 0,
warn: 1,
log: 2,
fail: 3,
info: 3,
ready: 3,
start: 3,
success: 3,
debug: 4,
trace: 5,
verbose: 999
Expand Down
4 changes: 3 additions & 1 deletion src/enums/log-types.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import type { LogType } from '@flex-development/log'
*
* @internal
*
* @enum {LogType | 'inspect'}
* @enum {LogType | 'inspect' | 'silent'}
*/
enum logTypes {
debug = 'debug',
error = 'error',
fail = 'fail',
fatal = 'fatal',
info = 'info',
inspect = 'inspect',
log = 'log',
ready = 'ready',
silent = 'silent',
start = 'start',
success = 'success',
trace = 'trace',
Expand Down
16 changes: 11 additions & 5 deletions src/interfaces/__tests__/input-log-object.spec-d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type TestSubject from '#interfaces/input-log-object'
import type { Color } from '@flex-development/colors'
import type {
LogFormatOptions,
LogLevel,
LogLevelOption,
LogType
} from '@flex-development/log'
import type { Nilable } from '@flex-development/tutils'
Expand Down Expand Up @@ -49,16 +49,16 @@ describe('unit-d:interfaces/InputLogObject', () => {
.toEqualTypeOf<Nilable<string>>()
})

it('should match [level?: LogLevel | null | undefined]', () => {
it('should match [level?: LogLevelOption | null | undefined]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('level')
.toEqualTypeOf<Nilable<LogLevel>>()
.toEqualTypeOf<Nilable<LogLevelOption>>()
})

it('should match [message?: string | null | undefined]', () => {
it('should match [message?: unknown]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('message')
.toEqualTypeOf<Nilable<string>>()
.toEqualTypeOf<unknown>()
})

it('should match [stack?: string | null | undefined]', () => {
Expand All @@ -67,6 +67,12 @@ describe('unit-d:interfaces/InputLogObject', () => {
.toEqualTypeOf<Nilable<string>>()
})

it('should match [tag?: string | null | undefined]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('tag')
.toEqualTypeOf<Nilable<string>>()
})

it('should match [type?: LogType | null | undefined]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('type')
Expand Down
15 changes: 10 additions & 5 deletions src/interfaces/__tests__/log-format-options.spec-d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
*/

import type TestSubject from '#interfaces/log-format-options'
import type { Nilable, Optional } from '@flex-development/tutils'
import type { InspectOptions } from '@flex-development/log'
import type { Nilable } from '@flex-development/tutils'

describe('unit-d:interfaces/LogFormatOptions', () => {
it('should match [colors?: boolean | null | undefined]', () => {
it('should extend InspectOptions', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<InspectOptions>()
})

it('should match [badge?: boolean | null | undefined]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('colors')
.toHaveProperty('badge')
.toEqualTypeOf<Nilable<boolean>>()
})

Expand All @@ -19,10 +24,10 @@ describe('unit-d:interfaces/LogFormatOptions', () => {
.toEqualTypeOf<Nilable<number>>()
})

it('should match [date?: boolean | undefined]', () => {
it('should match [date?: boolean | null | undefined]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('date')
.toEqualTypeOf<Optional<boolean>>()
.toEqualTypeOf<Nilable<boolean>>()
})

it('should match [icon?: boolean | null | undefined]', () => {
Expand Down
20 changes: 20 additions & 0 deletions src/interfaces/__tests__/log-level-map.spec-d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ describe('unit-d:interfaces/LogLevelMap', () => {
expectTypeOf<TestSubject>().toHaveProperty('error').toEqualTypeOf<0>()
})

it('should match [fail: 3]', () => {
expectTypeOf<TestSubject>().toHaveProperty('fail').toEqualTypeOf<3>()
})

it('should match [fatal: 0]', () => {
expectTypeOf<TestSubject>().toHaveProperty('fatal').toEqualTypeOf<0>()
})

it('should match [info: 3]', () => {
expectTypeOf<TestSubject>().toHaveProperty('info').toEqualTypeOf<3>()
})
Expand All @@ -22,10 +30,22 @@ describe('unit-d:interfaces/LogLevelMap', () => {
expectTypeOf<TestSubject>().toHaveProperty('log').toEqualTypeOf<2>()
})

it('should match [ready: 3]', () => {
expectTypeOf<TestSubject>().toHaveProperty('ready').toEqualTypeOf<3>()
})

it('should match [silent: -1]', () => {
expectTypeOf<TestSubject>().toHaveProperty('silent').toEqualTypeOf<-1>()
})

it('should match [start: 3]', () => {
expectTypeOf<TestSubject>().toHaveProperty('start').toEqualTypeOf<3>()
})

it('should match [success: 3]', () => {
expectTypeOf<TestSubject>().toHaveProperty('success').toEqualTypeOf<3>()
})

it('should match [trace: 5]', () => {
expectTypeOf<TestSubject>().toHaveProperty('trace').toEqualTypeOf<5>()
})
Expand Down
11 changes: 2 additions & 9 deletions src/interfaces/__tests__/log-object.spec-d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import type TestSubject from '#interfaces/log-object'
import type {
InputLogObject,
LogFormatOptions,
LogLevel,
LogType
} from '@flex-development/log'
Expand All @@ -17,10 +16,10 @@ describe('unit-d:interfaces/LogObject', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<InputLogObject>()
})

it('should match [additional: string[]]', () => {
it('should match [additional?: string[] | null | undefined]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('additional')
.toEqualTypeOf<string[]>()
.toEqualTypeOf<Nilable<string[]>>()
})

it('should match [args: unknown[]]', () => {
Expand All @@ -33,12 +32,6 @@ describe('unit-d:interfaces/LogObject', () => {
expectTypeOf<TestSubject>().toHaveProperty('date').toEqualTypeOf<Date>()
})

it('should match [format: LogFormatOptions]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('format')
.toEqualTypeOf<LogFormatOptions>()
})

it('should match [level: LogLevel]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('level')
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/__tests__/log-type-map.spec-d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ describe('unit-d:interfaces/LogTypeMap', () => {
expectTypeOf<TestSubject>().toHaveProperty('fail').toEqualTypeOf<'fail'>()
})

it('should match [fatal: "fatal"]', () => {
expectTypeOf<TestSubject>().toHaveProperty('fatal').toEqualTypeOf<'fatal'>()
})

it('should match [info: "info"]', () => {
expectTypeOf<TestSubject>().toHaveProperty('info').toEqualTypeOf<'info'>()
})
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/__tests__/write-stream.spec-d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
*/

import type TestSubject from '#interfaces/write-stream'
import type { Nilable } from '@flex-development/tutils'

describe('unit-d:interfaces/WriteStream', () => {
it('should match [columns: number | null | undefined]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('columns')
.toEqualTypeOf<Nilable<number>>()
})

describe('write', () => {
type Subject = TestSubject['write']

Expand Down
Loading

0 comments on commit 194e988

Please sign in to comment.