Skip to content

Commit

Permalink
test(types): add TS validation to assure types are properly configured
Browse files Browse the repository at this point in the history
  • Loading branch information
oscard0m committed Mar 12, 2022
1 parent 5ccd50f commit 0011470
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ name: Test
- opened
- synchronize
jobs:
test:
test_matrix:
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -26,3 +26,14 @@ jobs:
node-version: 16
- run: npm ci
- run: npm run test
test:
runs-on: ubuntu-latest
needs: test_matrix
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
cache: npm
node-version: 16
- run: npm ci
- run: npm run validate:ts
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"test": "jest --coverage",
"update-endpoints": "npm-run-all update-endpoints:*",
"update-endpoints:fetch-json": "node scripts/update-endpoints/fetch-json",
"update-endpoints:code": "node scripts/update-endpoints/code"
"update-endpoints:code": "node scripts/update-endpoints/code",
"validate:ts": "tsc --noEmit --noImplicitAny --target es2020 --esModuleInterop --moduleResolution node test/typescript-validate.ts"
},
"repository": "github:octokit/plugin-throttling.js",
"author": "Simon Grondin (http://github.com/SGrondin)",
Expand Down
51 changes: 51 additions & 0 deletions test/typescript-validate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Octokit } from "@octokit/core";
import { throttling } from "../src/index";
// ************************************************************
// THIS CODE IS NOT EXECUTED. IT IS FOR TYPECHECKING ONLY
// ************************************************************

const octokit = new Octokit();

// will be deprecated soon
// onAbuseLimit()
throttling(octokit, {
throttle: { enabled: true, onRateLimit: () => {}, onAbuseLimit: () => {} },
});

// onSecondaryLimit()
throttling(octokit, {
throttle: {
enabled: true,
onRateLimit: () => {},
onSecondaryRateLimit: () => {},
},
});

// onSecondaryLimit() and onAbuseLimit() should be a TS Error
// @ts-expect-error
throttling(octokit, {
throttle: {
enabled: true,
onRateLimit: () => {},
onSecondaryRateLimit: () => {},
onAbuseLimit: () => {},
},
});

// onRateLimit() missing should be a TS Error
// @ts-expect-error
throttling(octokit, {
throttle: {
enabled: true,
onSecondaryRateLimit: () => {},
},
});

// onSecondaryLimit() and onAbuseLimit() missing should be a TS Error
throttling(octokit, {
// @ts-expect-error
throttle: {
enabled: true,
onRateLimit: () => {},
},
});

0 comments on commit 0011470

Please sign in to comment.