-
-
Notifications
You must be signed in to change notification settings - Fork 56
Run dedicated typescript types tests using tsd #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jankapunkt
wants to merge
4
commits into
master
Choose a base branch
from
tests/typescript-checks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
30706d8
tests(typescript): run dedicated typescript types tests using tsd
jankapunkt 2fce789
tests(types): added tests for Response and Errors
jankapunkt 88d5a8c
Merge branch 'master' of github.com:node-oauth/node-oauth2-server int…
jankapunkt 968b761
Merge branch 'master' into tests/typescript-checks
jankapunkt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| import {expectType} from 'tsd'; | ||
| import express from 'express' | ||
| import { | ||
| OAuth2Server, | ||
| OAuthError, | ||
| Request, | ||
| Response, | ||
| AccessDeniedError, | ||
| InsufficientScopeError, | ||
| InvalidArgumentError, | ||
| InvalidClientError, | ||
| InvalidGrantError, | ||
| InvalidRequestError, | ||
| InvalidScopeError, | ||
| InvalidTokenError, | ||
| ServerError, | ||
| UnauthorizedClientError, | ||
| UnauthorizedRequestError, | ||
| UnsupportedGrantTypeError, | ||
| UnsupportedResponseTypeError | ||
| } from '.'; | ||
| import {Request as UndiciRequest, Response as UndiciResponse} from 'undici'; | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
| // REQUEST | ||
| // ---------------------------------------------------------------------------- | ||
| function testRequest(req: Request): void { | ||
| expectType<string>(req.method); | ||
| expectType<Record<string, string>>(req.headers); | ||
| expectType<Record<string, string>>(req.query); | ||
| expectType<any>(req.body); | ||
| } | ||
|
|
||
| const args = [ | ||
| undefined, | ||
| {}, | ||
| {method: 'get'}, | ||
| {method: 'get', headers: {x: 'y'}}, | ||
| {method: 'get', query: {moo: 'foo'}}, | ||
| {method: 'get', headers: {x: 'y'}, query: {moo: 'foo'}}, | ||
| {method: 'get', headers: {x: 'y'}, query: {moo: 'foo', bar: 'baz'}}, | ||
| // check for express request compatibility | ||
| new express.Request({ | ||
| method: 'get', | ||
| query: {moo: 'foo'}, | ||
| headers: {x: 'y'} | ||
| }), | ||
| // check for compatibility with fetch api Request | ||
| // we use undici Request as a stand-in for fetch api Request | ||
| // because we still support older versions of Node.js | ||
| new UndiciRequest( | ||
| 'https://example.com?moo=foo%2Cbar', | ||
| { | ||
| method: 'get', headers: {x: 'y'} | ||
| }) | ||
| ]; | ||
|
|
||
| for (const arg of args) { | ||
| testRequest(new Request(arg)); | ||
| } | ||
|
|
||
|
|
||
| // ---------------------------------------------------------------------------- | ||
| // RESPONSE | ||
| // ---------------------------------------------------------------------------- | ||
| function testResponse(res: Response): void { | ||
| expectType<number>(res.status); | ||
| expectType<Record<string, string>>(res.headers); | ||
| expectType<any>(res.body); | ||
| } | ||
|
|
||
| const resArgs = [ | ||
| undefined, | ||
| {}, | ||
| {status: 200}, | ||
| {status: 200, headers: {x: 'y'}}, | ||
| {status: 200, body: 'foo'}, | ||
| {status: 200, headers: {x: 'y'}, body: 'foo'}, | ||
| {status: 200, headers: {x: 'y'}, body: 'foo', statusText: 'OK'}, | ||
| // check for express response compatibility | ||
| new express.Response({ | ||
| status: 200, | ||
| headers: {x: 'y'}, | ||
| body: 'foo' | ||
| }), | ||
| // check for compatibility with fetch api Response | ||
| // we use undici Response as a stand-in for fetch api Response | ||
| // because we still support older versions of Node.js | ||
| new UndiciResponse( | ||
| 'foo', | ||
| { | ||
| status: 200, | ||
| headers: {x: 'y'}, | ||
| statusText: 'OK' | ||
| }) | ||
| ]; | ||
|
|
||
| for (const arg of resArgs) { | ||
| testResponse(new Response(arg)); | ||
| } | ||
|
|
||
| // ---------------------------------------------------------------------------- | ||
| // ERRORS | ||
| // ---------------------------------------------------------------------------- | ||
| function testError(err: OAuthError): void { | ||
| expectType<string>(err.name); | ||
| expectType<string>(err.message); | ||
| expectType<number>(err.code); | ||
| } | ||
|
|
||
| const errorTypes = [ | ||
| AccessDeniedError, | ||
| InsufficientScopeError, | ||
| InvalidArgumentError, | ||
| InvalidClientError, | ||
| InvalidGrantError, | ||
| InvalidRequestError, | ||
| InvalidScopeError, | ||
| InvalidTokenError, | ||
| ServerError, | ||
| UnauthorizedClientError, | ||
| UnauthorizedRequestError, | ||
| UnsupportedGrantTypeError, | ||
| UnsupportedResponseTypeError | ||
| ]; | ||
|
|
||
| const errorArgs = [ | ||
| undefined, | ||
| {}, | ||
| {message: 'foo'}, | ||
| {message: 'foo', code: 400}, | ||
| {message: 'foo', code: 400, data: {bar: 'baz'}}, | ||
| // check for express error compatibility | ||
| new express.Error('foo'), | ||
| // native error compatibility | ||
| new Error('foo') | ||
| ]; | ||
|
|
||
| for (const arg of errorArgs) { | ||
| for (const ErrorType of errorTypes) { | ||
| testError(new ErrorType(arg)); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.