@rcompat/test 0.10.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/private/Assert.d.ts +1 -1
- package/lib/private/Assert.js +11 -5
- package/lib/private/E.d.ts +3 -2
- package/lib/private/extend.d.ts +19 -0
- package/lib/private/extend.js +14 -0
- package/lib/private/index.d.ts +7 -4
- package/lib/private/index.js +8 -1
- package/package.json +3 -3
package/lib/private/Assert.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export default class Assert<const Actual> {
|
|
|
16
16
|
undefined(): this;
|
|
17
17
|
defined(): this;
|
|
18
18
|
instance(expected: UnknownFunction): this;
|
|
19
|
-
throws(expected
|
|
19
|
+
throws(expected: string | (new (...args: any[]) => Error)): this;
|
|
20
20
|
tries(): this;
|
|
21
21
|
pass(): void;
|
|
22
22
|
fail<const Expected extends Not<Equals<Actual, Expected>> extends true ? unknown : "was supposed to fail but didn't">(): void;
|
package/lib/private/Assert.js
CHANGED
|
@@ -80,12 +80,17 @@ export default class Assert {
|
|
|
80
80
|
this.#failed("[did not throw]");
|
|
81
81
|
}
|
|
82
82
|
catch (error) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
if (typeof expected === "string") {
|
|
84
|
+
const code = E(error).code;
|
|
85
|
+
code === expected
|
|
86
|
+
? this.#passed()
|
|
87
|
+
: this.#failed(expected, code ?? "[no code]");
|
|
86
88
|
}
|
|
87
89
|
else {
|
|
88
|
-
|
|
90
|
+
error instanceof expected
|
|
91
|
+
? this.#passed()
|
|
92
|
+
: this.#failed(expected.name, error?.constructor?.name
|
|
93
|
+
?? "[unknown]");
|
|
89
94
|
}
|
|
90
95
|
}
|
|
91
96
|
return this;
|
|
@@ -96,7 +101,8 @@ export default class Assert {
|
|
|
96
101
|
this.#passed();
|
|
97
102
|
}
|
|
98
103
|
catch (error) {
|
|
99
|
-
|
|
104
|
+
const { code, message } = E(error);
|
|
105
|
+
this.#failed(`${code ?? message}`, "[did not throw]");
|
|
100
106
|
}
|
|
101
107
|
return this;
|
|
102
108
|
}
|
package/lib/private/E.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
type
|
|
1
|
+
type EncodedError = {
|
|
2
2
|
message: string;
|
|
3
|
+
code?: string;
|
|
3
4
|
};
|
|
4
|
-
declare const _default: (error: unknown) =>
|
|
5
|
+
declare const _default: (error: unknown) => EncodedError;
|
|
5
6
|
export default _default;
|
|
6
7
|
//# sourceMappingURL=E.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type Assert from "#Assert";
|
|
2
|
+
import type Asserter from "#Asserter";
|
|
3
|
+
import type Body from "#Body";
|
|
4
|
+
import type { MaybePromise } from "@rcompat/type";
|
|
5
|
+
type ExtendedAssert<T, Extensions> = Assert<T> & Extensions;
|
|
6
|
+
type ExtendedAsserter<Extensions> = <const T>(actual?: T) => ExtendedAssert<T, Extensions>;
|
|
7
|
+
type ExtendedBody<Extensions> = (asserter: ExtendedAsserter<Extensions>) => MaybePromise<void>;
|
|
8
|
+
export type Factory<Subject, Extensions> = (assert: Asserter, subject: Subject) => Extensions;
|
|
9
|
+
export type ExtendedTest<Extensions> = {
|
|
10
|
+
case(name: string, body: ExtendedBody<Extensions>): void;
|
|
11
|
+
ended(end: () => MaybePromise<void>): void;
|
|
12
|
+
};
|
|
13
|
+
type Base = {
|
|
14
|
+
case(name: string, body: Body): void;
|
|
15
|
+
ended(end: () => MaybePromise<void>): void;
|
|
16
|
+
};
|
|
17
|
+
declare const _default: <Subject, Extensions>(base: Base, factory: Factory<Subject, Extensions>) => ExtendedTest<Extensions>;
|
|
18
|
+
export default _default;
|
|
19
|
+
//# sourceMappingURL=extend.d.ts.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default (base, factory) => ({
|
|
2
|
+
case(name, body) {
|
|
3
|
+
base.case(name, asserter => {
|
|
4
|
+
const extended = (actual) => {
|
|
5
|
+
const a = asserter(actual);
|
|
6
|
+
const extra = factory(asserter, actual);
|
|
7
|
+
return Object.assign(Object.create(a), extra);
|
|
8
|
+
};
|
|
9
|
+
return body(extended);
|
|
10
|
+
});
|
|
11
|
+
},
|
|
12
|
+
ended: base.ended.bind(base),
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=extend.js.map
|
package/lib/private/index.d.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type Asserter from "#Asserter";
|
|
1
2
|
import type Body from "#Body";
|
|
2
3
|
import type End from "#End";
|
|
4
|
+
import type Env from "#Env";
|
|
5
|
+
import type Result from "#Result";
|
|
6
|
+
import type Test from "#Test";
|
|
7
|
+
import type { ExtendedTest, Factory } from "#extend";
|
|
3
8
|
declare const _default: {
|
|
9
|
+
extend<Subject, Extensions>(factory: Factory<Subject, Extensions>): ExtendedTest<Extensions>;
|
|
4
10
|
case(name: string, body: Body): void;
|
|
5
11
|
ended(end: End): void;
|
|
6
12
|
};
|
|
7
13
|
export default _default;
|
|
8
|
-
export type {
|
|
9
|
-
export type { default as Env } from "#Env";
|
|
10
|
-
export type { default as Result } from "#Result";
|
|
11
|
-
export type { default as Test } from "#Test";
|
|
14
|
+
export type { Asserter, Env, ExtendedTest, Result, Test };
|
|
12
15
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/private/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import extend from "#extend";
|
|
1
2
|
import repository from "#repository";
|
|
2
|
-
|
|
3
|
+
const base = {
|
|
3
4
|
case(name, body) {
|
|
4
5
|
repository.put(name, body);
|
|
5
6
|
},
|
|
@@ -7,4 +8,10 @@ export default {
|
|
|
7
8
|
repository.ended(end);
|
|
8
9
|
},
|
|
9
10
|
};
|
|
11
|
+
export default {
|
|
12
|
+
...base,
|
|
13
|
+
extend(factory) {
|
|
14
|
+
return extend(base, factory);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
10
17
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rcompat/test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Standard library testing",
|
|
5
5
|
"bugs": "https://github.com/rcompat/rcompat/issues",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"directory": "packages/test"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@rcompat/fs": "^0.
|
|
19
|
-
"@rcompat/type": "^0.
|
|
18
|
+
"@rcompat/fs": "^0.27.1",
|
|
19
|
+
"@rcompat/type": "^0.10.0"
|
|
20
20
|
},
|
|
21
21
|
"type": "module",
|
|
22
22
|
"imports": {
|