Skip to content

Commit 296739e

Browse files
authored
feat: 添加单元测试,基于vitest 改造了现有的测试。 (#385)
* test: add unit test and generate snapshot * fix: 生成的类型缺少namespace问题 * style: prefer type import * ci: add pr unit test and run unit test while releasing * docs: update test command * chore: add change set * test: 修改中文tag, 避免bing api 在单数复数中切换导致单元测试失败 * chore: updata changeset
1 parent 2ac8cf5 commit 296739e

File tree

85 files changed

+43218
-607
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+43218
-607
lines changed

.changeset/afraid-news-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': patch
3+
---
4+
5+
fix: refactor test cases to use vitest as testing framework

.changeset/eager-books-throw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': patch
3+
---
4+
5+
fix: 生成的类型缺少namespace问题

.changeset/sharp-bees-stay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': patch
3+
---
4+
5+
style: prefer type import

.eslintrc.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
'test',
1212
'*.cjs',
1313
'openapi-ts-request.config.ts',
14+
'vitest.config.ts',
1415
],
1516
plugins: [],
1617
parserOptions: {
@@ -21,5 +22,6 @@ module.exports = {
2122
rules: {
2223
'@typescript-eslint/ban-ts-comment': 'warn',
2324
'@typescript-eslint/no-explicit-any': 'off',
25+
'@typescript-eslint/consistent-type-imports': 'error',
2426
},
2527
};

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v4
13+
14+
- name: Install pnpm
15+
uses: pnpm/action-setup@v4
16+
17+
- name: Use node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '20.x'
21+
registry-url: 'https://registry.npmjs.org'
22+
cache: 'pnpm'
23+
24+
- name: Installing Dependencies
25+
run: pnpm install
26+
27+
- name: Running unit Test
28+
run: pnpm run test:unit

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ jobs:
3333
if: steps.cache-dependencies.outputs.cache-hit != 'true'
3434
run: pnpm install
3535

36-
- name: Running Test
37-
run: pnpm run test
36+
- name: Running unit Test
37+
run: pnpm run test:unit
3838

3939
- name: Running Build
4040
run: pnpm run build

.husky/pre-push

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# pnpm test
1+
# pnpm test:unit

README-en_US.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export default {
338338
1. learn [Pull Request]("https://help.github.com/articles/using-pull-requests") specification
339339
2. fork this repository
340340
3. create a new branch to modify the code:`git checkout -b my-branch main`
341-
4. make sure your code passes all test cases (new functional test cases need to be added for new features):`pnpm test`
341+
4. make sure your code passes all test cases (new functional test cases need to be added for new features):`pnpm test:unit`
342342
5. create a changeset file using the command:`pnpm changeset`
343343
6. submit your changes using commit (must follow commitlint specification)
344344
7. submit Pull Request

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ export default {
340340
1. 熟悉 [Pull Request]("https://help.github.com/articles/using-pull-requests") 规范
341341
2. fork 此仓库
342342
3. 开一个新分支修改代码:`git checkout -b my-branch main`
343-
4. 确保你的代码可以通过所有测试用例(新增功能需要添加新的功能测试用例):`pnpm test`
343+
4. 确保你的代码可以通过所有测试用例(新增功能需要添加新的功能测试用例):`pnpm test:unit`
344344
5. 创建 changeset 文件通过命令:`pnpm changeset`
345345
6. 使用 commit 提交你的修改(需遵循 commitlint 规范)
346346
7. 发起 Pull Request

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"changeset": "changeset",
3131
"lint": "eslint ./src --report-unused-disable-directives --max-warnings=0",
3232
"lint:fix": "eslint ./src --report-unused-disable-directives --max-warnings=0 --fix",
33+
"test:unit": "vitest",
3334
"test": "rm -rf ./test/apis/ ./test/mocks && npm run build && cd ./test && node ./test.js && cd ..",
3435
"test:new": "npm run build && cd ./test && node ./test.js && cd ..",
3536
"test:windows": "rimraf ./test/apis/ ./test/mocks && npm run build && cd ./test && node ./test.js && cd ..",
@@ -81,8 +82,10 @@
8182
"husky": "^9.0.11",
8283
"lint-staged": "^16.0.0",
8384
"openapi-types": "^12.1.3",
85+
"sanitize-filename": "^1.6.3",
8486
"ts-node": "^10.9.2",
85-
"typescript": "5.8.3"
87+
"typescript": "5.8.3",
88+
"vitest": "^3.2.4"
8689
},
8790
"keywords": [
8891
"openapi",

0 commit comments

Comments
 (0)