Skip to content

Commit 30706d8

Browse files
committed
tests(typescript): run dedicated typescript types tests using tsd
1 parent 9ad4cd5 commit 30706d8

File tree

6 files changed

+3227
-78
lines changed

6 files changed

+3227
-78
lines changed

.github/workflows/tests.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,29 @@ jobs:
3030
cache: npm
3131
- run: npm clean-install
3232
- run: npm run lint
33+
types:
34+
name: Typescript types check
35+
needs: [lint]
36+
runs-on: ubuntu-latest
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v4
40+
with:
41+
persist-credentials: false
42+
show-progress: false
43+
44+
- name: setup node
45+
uses: actions/setup-node@v4
46+
with:
47+
node-version: 20
48+
cache: npm
49+
- run: npm clean-install
50+
- run: npm run test:types
3351

3452
unittest:
3553
name: unit tests
3654
runs-on: ubuntu-latest
37-
needs: [lint]
55+
needs: [types]
3856
strategy:
3957
matrix:
4058
node: [16, 18, 20, 22]

index.d.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ declare namespace OAuth2Server {
5959
* Instantiates Request using the supplied options.
6060
*
6161
*/
62-
constructor(options: {
63-
headers: Record<string, string>,
64-
method: string,
65-
query: Record<string, string>,
66-
body?: any
67-
} & Record<string, any> | http.IncomingMessage);
62+
constructor(options?: Record<string, any> | http.IncomingMessage);
6863

6964
/**
7065
* Returns the specified HTTP header field. The match is case-insensitive.

index.test-d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import {expectType} from 'tsd';
2+
import express from 'express'
3+
import {OAuth2Server, Request, Response} from '.';
4+
import { Request as UndiciRequest } from 'undici';
5+
6+
expectType<Request>(new Request());
7+
expectType<Request>(new Request({}));
8+
9+
const req1 = new Request({ method: 'get', headers: { x: 'y'} });
10+
expectType<string>(req1.method);
11+
expectType<Record<string, string>>(req1.headers);
12+
13+
// check for express request compatibility
14+
const expressReq = new express.Request({ method: 'get', query: { moo: 'foo' }, headers: { x: 'y'} });
15+
const req2 = new Request(expressReq);
16+
expectType<string>(req2.method);
17+
expectType<Record<string, string>>(req2.headers);
18+
expectType<Record<string, string>>(req2.query);
19+
20+
// check for compatibility with fetch api Request
21+
// we use undici Request as a stand-in for fetch api Request
22+
// because we still support older versions of Node.js
23+
const undiciReq = new UndiciRequest('https://example.com', { method: 'get', headers: { x: 'y'} });
24+
const req3 = new Request(undiciReq);
25+
expectType<string>(req3.method);
26+
expectType<Record<string, string>>(req3.headers);
27+
expectType<Record<string, string>>(req3.query);

0 commit comments

Comments
 (0)