Skip to content

Commit

Permalink
Merge pull request #78 from GuoXiCheng/dev-h
Browse files Browse the repository at this point in the history
update
  • Loading branch information
GuoXiCheng authored Jan 11, 2024
2 parents de51b7c + 3fed597 commit 2a7d8c2
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
20 changes: 0 additions & 20 deletions jest.config.fake.js

This file was deleted.

12 changes: 12 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -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: ["<rootDir>/src/__tests__/fake/*.test.ts"],
testPathIgnorePatterns: []
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 0 additions & 37 deletions src/__tests__/fake-authenticate-gitee.test.ts

This file was deleted.

73 changes: 73 additions & 0 deletions src/__tests__/fake/authenticate-gitee.test.ts
Original file line number Diff line number Diff line change
@@ -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
});
});
});
36 changes: 2 additions & 34 deletions src/__tests__/helper/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -58,7 +27,6 @@ export const giteeRequest = createRequest({
httpLib: 'axios',
httpClient: axios,

baseURL: undefined,
accessToken: process.env.TEST_GITEE_TOKEN as string,

platform: 'gitee',
Expand Down

0 comments on commit 2a7d8c2

Please sign in to comment.