Skip to content

Commit

Permalink
build(deps): bump @flex-development/tutils from 6.0.0-alpha.10 to 6.0…
Browse files Browse the repository at this point in the history
….0-alpha.16

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Aug 7, 2023
1 parent 0da2e0c commit d77c0f5
Show file tree
Hide file tree
Showing 37 changed files with 394 additions and 350 deletions.
2 changes: 2 additions & 0 deletions .dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ bdougie
cefc
codecov
commitlintrc
customizer
dedupe
dessant
dohm
Expand All @@ -13,6 +14,7 @@ hmarr
iife
infile
keyid
ksort
larsgw
lcov
lintstagedrc
Expand Down
8 changes: 5 additions & 3 deletions __tests__/interfaces/mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file Test Environment Interfaces - Spy
* @module tests/interfaces/Spy
* @file Test Environment Interfaces - Mock
* @module tests/interfaces/Mock
*/

import type { Fn } from '@flex-development/tutils'
Expand All @@ -11,9 +11,11 @@ import type * as vitest from 'vitest'
*
* @template F - Function being mocked
*
* @extends {Fn<Parameters<F>,ReturnType<F>>}
* @extends {vitest.Mock<Parameters<F>,ReturnType<F>>}
*/
interface Mock<F extends Fn = Fn>
extends vitest.Mock<Parameters<F>, ReturnType<F>> {}
extends Fn<Parameters<F>, ReturnType<F>>,
vitest.Mock<Parameters<F>, ReturnType<F>> {}

export type { Mock as default }
4 changes: 3 additions & 1 deletion __tests__/interfaces/spy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import type * as vitest from 'vitest'
*
* @template F - Function being spied on
*
* @extends {Fn<Parameters<F>,ReturnType<F>>}
* @extends {vitest.SpyInstance<Parameters<F>,ReturnType<F>>}
*/
interface Spy<F extends Fn = Fn>
extends vitest.SpyInstance<Parameters<F>, ReturnType<F>> {}
extends Fn<Parameters<F>, ReturnType<F>>,
vitest.SpyInstance<Parameters<F>, ReturnType<F>> {}

export type { Spy as default }
74 changes: 50 additions & 24 deletions __tests__/reporters/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @module tests/reporters/Notifier
*/

import type { OneOrMany } from '@flex-development/tutils'
import { cast, isArray, type OneOrMany } from '@flex-development/tutils'
import notifier from 'node-notifier'
import type NotificationCenter from 'node-notifier/notifiers/notificationcenter'
import { performance } from 'node:perf_hooks'
Expand All @@ -20,22 +20,28 @@ import type { File, Reporter, Task, Test, Vitest } from 'vitest'
*/
class Notifier implements Reporter {
/**
* Test reporter context.
*
* @public
* @member {Vitest} ctx - Test reporter context
* @member {Vitest} ctx
*/
public ctx: Vitest = {} as Vitest
public ctx!: Vitest

/**
* Test run end time (in milliseconds).
*
* @public
* @member {number} end - Test run end time (in milliseconds)
* @member {number} end
*/
public end: number = 0
public end!: number

/**
* Test run start time (in milliseconds).
*
* @public
* @member {number} start - Test run start time (in milliseconds)
* @member {number} start
*/
public start: number = 0
public start!: number

/**
* Sends a notification.
Expand All @@ -52,19 +58,39 @@ class Notifier implements Reporter {
files: File[] = this.ctx.state.getFiles(),
errors: unknown[] = this.ctx.state.getUnhandledErrors()
): Promise<void> {
/** @const {Test[]} tests - Tests run */
/**
* Tests that have been run.
*
* @const {Test[]} tests
*/
const tests: Test[] = this.tests(files)

/** @const {number} fails - Total number of failed tests */
/**
* Total number of failed tests.
*
* @const {number} fails
*/
const fails: number = tests.filter(t => t.result?.state === 'fail').length

/** @const {number} passes - Total number of passed tests */
/**
* Total number of passed tests.
*
* @const {number} passes
*/
const passes: number = tests.filter(t => t.result?.state === 'pass').length

/** @var {string} message - Notification message */
/**
* Notification message.
*
* @var {string} message
*/
let message: string = ''

/** @var {string} title - Notification title */
/**
* Notification title.
*
* @var {string} title
*/
let title: string = ''

// get notification title and message based on number of failed tests
Expand All @@ -76,7 +102,11 @@ class Notifier implements Reporter {

title = '\u274C Failed'
} else {
/** @const {number} time - Time to run all tests (in milliseconds) */
/**
* Time to run all tests (in milliseconds).
*
* @const {number} time
*/
const time: number = this.end - this.start

message = dedent`
Expand Down Expand Up @@ -128,29 +158,25 @@ class Notifier implements Reporter {
*/
public onInit(context: Vitest): void {
this.ctx = context
return void (this.start = performance.now())
return void ((this.start = performance.now()) && (this.end = 0))
}

/**
* Returns an array of {@link Test} objects.
* Returns an array of {@linkcode Test} objects.
*
* @protected
*
* @param {OneOrMany<Task>} [tasks=[]] - Tasks to collect tests from
* @return {Test[]} `Test` object array
*/
protected tests(tasks: OneOrMany<Task> = []): Test[] {
const { mode } = this.ctx

return (Array.isArray(tasks) ? tasks : [tasks]).flatMap(task => {
const { type } = task

return mode === 'typecheck' && type === 'suite' && task.tasks.length === 0
? ([task] as unknown as [Test])
: type === 'test'
return (isArray<Task>(tasks) ? tasks : [tasks]).flatMap(task => {
return task.type === 'custom'
? [cast(task)]
: task.type === 'test'
? [task]
: 'tasks' in task
? task.tasks.flatMap(t => (t.type === 'test' ? [t] : this.tests(t)))
? task.tasks.flatMap(task => this.tests(task))
: []
})
}
Expand Down
21 changes: 13 additions & 8 deletions config/changelog.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import {
type Commit
} from '@flex-development/commitlint-config'
import pathe from '@flex-development/pathe'
import { CompareResult, isNIL } from '@flex-development/tutils'
import {
CompareResult,
at,
includes,
isNIL,
select
} from '@flex-development/tutils'
import addStream from 'add-stream'
import conventionalChangelog from 'conventional-changelog'
import type { Options } from 'conventional-changelog-core'
Expand Down Expand Up @@ -154,7 +160,6 @@ sade('changelog', true)
const changelog: Readable = conventionalChangelog<Commit>(
{
append: false,
debug: debug ? console.debug.bind(console) : undefined,
outputUnreleased:
typeof outputUnreleased === 'boolean'
? outputUnreleased
Expand Down Expand Up @@ -198,10 +203,10 @@ sade('changelog', true)
return void apply(null, {
...commit,
committerDate: dateformat(commit.committerDate, 'yyyy-mm-dd', true),
mentions: commit.mentions.filter(m => m !== 'flexdevelopment'),
mentions: select(commit.mentions, m => m !== 'flexdevelopment'),
// @ts-expect-error ts(2322)
raw: commit,
references: commit.references.filter(ref => ref.action !== null),
references: select(commit.references, ref => ref.action !== null),
version: commit.gitTags ? vgx.exec(commit.gitTags)?.[1] : undefined
})
},
Expand Down Expand Up @@ -296,21 +301,21 @@ sade('changelog', true)
*
* @const {CommitEnhanced?} first_commit
*/
const first_commit: CommitEnhanced | undefined = commits.at(0)
const first_commit: CommitEnhanced | undefined = at(commits, 0)

/**
* Last commit in release.
*
* @const {CommitEnhanced?} last_commit
*/
const last_commit: CommitEnhanced | undefined = commits.at(-1)
const last_commit: CommitEnhanced | undefined = at(commits, -1)

// set current and previous tags
if (key && (!currentTag || !previousTag)) {
currentTag = key.version ?? undefined

// try setting previous tag based on current tag
if (gitSemverTags.includes(currentTag ?? '')) {
if (includes(gitSemverTags, currentTag)) {
const { version = '' } = key
previousTag = gitSemverTags[gitSemverTags.indexOf(version) + 1]
if (!previousTag) previousTag = last_commit?.hash ?? undefined
Expand All @@ -324,7 +329,7 @@ sade('changelog', true)
: !currentTag && version
? pkg.tagPrefix + version
: currentTag ?? version
previousTag = previousTag ?? gitSemverTags[0]
previousTag = previousTag ?? at(gitSemverTags, 0)
}

// set release date
Expand Down
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@
"@flex-development/mlly": "1.0.0-alpha.15",
"@flex-development/pathe": "1.0.3",
"@flex-development/tsconfig-types": "3.2.0",
"@flex-development/tutils": "6.0.0-alpha.10",
"merge-anything": "5.1.6",
"sort-keys": "5.0.0",
"@flex-development/tutils": "6.0.0-alpha.16",
"strip-bom": "5.0.0",
"strip-json-comments": "5.0.0"
},
Expand Down Expand Up @@ -147,7 +145,6 @@
"pkg-size": "2.4.0",
"prettier": "2.8.8",
"prettier-plugin-sh": "0.12.8",
"radash": "10.8.1",
"sade": "1.8.1",
"semver": "7.5.2",
"serve": "14.2.0",
Expand All @@ -172,8 +169,7 @@
}
},
"resolutions": {
"@ardatan/sync-fetch": "larsgw/sync-fetch#head=worker_threads",
"@flex-development/tutils": "6.0.0-alpha.10"
"@ardatan/sync-fetch": "larsgw/sync-fetch#head=worker_threads"
},
"engines": {
"node": ">=16.20.0",
Expand Down
12 changes: 6 additions & 6 deletions src/interfaces/__tests__/options-load-tsconfig.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
*/

import type mlly from '@flex-development/mlly'
import type { Fn, KeysRequired } from '@flex-development/tutils'
import type { Fn, Optional, RequiredKeys } from '@flex-development/tutils'
import type TestSubject from '../options-load-tsconfig'

describe('unit-d:interfaces/LoadTsconfigOptions', () => {
it('should allow empty object', () => {
expectTypeOf<KeysRequired<TestSubject>>().toBeNever()
expectTypeOf<RequiredKeys<TestSubject>>().toBeNever()
})

it('should match [file?: Fn<[mlly.ModuleId], boolean>]', () => {
it('should match [file?: Optional<Fn<[mlly.ModuleId], boolean>>]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('file')
.toEqualTypeOf<Fn<[mlly.ModuleId], boolean> | undefined>()
.toEqualTypeOf<Optional<Fn<[mlly.ModuleId], boolean>>>()
})

it('should match [read?: Fn<[mlly.ModuleId], string>]', () => {
it('should match [read?: Optional<Fn<[mlly.ModuleId], string>>]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('read')
.toEqualTypeOf<Fn<[mlly.ModuleId], string> | undefined>()
.toEqualTypeOf<Optional<Fn<[mlly.ModuleId], string>>>()
})
})
13 changes: 8 additions & 5 deletions src/interfaces/__tests__/options-resolve-paths.spec-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import type mlly from '@flex-development/mlly'
import type { Omit, Optional } from '@flex-development/tutils'
import type LoadTsconfigOptions from '../options-load-tsconfig'
import type TestSubject from '../options-resolve-paths'

Expand All @@ -13,9 +14,11 @@ describe('unit-d:interfaces/ResolvePathsOptions', () => {
})

it('should extend Omit<mlly.ResolveAliasOptions, "aliases" | "cwd">', () => {
expectTypeOf<TestSubject>().toMatchTypeOf<
Omit<mlly.ResolveAliasOptions, 'aliases' | 'cwd'>
>()
// Arrange
type Expect = Omit<mlly.ResolveAliasOptions, 'aliases' | 'cwd'>

// Expect
expectTypeOf<TestSubject>().toMatchTypeOf<Expect>()
})

it('should match [baseUrl?: mlly.ResolveAliasOptions["cwd"]]', () => {
Expand All @@ -30,9 +33,9 @@ describe('unit-d:interfaces/ResolvePathsOptions', () => {
.toEqualTypeOf<mlly.ModuleId>()
})

it('should match [tsconfig?: mlly.ModuleId]', () => {
it('should match [tsconfig?: Optional<mlly.ModuleId>]', () => {
expectTypeOf<TestSubject>()
.toHaveProperty('tsconfig')
.toEqualTypeOf<mlly.ModuleId | undefined>()
.toEqualTypeOf<Optional<mlly.ModuleId>>()
})
})
6 changes: 3 additions & 3 deletions src/interfaces/options-load-tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import type mlly from '@flex-development/mlly'
import type { Fn } from '@flex-development/tutils'
import type { Fn, Optional } from '@flex-development/tutils'

/**
* Options for loading tsconfig files.
Expand All @@ -20,7 +20,7 @@ interface LoadTsconfigOptions {
* @param {mlly.ModuleId} id - Module id to evaluate
* @return {boolean} `true` if file exists at `id`, `false` otherwise
*/
file?: Fn<[mlly.ModuleId], boolean> | undefined
file?: Optional<Fn<[mlly.ModuleId], boolean>>

/**
* Reads the file at the given module `id`.
Expand All @@ -32,7 +32,7 @@ interface LoadTsconfigOptions {
* @param {mlly.ModuleId} id - Module id to evaluate
* @return {string} File content at `id`
*/
read?: Fn<[mlly.ModuleId], string> | undefined
read?: Optional<Fn<[mlly.ModuleId], string>>
}

export type { LoadTsconfigOptions as default }
Loading

0 comments on commit d77c0f5

Please sign in to comment.