Skip to content

Commit e75d78d

Browse files
committed
feat(testing): createThenable
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent e8ee57a commit e75d78d

43 files changed

Lines changed: 1111 additions & 33 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.attw.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"color": true,
33
"emoji": true,
44
"format": "ascii",
5-
"ignoreRules": ["cjs-resolves-to-esm", "internal-resolution-error"],
5+
"ignoreRules": [
6+
"cjs-resolves-to-esm",
7+
"internal-resolution-error",
8+
"no-resolution"
9+
],
610
"summary": true
711
}

.commitlintrc.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ import { scopes } from '@flex-development/commitlint-config'
1515
const config: UserConfig = {
1616
extends: ['@flex-development'],
1717
rules: {
18-
'scope-enum': [RuleConfigSeverity.Error, 'always', scopes(['chore'])]
18+
'scope-enum': [RuleConfigSeverity.Error, 'always', scopes([
19+
'chore',
20+
'testing'
21+
])]
1922
}
2023
}
2124

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ Attach a callback only for the rejection of a [`Thenable`][thenable] (`type`).
597597

598598
```ts
599599
type Catch<T = unknown, Reason = any> = <Next = never>(
600-
this: unknown,
600+
this: any,
601601
onrejected?: OnRejected<Next, Reason> | null | undefined
602602
) => Thenable<Next | T>
603603
```
@@ -741,7 +741,7 @@ Attach a callback that is invoked only when a [`Thenable`][thenable] is settled
741741

742742
```ts
743743
type Finally<T = unknown> = (
744-
this: unknown,
744+
this: any,
745745
onfinally?: OnFinally | null | undefined
746746
) => Thenable<T>
747747
```
@@ -901,7 +901,7 @@ Attach callbacks for the resolution and/or rejection of a [`Thenable`][thenable]
901901

902902
```ts
903903
type Then<T = unknown, Reason = any> = <Succ = T, Fail = never>(
904-
this: unknown,
904+
this: any,
905905
onfulfilled?: OnFulfilled<T, Succ> | null | undefined,
906906
onrejected?: OnRejected<Fail, Reason> | null | undefined
907907
) => Thenable<Fail | Succ>

__fixtures__/.gitkeep

Whitespace-only changes.

__fixtures__/boom.mts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @file Fixtures - error
3+
* @module fixtures/error
4+
*/
5+
6+
/**
7+
* A test error.
8+
*
9+
* @type {Error}
10+
*/
11+
export default new Error('boom!', { cause: { test: true } })

__fixtures__/resolved.mts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @file Fixtures - resolved
3+
* @module fixtures/resolved
4+
*/
5+
6+
import type ThenableType from '#tests/types/thenable-type'
7+
8+
/**
9+
* Record, where each key is a {@linkcode ThenableType}
10+
* and each value is a resolved value.
11+
*
12+
* @type {Record<ThenableType, boolean>}
13+
*/
14+
export default { fail: false, succ: true }

__tests__/types/thenable-type.mts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @file Type Aliases - ThenableType
3+
* @module tests/types/ThenableType
4+
*/
5+
6+
/**
7+
* Union of thenable types.
8+
*/
9+
type ThenableType = 'fail' | 'succ'
10+
11+
export type { ThenableType as default }

__tests__/utils/thrower.mts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @file Test Utilities - thrower
3+
* @module tests/utils/thrower
4+
*/
5+
6+
import error from '#fixtures/boom'
7+
8+
/**
9+
* Throw the test error.
10+
*
11+
* @this {void}
12+
*
13+
* @return {never}
14+
* Never; throws test error
15+
* @throws {Error}
16+
*/
17+
function thrower(this: void): never {
18+
throw error
19+
}
20+
21+
export default thrower

eslint.config.mjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,24 @@ const config = [
4545
}
4646
},
4747
{
48-
files: ['src/lib/when.mts'],
48+
files: [
49+
'src/lib/when.mts',
50+
'src/testing/lib/__tests__/create-thenable.functional.spec.mts'
51+
],
4952
rules: {
5053
'promise/prefer-await-to-then': 0
5154
}
5255
},
56+
{
57+
files: ['src/testing/lib/create-thenable.mts'],
58+
rules: {
59+
'@typescript-eslint/only-throw-error': 0,
60+
'@typescript-eslint/promise-function-async': 0,
61+
'promise/prefer-await-to-then': 0,
62+
'unicorn/catch-error-name': 0,
63+
'unicorn/no-thenable': 0
64+
}
65+
},
5366
{
5467
files: ['src/types/chain.mts'],
5568
rules: {

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@
5555
"when": "./src/index.mts",
5656
"default": "./dist/index.mjs"
5757
},
58-
"./package.json": "./package.json"
58+
"./package.json": "./package.json",
59+
"./testing": {
60+
"when": "./src/testing/index.mts",
61+
"default": "./dist/testing/index.mjs"
62+
}
5963
},
6064
"imports": {
6165
"#fixtures/*": "./__fixtures__/*.mts",
@@ -67,6 +71,10 @@
6771
"when": "./src/lib/*.mts",
6872
"default": "./dist/lib/*.mjs"
6973
},
74+
"#testing/*": {
75+
"when": "./src/testing/*.mts",
76+
"default": "./dist/testing/*.mjs"
77+
},
7078
"#tests/*": "./__tests__/*.mts",
7179
"#types/*": {
7280
"when": "./src/types/*.mts",
@@ -82,7 +90,7 @@
8290
},
8391
"scripts": {
8492
"build": "yarn clean:build && tsc -p tsconfig.build.json --noEmit false && yarn bundle:dts",
85-
"bundle:dts": "rollup --config=rollup.config.mts && trash dist/{interfaces,types} && trash dist/{internal,lib}/*.d.mts",
93+
"bundle:dts": "rollup --config=rollup.config.mts && trash dist/**/{interfaces,types} && trash dist/**/lib/*.d.mts",
8694
"check:ci": "yarn dedupe --check && yarn check:format && yarn check:lint && yarn check:spelling && yarn typecheck && yarn check:types && yarn test:cov && yarn pack && yarn check:types:build && attw package.tgz && yarn clean:pack",
8795
"check:format": "dprint check --incremental=false",
8896
"check:lint": "eslint --exit-on-fatal-error --max-warnings 0 .",
@@ -124,6 +132,7 @@
124132
"@commitlint/cli": "20.4.2",
125133
"@commitlint/types": "20.4.0",
126134
"@edge-runtime/vm": "5.0.0",
135+
"@faker-js/faker": "10.3.0",
127136
"@flex-development/commitlint-config": "1.0.1",
128137
"@flex-development/eslint-config": "1.1.1",
129138
"@flex-development/grease": "3.0.0-alpha.9",

0 commit comments

Comments
 (0)