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.18

Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Aug 9, 2023
1 parent ea9bb05 commit 3082838
Show file tree
Hide file tree
Showing 73 changed files with 778 additions and 949 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@
"shellformat.flag": "-ci -fn -i=2 -sr",
"shellformat.useEditorConfig": true,
"terminal.integrated.copyOnSelection": true,
"terminal.integrated.scrollback": 10000,
"todo-tree.filtering.ignoreGitSubmodules": true,
"todo-tree.filtering.includeHiddenFiles": false,
"todo-tree.filtering.useBuiltInExcludes": "file and search excludes",
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 }
10 changes: 6 additions & 4 deletions __tests__/interfaces/spy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
*/

import type { Fn } from '@flex-development/tutils'
import type { SpyInstance } from 'vitest'
import type * as vitest from 'vitest'

/**
* {@linkcode SpyInstance} utility.
* {@linkcode vitest.SpyInstance} utility.
*
* @template F - Function being spied on
*
* @extends {SpyInstance<Parameters<F>,ReturnType<F>>}
* @extends {Fn<Parameters<F>,ReturnType<F>>}
* @extends {vitest.SpyInstance<Parameters<F>,ReturnType<F>>}
*/
interface Spy<F extends Fn = Fn>
extends SpyInstance<Parameters<F>, ReturnType<F>> {}
extends Fn<Parameters<F>, ReturnType<F>>,
vitest.SpyInstance<Parameters<F>, ReturnType<F>> {}

export type { Spy as default }
72 changes: 49 additions & 23 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,7 +158,7 @@ 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))
}

/**
Expand All @@ -140,17 +170,13 @@ class Notifier implements Reporter {
* @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
22 changes: 15 additions & 7 deletions __tests__/setup/serializers/result-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@
*/

import type { Result } from '#src/interfaces'
import { isNIL, isObjectPlain, isString } from '@flex-development/tutils'
import {
cast,
get,
isArray,
isNIL,
isObjectPlain,
isString,
omit,
pick
} from '@flex-development/tutils'
import pf from 'pretty-format'
import { get, omit, pick } from 'radash'

expect.addSnapshotSerializer({
/**
Expand All @@ -16,7 +24,7 @@ expect.addSnapshotSerializer({
* @return {string} `value` as printable string
*/
print(value: unknown): string {
value = (value as Result[]).map(result => {
value = cast<Result[]>(value).map(result => {
result.cwd = result.cwd.replace(/.*?(?=\/__.+)/, '${process.cwd()}')

return {
Expand All @@ -37,16 +45,16 @@ expect.addSnapshotSerializer({
* @return {value is Result[]} `true` if `value` is {@linkcode Result} array
*/
test(value: unknown): value is Result[] {
return Array.isArray(value)
return isArray(value)
? value.every(item => {
return (
isString(get(item, 'cwd')) &&
Array.isArray(get(item, 'errors')) &&
isArray(get(item, 'errors')) &&
(isObjectPlain(get(item, 'mangleCache')) ||
isNIL(get(item, 'mangleCache'))) &&
isString(get(item, 'outdir')) &&
Array.isArray(get(item, 'outputs')) &&
Array.isArray(get(item, 'warnings'))
isArray(get(item, 'outputs')) &&
isArray(get(item, 'warnings'))
)
})
: false
Expand Down
1 change: 1 addition & 0 deletions __tests__/utils/create-testing-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import AppModule from '#src/cli/app.module'
import { CLI_NAME } from '#src/cli/constants'
import type { Omit } from '@flex-development/tutils'
import { Module } from '@nestjs/common'
import type { TestingModule } from '@nestjs/testing'
import { CommandRunnerModule } from 'nest-commander'
Expand Down
3 changes: 2 additions & 1 deletion __tests__/utils/get-package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import type mlly from '@flex-development/mlly'
import type pkg from '@flex-development/pkg-types'
import { cast } from '@flex-development/tutils'

/**
* Retrieves a `package.json` object.
Expand All @@ -29,7 +30,7 @@ const getPackageJson = async (
*/
const fs: typeof import('node:fs') = await vi.importActual('node:fs')

return JSON.parse(fs.readFileSync(id, 'utf8')) as pkg.PackageJson
return cast(JSON.parse(fs.readFileSync(id, 'utf8')))
}

export default getPackageJson
17 changes: 13 additions & 4 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { defineBuildConfig, type Config } from '#src'
import pathe from '@flex-development/pathe'
import pkg from './package.json' assert { type: 'json' }
import tsconfig from './tsconfig.build.json' assert { type: 'json' }

Expand All @@ -15,7 +16,13 @@ import tsconfig from './tsconfig.build.json' assert { type: 'json' }
const config: Config = defineBuildConfig({
charset: 'utf8',
entries: [
{ ignore: ['cli/**'] },
{ dts: 'only', ignore: ['cli/**'] },
{ dts: false, pattern: ['(interfaces|types)/index.ts'] },
{
dts: false,
pattern: ['*.ts', 'config/*', 'internal/*', 'plugins/*', 'utils/*'],
sourcemap: true
},
{
bundle: true,
external: [
Expand All @@ -30,11 +37,13 @@ const config: Config = defineBuildConfig({
minify: true,
name: 'cli',
platform: 'node',
source: 'src/cli/index.ts'
source: 'src/cli/index.ts',
sourcemap: true,
sourcesContent: false
}
],
sourcemap: true,
sourcesContent: false,
minifySyntax: true,
sourceRoot: 'file' + pathe.delimiter + pathe.sep.repeat(2),
target: [
pkg.engines.node.replace(/^\D+/, 'node'),
tsconfig.compilerOptions.target
Expand Down
Loading

0 comments on commit 3082838

Please sign in to comment.