Skip to content

Commit

Permalink
refactor(types): improve type implementations and tests
Browse files Browse the repository at this point in the history
- dropped EnsureString, Keys, MergeDefaults, OmitNative, Omit, PickNative, Pick
- MergeDefaults functionality was merged into Merge
- TupleLength -> Length
- TupleToUnion -> ArrayToUnion
- Omit and Pick were improved, but still under review
- added several new types

Signed-off-by: Lexus Drumgold <[email protected]>
  • Loading branch information
unicornware committed Jul 3, 2023
1 parent b159afe commit ed37d71
Show file tree
Hide file tree
Showing 295 changed files with 12,653 additions and 2,485 deletions.
7 changes: 7 additions & 0 deletions .attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"color": true,
"emoji": true,
"format": "ascii",
"ignoreRules": [],
"summary": true
}
4 changes: 2 additions & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ ignore:
- '**/__mocks__/**'
- '**/__tests__/**'
- '**/index.ts'
- src/interfaces/
- src/types/
- '**/interfaces'
- '**/types'
- src/utils/*.options.ts
5 changes: 5 additions & 0 deletions .dictionary.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
abcdefghijklmnopqrstuvwyz
ardatan
attw
bdougie
booleanish
cefc
Expand Down Expand Up @@ -31,6 +33,9 @@ promisable
stringafiable
tryit
tscu
uncapitalize
unstub
vates
vitest
yarnrc
zyxwvutsrqponmlkjihgfedcba
4 changes: 3 additions & 1 deletion .eslintrc.base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,9 @@ const config = {
implementsReplacesDocs: true,
overrideReplacesDocs: true,
preferredTypes: {
'*': false
'*': false,
'.<>': false,
'Array<>': { replacement: '[]' }
},
structuredTags: {
const: {
Expand Down
28 changes: 6 additions & 22 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,19 @@ const config = {
overrides: [
...require('./.eslintrc.base.cjs').overrides,
{
files: [
'src/types/built-in.ts',
'src/types/fn.ts',
'src/types/simplify.ts'
],
rules: {
'@typescript-eslint/ban-types': 0
}
},
{
files: ['src/types/built-in.ts'],
files: ['src/interfaces/map-like.ts'],
rules: {
'@typescript-eslint/array-type': 0
'@typescript-eslint/consistent-indexed-object-style': 0
}
},
{
files: [
'src/types/head.ts',
'src/types/is-tuple.ts',
'src/types/tail.ts'
'src/types/built-in.ts',
'src/types/fn.ts',
'src/types/is-index-signature.ts'
],
rules: {
'@typescript-eslint/no-unused-vars': 0
}
},
{
files: ['src/interfaces/map-like.ts'],
rules: {
'@typescript-eslint/consistent-indexed-object-style': 0
'@typescript-eslint/ban-types': 0
}
}
],
Expand Down
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ updates:
prefix: build
include: scope
directory: /
ignore:
- dependency-name: vitest
labels:
- scope:dependencies
- type:build
Expand Down
2 changes: 1 addition & 1 deletion .github/infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ branches:
- context: test (18)
- context: test (19)
- context: test (20)
- context: typescript (5.1.0-beta)
- context: typescript (5.1.6)
- context: typescript (latest)
- context: typescript (~4.9.0)
strict: true
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ jobs:
- gitguardian
- preflight
runs-on: ubuntu-latest
env:
TARFILE: |
(startsWith(github.ref_name, 'release/') && ${{ format('@{0}-{1}-{2}.tgz', github.repository_owner, github.event.repository.name, needs.preflight.outputs.version) }})
|| ${{ format('@{0}-{1}-{2}+{3}.tgz', github.repository_owner, github.event.repository.name, needs.preflight.outputs.version, github.event.pull_request.head.sha || github.sha) }}
steps:
- id: checkout
name: Checkout ${{ env.REF_NAME }}
Expand All @@ -372,19 +376,24 @@ jobs:
with:
key: ${{ runner.os }}-${{ github.run_id }}
path: ${{ env.CACHE_PATH }}
- id: local-binaries
name: Add local binaries to $PATH
run: echo "$GITHUB_WORKSPACE/$CACHE_PATH/.bin" >> $GITHUB_PATH
- id: pack
name: Pack project
run: yarn pack -o %s-%v.tgz
run: yarn pack -o ${{ env.TARFILE }}
- id: typecheck
name: Run typecheck
run: yarn check:types:build
- id: attw
name: Analyze types distribution
run: attw ${{ env.TARFILE }}
- id: pkg-size-report
name: Package size report
run: yarn pkg-size
- id: archive
name: Archive production artifacts
uses: actions/[email protected]
with:
name: |
${{ format('@{0}-{1}-{2}', github.repository_owner, github.event.repository.name, needs.preflight.outputs.version) }}
path: '*.tgz'
name: ${{ env.TARFILE }}
path: ${{ env.TARFILE }}
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
3 changes: 2 additions & 1 deletion __fixtures__/book.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @module tests/fixtures/Book
*/

import type { Nullable, Simplify } from '#src/types'
import type Author from './author.interface'
import type Publisher from './publisher.interface'

Expand All @@ -23,7 +24,7 @@ interface Book {
/**
* Book publisher.
*/
publisher?: Publisher
publisher?: Nullable<Simplify<Publisher>>

/**
* Book readers.
Expand Down
26 changes: 0 additions & 26 deletions __fixtures__/ordered-pair.ts

This file was deleted.

31 changes: 31 additions & 0 deletions __fixtures__/vehicle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @file Test Fixtures - Vehicle
* @module tests/fixtures/Vehicle
*/

/**
* Object representing a vehicle.
*/
type Vehicle = {
/**
* Vehicle brand.
*/
make: string

/**
* Vehicle model.
*/
model: string

/**
* Vehicle identification number.
*/
vin: string

/**
* Vehicle model year.
*/
year: number
}

export type { Vehicle as default }
68 changes: 47 additions & 21 deletions __tests__/reporters/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (isArray<Task>(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 task.type === 'custom'
? [task as unknown as Test]
: 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
Loading

0 comments on commit ed37d71

Please sign in to comment.