Skip to content

Commit 9b89fbf

Browse files
authored
[add] Test framework based on ts-jest (#18)
1 parent 5ba7797 commit 9b89fbf

File tree

16 files changed

+2369
-470
lines changed

16 files changed

+2369
-470
lines changed

.github/workflows/publish-type.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
cache: pnpm
2323
- name: Install, Build & Publish
2424
run: |
25-
pnpm i && pnpm build
25+
pnpm i && npm test
2626
cd type/
2727
npm publish
2828
env:

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
npm test
1+
npm run lint

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
npm run build
1+
npm test

ReadMe.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@
1717
4. ORM framework: [TypeORM][12]
1818
5. API document: [Swagger][13]
1919
6. Mock API: [OpenAPI backend][14]
20+
7. Test framework: [Jest][15]
2021

2122
## Major features
2223

2324
1. [API entry & Health checking](source/controller/Base.ts)
2425
2. User management
2526
1. [Session](source/controller/User.ts)
2627
2. [OAuth sign in](source/controller/OAuth.ts)
27-
- recommend to use with [Next SSR middleware][15]
28-
3. [Platform Admin](source/controller/Admin.ts)
28+
- recommend to use with [Next SSR middleware][16]
29+
3. [Platform Admin](source/controller/PlatformAdmin.ts)
2930
3. [Activity logging](source/controller/ActivityLog.ts)
3031
4. Hackathon management
3132
1. [Meta](source/controller/Hackathon.ts)
@@ -45,18 +46,18 @@
4546

4647
1. Install GitHub apps in your organization or account:
4748

48-
1. [Probot settings][16]: set up Issue labels & Pull Request rules
49-
2. [PR badge][17]: set up Online [VS Code][18] editor entries in Pull Request description
49+
1. [Probot settings][17]: set up Issue labels & Pull Request rules
50+
2. [PR badge][18]: set up Online [VS Code][19] editor entries in Pull Request description
5051

51-
2. Click the **[<kbd>Use this template</kbd>][19] button** on the top of this GitHub repository's home page, then create your own repository in the app-installed namespace above
52+
2. Click the **[<kbd>Use this template</kbd>][20] button** on the top of this GitHub repository's home page, then create your own repository in the app-installed namespace above
5253

5354
3. Click the **[<kbd>Open in GitHub codespaces</kbd>][8] button** on the top of ReadMe file, then an **online VS Code development environment** will be started immediately
5455

55-
4. Recommend to add a [Notification step in GitHub actions][20] for your Team IM app
56+
4. Recommend to add a [Notification step in GitHub actions][21] for your Team IM app
5657

57-
5. Remind the PMs & users of your product to submit **Feature/Enhancement** requests or **Bug** reports with [Issue forms][21] instead of IM messages or Mobile Phone calls
58+
5. Remind the PMs & users of your product to submit **Feature/Enhancement** requests or **Bug** reports with [Issue forms][22] instead of IM messages or Mobile Phone calls
5859

59-
6. Collect all these issues into [Project kanbans][22], then create **Pull requests** & add `closes #issue_number` into its description for automation
60+
6. Collect all these issues into [Project kanbans][23], then create **Pull requests** & add `closes #issue_number` into its description for automation
6061

6162
## API Usage
6263

@@ -87,7 +88,7 @@ pnpm i
8788
pnpm dev
8889
```
8990

90-
or just press <kbd>F5</kbd> key in [VS Code][18].
91+
or just press <kbd>F5</kbd> key in [VS Code][19].
9192

9293
### Migration
9394

@@ -148,11 +149,12 @@ git push origin master --tags
148149
[12]: https://typeorm.io/
149150
[13]: https://swagger.io/
150151
[14]: https://github.com/anttiviljami/openapi-backend
151-
[15]: https://github.com/kaiyuanshe/Next-SSR-middleware
152-
[16]: https://github.com/apps/settings
153-
[17]: https://pullrequestbadge.com/
154-
[18]: https://code.visualstudio.com/
155-
[19]: https://github.com/new?template_name=openhackathon-service&template_owner=kaiyuanshe
156-
[20]: https://github.com/kaiyuanshe/kaiyuanshe.github.io/blob/bb4675a56bf1d6b207231313da5ed0af7cf0ebd6/.github/workflows/pull-request.yml#L32-L56
157-
[21]: https://github.com/kaiyuanshe/OpenHackathon-service/issues/new/choose
158-
[22]: https://github.com/kaiyuanshe/OpenHackathon-service/projects
152+
[15]: https://jestjs.io/
153+
[16]: https://github.com/kaiyuanshe/Next-SSR-middleware
154+
[17]: https://github.com/apps/settings
155+
[18]: https://pullrequestbadge.com/
156+
[19]: https://code.visualstudio.com/
157+
[20]: https://github.com/new?template_name=openhackathon-service&template_owner=kaiyuanshe
158+
[21]: https://github.com/kaiyuanshe/kaiyuanshe.github.io/blob/bb4675a56bf1d6b207231313da5ed0af7cf0ebd6/.github/workflows/pull-request.yml#L32-L56
159+
[22]: https://github.com/kaiyuanshe/OpenHackathon-service/issues/new/choose
160+
[23]: https://github.com/kaiyuanshe/OpenHackathon-service/projects

package.json

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,44 @@
2525
"koa-mount": "^4.0.0",
2626
"koa2-swagger-ui": "^5.10.0",
2727
"koagger": "^0.3.0",
28-
"marked": "^14.1.0",
29-
"mobx-github": "^0.3.2",
30-
"mobx-restful": "^0.7.0-rc.0",
28+
"marked": "^14.1.1",
29+
"mobx-github": "^0.3.4",
30+
"mobx-restful": "^1.0.1",
3131
"pg": "^8.12.0",
3232
"pg-connection-string": "^2.6.4",
3333
"reflect-metadata": "^0.2.2",
3434
"routing-controllers": "^0.10.4",
3535
"routing-controllers-openapi": "^4.0.0",
3636
"tslib": "^2.7.0",
3737
"typeorm": "npm:@helveg/typeorm@^0.3.20",
38+
"undici": "^6.19.8",
3839
"web-utility": "^4.4.0"
3940
},
4041
"devDependencies": {
42+
"@types/jest": "^29.5.12",
4143
"@types/jsonwebtoken": "^9.0.6",
4244
"@types/koa": "^2.15.0",
4345
"@types/koa-logger": "^3.1.5",
44-
"@types/node": "^20.16.2",
45-
"@typescript-eslint/eslint-plugin": "^8.3.0",
46-
"@typescript-eslint/parser": "^8.3.0",
46+
"@types/node": "^20.16.5",
47+
"@typescript-eslint/eslint-plugin": "^8.4.0",
48+
"@typescript-eslint/parser": "^8.4.0",
4749
"eslint": "^8.57.0",
4850
"eslint-plugin-simple-import-sort": "^12.1.1",
4951
"get-git-folder": "^0.1.2",
5052
"husky": "^9.1.5",
51-
"lint-staged": "^15.2.9",
53+
"jest": "^29.7.0",
54+
"koajax": "^3.0.2",
55+
"lint-staged": "^15.2.10",
5256
"prettier": "^3.3.3",
5357
"sqlite3": "^5.1.7",
54-
"ts-node-dev": "^2.0.0",
58+
"start-server-and-test": "^2.0.5",
59+
"ts-jest": "^29.2.5",
60+
"ts-node": "^10.9.2",
5561
"typescript": "~5.5.4"
5662
},
63+
"resolutions": {
64+
"native-file-system-adapter": "npm:@tech_query/native-file-system-adapter@^3.0.1"
65+
},
5766
"prettier": {
5867
"singleQuote": true,
5968
"trailingComma": "none",
@@ -63,11 +72,17 @@
6372
"lint-staged": {
6473
"*.{md,json,yml,ts}": "prettier --write"
6574
},
75+
"jest": {
76+
"preset": "ts-jest"
77+
},
6678
"scripts": {
6779
"prepare": "husky || true",
6880
"install": "get-git-folder https://github.com/kaiyuanshe/service-configuration main OpenHackathon-Web || true",
69-
"dev": "ts-node-dev source/",
70-
"test": "lint-staged",
81+
"dev": "cross-env TS_NODE_TRANSPILE_ONLY=true node -r ts-node/register --watch source/",
82+
"lint": "lint-staged",
83+
"start-test": "rm -rf .data/ && node dist/",
84+
"jest": "jest",
85+
"test": "npm run build && server-test start-test 8080 jest",
7186
"build": "rm -rf dist/ type/*.d.ts && tsc && mv dist/model/*.d.ts type/",
7287
"start": "cross-env NODE_ENV=production node dist/",
7388
"typeorm": "typeorm-ts-node-commonjs -d source/model/index.ts",

0 commit comments

Comments
 (0)