Skip to content

Commit

Permalink
Add tests (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
G4brym authored Jun 6, 2023
2 parents 50b9ec8 + 2d74306 commit cee9416
Show file tree
Hide file tree
Showing 11 changed files with 3,125 additions and 1,673 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
. "$(dirname "$0")/common.sh"

npm run prettify
#npm run test
npm run test
18 changes: 18 additions & 0 deletions jestconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
},
"testRegex": "/tests/.*\\.test\\.ts$",
"collectCoverageFrom": ["src/**/*.{ts,js}"],
"coverageThreshold": {
"global": {
"branches": 45,
"functions": 70,
"lines": 70,
"statements": 70
}
},
"moduleNameMapper": {
"^_/(.*)$": "<rootDir>/src/$1"
}
}
4,262 changes: 2,599 additions & 1,663 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
"postpublish": "pinst --enable",
"build": "rollup -c",
"package": "npm run build && npm pack",
"test": "jest --no-cache --runInBand",
"test:cov": "jest --coverage --no-cache --runInBand",
"addscope": "node tools/packagejson name @cloudflare/itty-router-openapi",
"prettify": "prettier . --write --ignore-unknown",
"prettify": "prettier --check '*.{json,js,md,ts,mjs}' 'src/**/*.{js,ts}' 'tests/**/*.{js,ts}' || (prettier -w '*.{json,js}' 'src/**/*.{js,ts}' 'tests/**/*.{js,ts}'; exit 1)",
"lint": "npm run prettify",
"prepare": "husky install"
"prepare": "husky install",
"test": "jest --no-cache --runInBand --config jestconfig.json --verbose",
"coverage": "jest --no-cache --runInBand --config jestconfig.json --verbose --coverage"
},
"publishConfig": {
"access": "public"
Expand Down Expand Up @@ -69,19 +70,20 @@
"@commitlint/config-conventional": "^13.1.0",
"@rollup/plugin-terser": "^0.2.1",
"@rollup/plugin-typescript": "^10.0.1",
"@types/jest": "^27.0.1",
"@types/jest": "^29.0.0",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"husky": "^7.0.2",
"jest": "^28.1.2",
"jest": "^29.0.0",
"jest-openapi": "^0.14.2",
"pinst": "^2.1.6",
"prettier": "^2.4.0",
"rollup": "^3.8.1",
"rollup-plugin-bundle-size": "^1.0.3",
"ts-jest": "^28.0.5",
"ts-jest": "^29.0.0",
"typescript": "^4.8.4"
},
"dependencies": {
Expand Down
3 changes: 3 additions & 0 deletions src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export function OpenAPIRouter(options?: RouterOptions): OpenAPIRouterSchema {
paths: OpenAPIPaths,
}

// Quick fix, to make api spec valid
delete schema.raiseUnknownParameters

// @ts-ignore
const routerProxy: OpenAPIRouter = new Proxy(router, {
get: (target, prop, receiver) => {
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type OpenAPIRouterSchema = {
routes: RouteEntry[]
handle: (request: RequestLike, ...extra: any) => Promise<any>
original: RouterType
schema: any
} & {
[any: string]: ClassRoute
} & {
Expand Down
8 changes: 8 additions & 0 deletions tests/integration/openapi.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { todoRouter } from '../router'
import jestOpenAPI from 'jest-openapi'

describe('openapiValidation', () => {
it('loadSpec', async () => {
jestOpenAPI(todoRouter.schema)
})
})
Loading

0 comments on commit cee9416

Please sign in to comment.