diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 330c29e2..0447b541 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ name: Test - opened - synchronize jobs: - test: + test_matrix: runs-on: ubuntu-latest strategy: matrix: @@ -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 diff --git a/package.json b/package.json index eab73abb..a21c46db 100644 --- a/package.json +++ b/package.json @@ -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)", diff --git a/test/typescript-validate.ts b/test/typescript-validate.ts new file mode 100644 index 00000000..2051c4a6 --- /dev/null +++ b/test/typescript-validate.ts @@ -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: () => {}, + }, +});