@wolfstar/http-framework-test-utils 3.0.0 → 3.0.2
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 +112 -0
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +9 -9
- package/dist/esm/types-EeGiyIko.d.ts.map +1 -1
- package/dist/esm/vitest.d.ts +0 -1
- package/dist/esm/vitest.d.ts.map +1 -1
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# `@wolfstar/http-framework-test-utils`
|
|
2
|
+
|
|
3
|
+
Test utilities and fixtures for [`@wolfstar/http-framework`](https://github.com/wolfstar-project/stars-components/tree/main/packages/http-framework) — designed to work with [Vitest](https://vitest.dev/).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @wolfstar/http-framework-test-utils vitest
|
|
9
|
+
# or
|
|
10
|
+
pnpm add -D @wolfstar/http-framework-test-utils vitest
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### `createTestHarness`
|
|
16
|
+
|
|
17
|
+
The entry point for most tests. Returns a `TestableClient` and an `InteractionTestRunner` wired together:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { createTestHarness } from '@wolfstar/http-framework-test-utils';
|
|
21
|
+
|
|
22
|
+
const { client, runner } = createTestHarness();
|
|
23
|
+
|
|
24
|
+
// Load your commands before running tests
|
|
25
|
+
await client.load();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Running interactions
|
|
29
|
+
|
|
30
|
+
Use `InteractionTestRunner.run()` to dispatch a Discord interaction and get back a typed result:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { ChatInputApplicationCommandInteractionData } from '@wolfstar/http-framework-test-utils';
|
|
34
|
+
|
|
35
|
+
const result = await runner.run({
|
|
36
|
+
...ChatInputApplicationCommandInteractionData,
|
|
37
|
+
data: { id: '0', name: 'ping', type: 1, options: [] }
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
expect(result.statusCode).toBe(200);
|
|
41
|
+
expect(result.json()).toMatchObject({ type: 4, data: { content: 'Pong!' } });
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Vitest custom matchers
|
|
45
|
+
|
|
46
|
+
Import and register the matchers in your Vitest setup file:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
// vitest.setup.ts
|
|
50
|
+
import { expect } from 'vitest';
|
|
51
|
+
import { httpFrameworkMatchers } from '@wolfstar/http-framework-test-utils/vitest';
|
|
52
|
+
|
|
53
|
+
expect.extend(httpFrameworkMatchers);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Then in tests:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
expect(result).toHaveStatus(200);
|
|
60
|
+
expect(result).toHaveBody('{"type":4}');
|
|
61
|
+
expect(result).toHaveJsonBody({ type: 4, data: { content: 'Pong!' } });
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`toHaveJsonBody` performs a strict deep-equality check: the expected object must contain the exact same set of keys as the response body at every level. If you only care about a subset of fields, assert against `result.json()` with Vitest's built-in `toMatchObject` instead.
|
|
65
|
+
|
|
66
|
+
### Available fixtures
|
|
67
|
+
|
|
68
|
+
Pre-built interaction payloads for all interaction types:
|
|
69
|
+
|
|
70
|
+
| Export | Type |
|
|
71
|
+
| -------------------------------------------------- | ---------------------------- |
|
|
72
|
+
| `ChatInputApplicationCommandInteractionData` | Chat input command |
|
|
73
|
+
| `MessageApplicationCommandInteractionData` | Message context menu command |
|
|
74
|
+
| `UserApplicationCommandInteractionData` | User context menu command |
|
|
75
|
+
| `ApplicationCommandAutocompleteInteractionData` | Autocomplete |
|
|
76
|
+
| `MessageComponentButtonInteractionData` | Button |
|
|
77
|
+
| `MessageComponentStringSelectInteractionData` | String select menu |
|
|
78
|
+
| `MessageComponentChannelSelectInteractionData` | Channel select menu |
|
|
79
|
+
| `MessageComponentRoleSelectInteractionData` | Role select menu |
|
|
80
|
+
| `MessageComponentUserSelectInteractionData` | User select menu |
|
|
81
|
+
| `MessageComponentMentionableSelectInteractionData` | Mentionable select menu |
|
|
82
|
+
| `ModalSubmitInteractionData` | Modal submit |
|
|
83
|
+
|
|
84
|
+
Base data is also exported: `UserData`, `InteractionGuildMemberData`, `MessageData`, `BaseInteractionData`.
|
|
85
|
+
|
|
86
|
+
### Helper utilities
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { buildSubcommand, getAndDelete, makeCommand } from '@wolfstar/http-framework-test-utils';
|
|
90
|
+
|
|
91
|
+
// Build a SlashCommandSubcommandBuilder
|
|
92
|
+
const sub = buildSubcommand('add', 'Adds two numbers');
|
|
93
|
+
|
|
94
|
+
// Construct a command instance for unit testing
|
|
95
|
+
const cmd = makeCommand(MyCommand);
|
|
96
|
+
|
|
97
|
+
// Retrieve and clean up a command's registry entry
|
|
98
|
+
const entry = getAndDelete(MyCommand);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Exports
|
|
102
|
+
|
|
103
|
+
| Entry point | Contents |
|
|
104
|
+
| -------------------------------------------- | ------------------------------------------------ |
|
|
105
|
+
| `@wolfstar/http-framework-test-utils` | All utilities, fixtures, runners, and types |
|
|
106
|
+
| `@wolfstar/http-framework-test-utils/vitest` | Custom Vitest matchers (`httpFrameworkMatchers`) |
|
|
107
|
+
|
|
108
|
+
## Requirements
|
|
109
|
+
|
|
110
|
+
- Node.js `>=20`
|
|
111
|
+
- `@wolfstar/http-framework` (peer dependency)
|
|
112
|
+
- `vitest >=4.0.0` (optional peer dependency — only needed for the `/vitest` entry point)
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -5,7 +5,6 @@ import { APIApplicationCommandAutocompleteInteraction, APIAuthorizingIntegration
|
|
|
5
5
|
import { Writable } from "node:stream";
|
|
6
6
|
import { Constructor } from "@sapphire/utilities";
|
|
7
7
|
import { ServerResponse } from "node:http";
|
|
8
|
-
|
|
9
8
|
//#region src/commands.d.ts
|
|
10
9
|
declare function buildSubcommand(name: string, description: string): SlashCommandSubcommandBuilder;
|
|
11
10
|
declare function getAndDelete<Options extends Command.Options>(command: typeof Command<Options>): any;
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/commands.ts","../../src/fixtures.ts","../../src/TestableClient.ts","../../src/InteractionTestRunner.ts","../../src/MockServerResponse.ts","../../src/snowflake.ts","../../src/testHarness.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/commands.ts","../../src/fixtures.ts","../../src/TestableClient.ts","../../src/InteractionTestRunner.ts","../../src/MockServerResponse.ts","../../src/snowflake.ts","../../src/testHarness.ts"],"mappings":";;;;;;;;iBAKgB,gBAAgB,cAAc,sBAAsB;iBAIpD,aAAa,gBAAgB,QAAQ,SAAS,gBAAgB,QAAQ;iBAQtE,YAAY,gBAAgB,QAAQ,SAAS,cAAc,YAAY,QAAQ,YAAY,QAAQ;;;cCWtG,UAAU,SAAS;cAWnB,4BAA4B,SAAS;cAUrC,aAAa,SAAS;cAiBtB,iBAAiB;cACjB,YAAY;cAEZ;;;;;;;;;;WAUQ,cAAA;WACkB,gCAAA;;;cAI1B,+CAA+C;cAM/C,4CAA4C;cAQ5C,0CAA0C;cAc1C,uCAAuC;cASvC,uCAAuC;cASvC,8CAA8C,yCAAyC;cASvF,kDAAkD,6CAA6C;cAc/F,2CAA2C,sCAAsC;cASjF,6CAA6C,wCAAwC;cASrF,2CAA2C,sCAAsC;cASjF,4BAA4B;;;cC3K5B,uBAAuB;EAChB,YAAA,UAAS,QAAQ;EAId,kBACrB,aAAa,QAAQ,gBAAgB,yCACrC,UAAU,iBACR,QAAQ;;;;cCZC;;EAGO,YAAA,QAAQ;EAId,IAAI,aAAa,QAAQ,gBAAgB,0CAA0C,QAAQ;;;;cCT5F,2BAA2B;;EAChC;WACS,SAAS;EAGlB,UAAU,cAAc;EAIf,OAAO,gBAAgB,WAAW,gBAAgB,WAAW,QAAQ;EAK9E;EAIA,cAAc,gBAAgB;EAI9B;;iBAOQ,gBAAgB;;;UC9Bf;;EAEhB,qBAAqB;;EAErB;;EAEA;;EAEA;;iBAWe,kBAAkB,UAAS;iBAkB3B,yBAAyB,UAAS,KAAK;;;iBCnCvC,kBAAkB,UAAS,QAAQ;;;;KAMvC,cAAc,kBAAkB"}
|
package/dist/esm/index.js
CHANGED
|
@@ -270,7 +270,7 @@ const ModalSubmitInteractionData = {
|
|
|
270
270
|
};
|
|
271
271
|
|
|
272
272
|
//#endregion
|
|
273
|
-
//#region \0@oxc-project+runtime@0.
|
|
273
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/typeof.js
|
|
274
274
|
function _typeof(o) {
|
|
275
275
|
"@babel/helpers - typeof";
|
|
276
276
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -281,7 +281,7 @@ function _typeof(o) {
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
//#endregion
|
|
284
|
-
//#region \0@oxc-project+runtime@0.
|
|
284
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPrimitive.js
|
|
285
285
|
function toPrimitive(t, r) {
|
|
286
286
|
if ("object" != _typeof(t) || !t) return t;
|
|
287
287
|
var e = t[Symbol.toPrimitive];
|
|
@@ -294,14 +294,14 @@ function toPrimitive(t, r) {
|
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
//#endregion
|
|
297
|
-
//#region \0@oxc-project+runtime@0.
|
|
297
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/toPropertyKey.js
|
|
298
298
|
function toPropertyKey(t) {
|
|
299
299
|
var i = toPrimitive(t, "string");
|
|
300
300
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
//#endregion
|
|
304
|
-
//#region \0@oxc-project+runtime@0.
|
|
304
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/defineProperty.js
|
|
305
305
|
function _defineProperty(e, r, t) {
|
|
306
306
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
307
307
|
value: t,
|
|
@@ -312,26 +312,26 @@ function _defineProperty(e, r, t) {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
//#endregion
|
|
315
|
-
//#region \0@oxc-project+runtime@0.
|
|
315
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/checkPrivateRedeclaration.js
|
|
316
316
|
function _checkPrivateRedeclaration(e, t) {
|
|
317
317
|
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
//#endregion
|
|
321
|
-
//#region \0@oxc-project+runtime@0.
|
|
321
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/classPrivateFieldInitSpec.js
|
|
322
322
|
function _classPrivateFieldInitSpec(e, t, a) {
|
|
323
323
|
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
324
324
|
}
|
|
325
325
|
|
|
326
326
|
//#endregion
|
|
327
|
-
//#region \0@oxc-project+runtime@0.
|
|
327
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/assertClassBrand.js
|
|
328
328
|
function _assertClassBrand(e, t, n) {
|
|
329
329
|
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
330
330
|
throw new TypeError("Private element is not present on this object");
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
//#endregion
|
|
334
|
-
//#region \0@oxc-project+runtime@0.
|
|
334
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/classPrivateFieldGet2.js
|
|
335
335
|
function _classPrivateFieldGet2(s, a) {
|
|
336
336
|
return s.get(_assertClassBrand(s, a));
|
|
337
337
|
}
|
|
@@ -370,7 +370,7 @@ function makeResponse() {
|
|
|
370
370
|
}
|
|
371
371
|
|
|
372
372
|
//#endregion
|
|
373
|
-
//#region \0@oxc-project+runtime@0.
|
|
373
|
+
//#region \0@oxc-project+runtime@0.142.0/helpers/esm/classPrivateFieldSet2.js
|
|
374
374
|
function _classPrivateFieldSet2(s, a, r) {
|
|
375
375
|
return s.set(_assertClassBrand(s, a), r), r;
|
|
376
376
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-EeGiyIko.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";UAAiB
|
|
1
|
+
{"version":3,"file":"types-EeGiyIko.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";UAAiB;EAChB;EACA;EACA,KAAK,gBAAgB"}
|
package/dist/esm/vitest.d.ts
CHANGED
package/dist/esm/vitest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest.d.ts","names":[],"sources":["../../src/vitest.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"vitest.d.ts","names":[],"sources":["../../src/vitest.ts"],"mappings":";;UAGiB,sBAAsB;EACtC,aAAa,mBAAmB;EAChC,WAAW,mBAAmB;EAC9B,eAAe,oBAAoB;;;YAKzB,UAAU,iBAAiB,sBAAsB;YACjD,qCAAqC;;cA2BnC;EACW,aAAA,uBAAA,cAAA,UAAA,mBAAiB;;;;EAOnB,WAAA,uBAAA,cAAA,UAAA,mBAAiB;;;;EAOb,eAAA,uBAAA,cAAA,UAAA,mBAAiB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wolfstar/http-framework-test-utils",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Test utilities for @wolfstar/http-framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"discord",
|
|
@@ -51,14 +51,14 @@
|
|
|
51
51
|
"@sapphire/pieces": "^4.4.1",
|
|
52
52
|
"@sapphire/utilities": "^3.18.2",
|
|
53
53
|
"discord-api-types": "^0.38.8",
|
|
54
|
-
"tsdown": "^0.22.
|
|
54
|
+
"tsdown": "^0.22.14",
|
|
55
55
|
"typescript": "~5.8.3",
|
|
56
56
|
"vitest": "^4.1.9",
|
|
57
|
-
"@wolfstar/http-framework": "3.
|
|
57
|
+
"@wolfstar/http-framework": "3.1.1"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
|
-
"vitest": ">=4.
|
|
61
|
-
"@wolfstar/http-framework": "^3.
|
|
60
|
+
"vitest": ">=4.1.9",
|
|
61
|
+
"@wolfstar/http-framework": "^3.1.1"
|
|
62
62
|
},
|
|
63
63
|
"peerDependenciesMeta": {
|
|
64
64
|
"vitest": {
|