@rcompat/test 0.12.1 → 0.13.0
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/README.md +6 -6
- package/lib/private/index.d.ts +1 -1
- package/lib/private/intercept.d.ts +1 -1
- package/lib/private/intercept.js +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -288,7 +288,7 @@ called and how.
|
|
|
288
288
|
```js
|
|
289
289
|
import test from "@rcompat/test";
|
|
290
290
|
|
|
291
|
-
|
|
291
|
+
using telegram = test.intercept("https://api.telegram.org", setup => {
|
|
292
292
|
setup.post("/sendMessage", () => ({
|
|
293
293
|
ok: true,
|
|
294
294
|
result: { message_id: 42 },
|
|
@@ -309,9 +309,9 @@ test.case("notifies user via telegram on signup", async assert => {
|
|
|
309
309
|
});
|
|
310
310
|
```
|
|
311
311
|
|
|
312
|
-
`
|
|
313
|
-
|
|
314
|
-
|
|
312
|
+
`using` restores the original fetch automatically when the file scope exits.
|
|
313
|
+
For long-lived intercepts that need manual control, use `restore()` with
|
|
314
|
+
`test.ended`:
|
|
315
315
|
|
|
316
316
|
```js
|
|
317
317
|
const telegram = test.intercept("https://api.telegram.org", setup => {
|
|
@@ -474,7 +474,7 @@ which is serialized into a `Response` automatically.
|
|
|
474
474
|
| `calls(path)` | Number of times `path` was hit |
|
|
475
475
|
| `requests(path)` | Array of `Request` objects recorded for `path` |
|
|
476
476
|
| `restore()` | Reinstate the original `globalThis.fetch` |
|
|
477
|
-
| `[Symbol.
|
|
477
|
+
| `[Symbol.dispose]` | Called automatically by `using` |
|
|
478
478
|
|
|
479
479
|
### `Asserter`
|
|
480
480
|
|
|
@@ -614,7 +614,7 @@ test.case("divide works normally", assert => {
|
|
|
614
614
|
```js
|
|
615
615
|
import test from "@rcompat/test";
|
|
616
616
|
|
|
617
|
-
|
|
617
|
+
using openai = test.intercept("https://api.openai.com", setup => {
|
|
618
618
|
setup.post("/v1/chat/completions", () => ({
|
|
619
619
|
choices: [{ message: { content: "Hello!" } }],
|
|
620
620
|
}));
|
package/lib/private/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ declare const _default: {
|
|
|
18
18
|
calls(path: string): number;
|
|
19
19
|
requests(path: string): Request[];
|
|
20
20
|
restore(): void;
|
|
21
|
-
[Symbol.
|
|
21
|
+
[Symbol.dispose](): void;
|
|
22
22
|
};
|
|
23
23
|
extend<Subject, Extensions>(factory: Factory<Subject, Extensions>): ExtendedTest<Extensions>;
|
|
24
24
|
case(name: string, body: Body): void;
|
|
@@ -10,7 +10,7 @@ type Intercept = {
|
|
|
10
10
|
calls(path: string): number;
|
|
11
11
|
requests(path: string): Request[];
|
|
12
12
|
restore(): void;
|
|
13
|
-
[Symbol.
|
|
13
|
+
[Symbol.dispose](): void;
|
|
14
14
|
};
|
|
15
15
|
declare const _default: (base_url: string, setup: (setup: Setup) => void) => Intercept;
|
|
16
16
|
export default _default;
|
package/lib/private/intercept.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rcompat/test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Standard library testing",
|
|
5
5
|
"bugs": "https://github.com/rcompat/rcompat/issues",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"directory": "packages/test"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@rcompat/is": "^0.
|
|
18
|
+
"@rcompat/is": "^0.7.0"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@rcompat/fs": "^0.
|
|
22
|
-
"@rcompat/type": "^0.
|
|
21
|
+
"@rcompat/fs": "^0.29.0",
|
|
22
|
+
"@rcompat/type": "^0.13.0"
|
|
23
23
|
},
|
|
24
24
|
"type": "module",
|
|
25
25
|
"imports": {
|