Skip to content

Commit 65fe5f1

Browse files
authored
Merge pull request #161 from dmanto/remove-tap-dev-dep
define and use new TapTestLike local dependence
2 parents c3322f1 + b47b0d0 commit 65fe5f1

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

src/types.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@ import type {Agent} from 'node:http';
77
import type {Readable, Stream} from 'node:stream';
88
import type {URL} from 'node:url';
99
import type {InspectOptions} from 'node:util';
10-
import type {Test} from 'tap';
1110
import type {CookieJar} from 'tough-cookie';
1211

12+
export interface TestContext {
13+
equal(actual: any, expected: any, message?: string): void;
14+
not(actual: any, expected: any, message?: string): void;
15+
notMatch(actual: any, pattern: RegExp, message?: string): void;
16+
match(actual: any, pattern: RegExp, message?: string): void;
17+
same(actual: any, expected: any, message?: string): void;
18+
plan(count: number): void;
19+
skip(message: string): void;
20+
todo(message: string): void;
21+
ok(value: any, message?: string): void;
22+
end(): void;
23+
24+
beforeEach(callback: (t: TestContext) => Promise<void>): void;
25+
afterEach(callback: () => Promise<void>): void;
26+
}
27+
1328
export type {JSONValue} from '@mojojs/util';
1429

1530
export interface JSONSchema {
@@ -221,7 +236,7 @@ export interface UserAgentWebSocketOptions extends SharedUserAgentRequestOptions
221236

222237
export type URLTarget = string | [string, MojoURLOptions];
223238

224-
export type TestUserAgentOptions = UserAgentOptions & {tap?: Test};
239+
export type TestUserAgentOptions = UserAgentOptions & {tap?: TestContext};
225240

226241
export interface ValidationError {
227242
instancePath: string;

src/user-agent/test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import type {App} from '../app.js';
33
import type {
44
JSONValue,
55
ServerOptions,
6+
TestContext,
67
TestUserAgentOptions,
78
UserAgentRequestOptions,
89
UserAgentWebSocketOptions
910
} from '../types.js';
1011
import type {WebSocket} from '../websocket.js';
1112
import type {URL} from 'node:url';
12-
import type {Test} from 'tap';
1313
import assert from 'node:assert/strict';
1414
import {on} from 'node:events';
1515
import {MockUserAgent} from './mock.js';
@@ -23,7 +23,7 @@ type SkipFunction = (...args: any[]) => any;
2323
// Helper function to add required `TestUserAgent` assert methods
2424
// that are missing in a `TAP` instance. This is as an intended side effect
2525
// to ensure compatibility with `TestUserAgent` class below
26-
function addNodeAssertMethods(tapInstance: Test): void {
26+
function addNodeAssertMethods(tapInstance: TestContext): void {
2727
(tapInstance as any).strictEqual = tapInstance.equal.bind(tapInstance);
2828
(tapInstance as any).notStrictEqual = tapInstance.not.bind(tapInstance);
2929
(tapInstance as any).doesNotMatch = tapInstance.notMatch.bind(tapInstance);
@@ -39,7 +39,7 @@ export class TestUserAgent extends MockUserAgent {
3939
*/
4040
body: Buffer = Buffer.from('');
4141

42-
_assert: typeof assert | Test | undefined = undefined;
42+
_assert: typeof assert | TestContext | undefined = undefined;
4343
_dom: DOM | undefined = undefined;
4444
_finished: [number, string] | null | undefined = undefined;
4545
_messages: AsyncIterableIterator<JSONValue> | undefined = undefined;
@@ -372,13 +372,13 @@ export class TestUserAgent extends MockUserAgent {
372372
return this._dom;
373373
}
374374

375-
_prepareTap(tap: Test): void {
375+
_prepareTap(tap: TestContext): void {
376376
addNodeAssertMethods(tap);
377377
this._assert = tap;
378378
const subtests = [tap];
379379
const assert = this._assert;
380380

381-
assert.beforeEach(async t => {
381+
assert.beforeEach(async (t: TestContext) => {
382382
addNodeAssertMethods(t);
383383
subtests.push(t);
384384
this._assert = t;

0 commit comments

Comments
 (0)