diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d35964a..1cc092d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: run: npm install - name: Run Jest tests - run: npm run test:real + run: npm run test env: TEST_GITEE_TOKEN: ${{ secrets.TEST_GITEE_TOKEN }} TEST_GITEE_OWNER: ${{ secrets.TEST_GITEE_OWNER }} diff --git a/jest.config.fake.js b/jest.config.fake.js deleted file mode 100644 index 7f46d16..0000000 --- a/jest.config.fake.js +++ /dev/null @@ -1,20 +0,0 @@ -module.exports = { - testTimeout: 120000, - preset: 'ts-jest', - testEnvironment: 'node', - collectCoverageFrom: [ - "src/**/*.ts", // 包括 src 目录下所有的 TypeScript 文件 - "!src/**/*.d.ts", // 排除 TypeScript 声明文件 - "!src/__tests__/**/*.ts" - ], - testMatch: ["/src/__tests__/**/*.test.ts"], - testPathIgnorePatterns: [ - "src/__tests__/authenticate-gitee.test.ts", - "src/__tests__/authenticate-github.test.ts", - "src/__tests__/authenticate-gitlab.test.ts", - "src/__tests__/book-repository.test.ts", - "src/__tests__/chat-repository.test.ts", - "src/__tests__/user-repository.test.ts", - "src/__tests__/wx-request.test.ts" - ] -}; diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..77f8161 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,12 @@ +module.exports = { + testTimeout: 30000, + preset: 'ts-jest', + testEnvironment: 'node', + collectCoverageFrom: [ + "src/**/*.ts", // 包括 src 目录下所有的 TypeScript 文件 + "!src/**/*.d.ts", // 排除 TypeScript 声明文件 + "!src/__tests__/**/*.ts" + ], + testMatch: ["/src/__tests__/fake/*.test.ts"], + testPathIgnorePatterns: [] +}; diff --git a/package.json b/package.json index 3acc4a6..ce7bf7c 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "module": "dist/bundle.esm.js", "types": "dist/index.d.ts", "scripts": { - "test:fake": "jest --coverage --config=jest.config.fake.js", + "test": "jest --coverage", "test:real": "jest --coverage --config=jest.config.real.js", "prebuild": "rimraf ./dist", "build": "rollup --config" diff --git a/src/__tests__/fake-authenticate-gitee.test.ts b/src/__tests__/fake-authenticate-gitee.test.ts deleted file mode 100644 index 2f6c110..0000000 --- a/src/__tests__/fake-authenticate-gitee.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { giteeRequest } from './helper/helper'; -describe('Test Use Fake Authenticate Gitee', () => { - test('Test Authenticate Gitee', async () => { - const res = await giteeRequest.authenticate(); - expect(res).toEqual({ - id: 1000001, - login: '***', - name: '***', - avatar_url: 'https://foruda.gitee.com/avatar/***/***.png', - url: 'https://gitee.com/api/v5/users/***', - html_url: 'https://gitee.com/***', - remark: '', - followers_url: 'https://gitee.com/api/v5/users/***/followers', - following_url: 'https://gitee.com/api/v5/users/***/following_url{/other_user}', - gists_url: 'https://gitee.com/api/v5/users/***/gists{/gist_id}', - starred_url: 'https://gitee.com/api/v5/users/***/starred{/owner}{/repo}', - subscriptions_url: 'https://gitee.com/api/v5/users/***/subscriptions', - organizations_url: 'https://gitee.com/api/v5/users/***/orgs', - repos_url: 'https://gitee.com/api/v5/users/***/repos', - events_url: 'https://gitee.com/api/v5/users/***/events{/privacy}', - received_events_url: 'https://gitee.com/api/v5/users/***/received_events', - type: 'User', - blog: null, - weibo: null, - bio: '', - public_repos: 0, - public_gists: 0, - followers: 0, - following: 0, - stared: 0, - watched: 0, - created_at: '2020-02-26T13:20:27+08:00', - updated_at: '2024-01-10T22:27:59+08:00', - email: null - }); - }); -}); \ No newline at end of file diff --git a/src/__tests__/fake/authenticate-gitee.test.ts b/src/__tests__/fake/authenticate-gitee.test.ts new file mode 100644 index 0000000..0dae3fb --- /dev/null +++ b/src/__tests__/fake/authenticate-gitee.test.ts @@ -0,0 +1,73 @@ +import { giteeRequest, mock } from '../helper/helper'; + +describe('Test Use Fake Authenticate Gitee', () => { + beforeAll(() => { + mock.onGet('https://gitee.com/api/v5/user').reply(async () => { + return [200, { + "id": 1000001, + "login": "***", + "name": "***", + "avatar_url": "https://foruda.gitee.com/avatar/***/***.png", + "url": "https://gitee.com/api/v5/users/***", + "html_url": "https://gitee.com/***", + "remark": "", + "followers_url": "https://gitee.com/api/v5/users/***/followers", + "following_url": "https://gitee.com/api/v5/users/***/following_url{/other_user}", + "gists_url": "https://gitee.com/api/v5/users/***/gists{/gist_id}", + "starred_url": "https://gitee.com/api/v5/users/***/starred{/owner}{/repo}", + "subscriptions_url": "https://gitee.com/api/v5/users/***/subscriptions", + "organizations_url": "https://gitee.com/api/v5/users/***/orgs", + "repos_url": "https://gitee.com/api/v5/users/***/repos", + "events_url": "https://gitee.com/api/v5/users/***/events{/privacy}", + "received_events_url": "https://gitee.com/api/v5/users/***/received_events", + "type": "User", + "blog": null, + "weibo": null, + "bio": "", + "public_repos": 0, + "public_gists": 0, + "followers": 0, + "following": 0, + "stared": 0, + "watched": 0, + "created_at": "2020-02-26T13:20:27+08:00", + "updated_at": "2024-01-10T22:27:59+08:00", + "email": null + }]; + }); + }); + test('Test Authenticate Gitee', async () => { + const res = await giteeRequest.authenticate(); + expect(res).toEqual({ + id: 1000001, + login: '***', + name: '***', + avatar_url: 'https://foruda.gitee.com/avatar/***/***.png', + url: 'https://gitee.com/api/v5/users/***', + html_url: 'https://gitee.com/***', + remark: '', + followers_url: 'https://gitee.com/api/v5/users/***/followers', + following_url: 'https://gitee.com/api/v5/users/***/following_url{/other_user}', + gists_url: 'https://gitee.com/api/v5/users/***/gists{/gist_id}', + starred_url: 'https://gitee.com/api/v5/users/***/starred{/owner}{/repo}', + subscriptions_url: 'https://gitee.com/api/v5/users/***/subscriptions', + organizations_url: 'https://gitee.com/api/v5/users/***/orgs', + repos_url: 'https://gitee.com/api/v5/users/***/repos', + events_url: 'https://gitee.com/api/v5/users/***/events{/privacy}', + received_events_url: 'https://gitee.com/api/v5/users/***/received_events', + type: 'User', + blog: null, + weibo: null, + bio: '', + public_repos: 0, + public_gists: 0, + followers: 0, + following: 0, + stared: 0, + watched: 0, + created_at: '2020-02-26T13:20:27+08:00', + updated_at: '2024-01-10T22:27:59+08:00', + email: null + }); + }); +}); \ No newline at end of file diff --git a/src/__tests__/helper/helper.ts b/src/__tests__/helper/helper.ts index 082b05e..2d0195b 100644 --- a/src/__tests__/helper/helper.ts +++ b/src/__tests__/helper/helper.ts @@ -5,40 +5,9 @@ import { createRequest } from '../../request-lib'; import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; import timezone from 'dayjs/plugin/timezone'; +import MockAdapter from 'axios-mock-adapter'; -// const mock = new MockAdapter(axios); - -// mock.onGet('https://fake-gitee/api/v5/user').reply(200, { -// "id": 1000001, -// "login": "***", -// "name": "***", -// "avatar_url": "https://foruda.gitee.com/avatar/***/***.png", -// "url": "https://gitee.com/api/v5/users/***", -// "html_url": "https://gitee.com/***", -// "remark": "", -// "followers_url": "https://gitee.com/api/v5/users/***/followers", -// "following_url": "https://gitee.com/api/v5/users/***/following_url{/other_user}", -// "gists_url": "https://gitee.com/api/v5/users/***/gists{/gist_id}", -// "starred_url": "https://gitee.com/api/v5/users/***/starred{/owner}{/repo}", -// "subscriptions_url": "https://gitee.com/api/v5/users/***/subscriptions", -// "organizations_url": "https://gitee.com/api/v5/users/***/orgs", -// "repos_url": "https://gitee.com/api/v5/users/***/repos", -// "events_url": "https://gitee.com/api/v5/users/***/events{/privacy}", -// "received_events_url": "https://gitee.com/api/v5/users/***/received_events", -// "type": "User", -// "blog": null, -// "weibo": null, -// "bio": "", -// "public_repos": 0, -// "public_gists": 0, -// "followers": 0, -// "following": 0, -// "stared": 0, -// "watched": 0, -// "created_at": "2020-02-26T13:20:27+08:00", -// "updated_at": "2024-01-10T22:27:59+08:00", -// "email": null -// }); +export const mock = new MockAdapter(axios); dayjs.extend(utc); dayjs.extend(timezone); @@ -58,7 +27,6 @@ export const giteeRequest = createRequest({ httpLib: 'axios', httpClient: axios, - baseURL: undefined, accessToken: process.env.TEST_GITEE_TOKEN as string, platform: 'gitee',