mirror of
https://github.com/lobehub/lobehub
synced 2026-04-21 17:47:27 +00:00
🔨 chore: improve test workflow (#8876)
* test workflow * test workflow * add test workflow * add test workflow * add test config * add test config * add test config * add test config * add test config * update * refactor tests * fix tests * fix tests * exclude packages * improve test * fix test * add a new package
This commit is contained in:
parent
499a9ca53e
commit
d07e2acae8
23 changed files with 148 additions and 37 deletions
88
.github/workflows/test.yml
vendored
88
.github/workflows/test.yml
vendored
|
|
@ -2,8 +2,82 @@ name: Test CI
|
|||
|
||||
on: [push, pull_request]
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
test:
|
||||
# Package tests - using each package's own test script
|
||||
test-packages:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
package: [file-loaders, prompts, model-runtime, web-crawler, electron-server-ipc]
|
||||
|
||||
name: Test package ${{ matrix.package }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- uses: pnpm/action-setup@v4
|
||||
|
||||
- name: Install bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
bun-version: ${{ secrets.BUN_VERSION }}
|
||||
|
||||
- name: Install deps
|
||||
run: bun i
|
||||
|
||||
- name: Test ${{ matrix.package }} package with coverage
|
||||
run: pnpm --filter @lobechat/${{ matrix.package }} test:coverage
|
||||
|
||||
- name: Upload ${{ matrix.package }} coverage to Codecov
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
files: ./packages/${{ matrix.package }}/coverage/lcov.info
|
||||
flags: packages/${{ matrix.package }}
|
||||
|
||||
# App tests
|
||||
test-website:
|
||||
name: Test Website
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- name: Install bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
with:
|
||||
bun-version: ${{ secrets.BUN_VERSION }}
|
||||
|
||||
- name: Install deps
|
||||
run: bun i
|
||||
|
||||
- name: Test App Coverage
|
||||
run: bun run test-app:coverage
|
||||
|
||||
- name: Upload App Coverage to Codecov
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
files: ./coverage/app/lcov.info
|
||||
flags: app
|
||||
|
||||
test-server:
|
||||
name: Test Database
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
services:
|
||||
|
|
@ -13,8 +87,6 @@ jobs:
|
|||
POSTGRES_PASSWORD: postgres
|
||||
options: >-
|
||||
--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
|
||||
|
||||
|
||||
ports:
|
||||
- 5432:5432
|
||||
|
||||
|
|
@ -53,13 +125,3 @@ jobs:
|
|||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
files: ./coverage/server/lcov.info
|
||||
flags: server
|
||||
|
||||
- name: Test App Coverage
|
||||
run: bun run test-app:coverage
|
||||
|
||||
- name: Upload App Coverage to Codecov
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
files: ./coverage/app/lcov.info
|
||||
flags: app
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@
|
|||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"scripts": {
|
||||
"test": "vitest"
|
||||
"test": "vitest",
|
||||
"test:coverage": "vitest --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": "^4.3.4"
|
||||
|
|
|
|||
10
packages/electron-server-ipc/vitest.config.ts
Normal file
10
packages/electron-server-ipc/vitest.config.ts
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
coverage: {
|
||||
all: false,
|
||||
},
|
||||
environment: 'node',
|
||||
},
|
||||
});
|
||||
|
|
@ -21,7 +21,8 @@
|
|||
"sideEffects": false,
|
||||
"main": "./src/index.ts",
|
||||
"scripts": {
|
||||
"test": "vitest"
|
||||
"test": "vitest",
|
||||
"test:coverage": "vitest --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@langchain/community": "^0.3.41",
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@
|
|||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"scripts": {
|
||||
"test": "vitest",
|
||||
"test:coverage": "vitest --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-bedrock-runtime": "^3.862.0",
|
||||
"@lobechat/types": "workspace:*",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// @vitest-environment node
|
||||
import { Mock } from 'vitest';
|
||||
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { LobeOpenAICompatibleRuntime, ModelProvider } from '@/libs/model-runtime';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// @vitest-environment node
|
||||
import { Mock, afterEach, beforeEach, expect, it, vi } from 'vitest';
|
||||
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { LobeOpenAICompatibleRuntime } from '@/libs/model-runtime';
|
||||
import { testProvider } from '@/libs/model-runtime/providerTestUtils';
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { OpenAI } from 'openai';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { imageUrlToBase64 } from '@/utils/imageToBase64';
|
||||
|
||||
|
|
|
|||
16
packages/model-runtime/vitest.config.ts
Normal file
16
packages/model-runtime/vitest.config.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import { resolve } from 'node:path';
|
||||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
alias: {
|
||||
/* eslint-disable sort-keys-fix/sort-keys-fix */
|
||||
'@/libs/model-runtime': resolve(__dirname, './src'),
|
||||
'@/types': resolve(__dirname, '../types/src'),
|
||||
'@/const': resolve(__dirname, '../const/src'),
|
||||
'@': resolve(__dirname, '../../src'),
|
||||
/* eslint-enable */
|
||||
},
|
||||
environment: 'happy-dom',
|
||||
},
|
||||
});
|
||||
|
|
@ -3,6 +3,10 @@
|
|||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"main": "./src/index.ts",
|
||||
"scripts": {
|
||||
"test": "vitest",
|
||||
"test:coverage": "vitest --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@lobechat/const": "workspace:*",
|
||||
"@lobechat/types": "workspace:*"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
import { Mock, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { globalHelpers } from '@/store/global/helpers';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { chainSummaryDescription } from '../summaryDescription';
|
||||
|
||||
|
|
@ -10,7 +8,7 @@ describe('chainSummaryDescription', () => {
|
|||
const expectedOutput = {
|
||||
messages: [
|
||||
{
|
||||
content: `你是一名擅长技能总结的助理,你需要将用户的输入的内容总结为一个角色技能简介,不超过 20 个字。内容需要确保信息清晰、逻辑清晰,并有效地传达角色的技能和经验,需要并翻译为目标语言:${globalHelpers.getCurrentLanguage()}。格式要求如下:\n输入: {文本作为JSON引用字符串} [locale]\n输出: {简介}`,
|
||||
content: `你是一名擅长技能总结的助理,你需要将用户的输入的内容总结为一个角色技能简介,不超过 20 个字。内容需要确保信息清晰、逻辑清晰,并有效地传达角色的技能和经验,需要并翻译为目标语言:en-US。格式要求如下:\n输入: {文本作为JSON引用字符串} [locale]\n输出: {简介}`,
|
||||
role: 'system',
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,17 +1,8 @@
|
|||
import { OpenAIChatMessage } from '@lobechat/types';
|
||||
import { Mock, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { chatHelpers } from '@/store/chat/helpers';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { chainSummaryTitle } from '../summaryTitle';
|
||||
|
||||
// Mock the chatHelpers.getMessagesTokenCount function
|
||||
vi.mock('@/store/chat/helpers', () => ({
|
||||
chatHelpers: {
|
||||
getMessagesTokenCount: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('chainSummaryTitle', () => {
|
||||
it('should use the default model if the token count is below the GPT-3.5 limit', async () => {
|
||||
// Arrange
|
||||
|
|
@ -21,7 +12,6 @@ describe('chainSummaryTitle', () => {
|
|||
];
|
||||
const currentLanguage = 'en-US';
|
||||
const tokenCount = 10000; // Arbitrary token count below the GPT-3.5 limit
|
||||
(chatHelpers.getMessagesTokenCount as Mock).mockResolvedValue(tokenCount);
|
||||
|
||||
// Act
|
||||
const result = await chainSummaryTitle(messages, currentLanguage);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { pluginPrompts } from './index';
|
||||
import { Tool } from './tools';
|
||||
|
||||
|
|
|
|||
7
packages/prompts/vitest.config.ts
Normal file
7
packages/prompts/vitest.config.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
environment: 'happy-dom',
|
||||
},
|
||||
});
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
export * from './artifact';
|
||||
export * from './chunk';
|
||||
export * from './clientDB';
|
||||
export * from './fetch';
|
||||
export * from './knowledgeBase';
|
||||
export * from './message';
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@
|
|||
"private": true,
|
||||
"main": "src/index.ts",
|
||||
"types": "src/index.ts",
|
||||
"scripts": {
|
||||
"test": "vitest",
|
||||
"test:coverage": "vitest --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mozilla/readability": "^0.6.0",
|
||||
"happy-dom": "^17.0.0",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { jina } from '../jina';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { NetworkConnectionError, PageNotFoundError, TimeoutError } from '../../utils/errorType';
|
||||
import * as withTimeoutModule from '../../utils/withTimeout';
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { TimeoutError } from '../errorType';
|
||||
import { DEFAULT_TIMEOUT, withTimeout } from '../withTimeout';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { applyUrlRules } from './appUrlRules';
|
||||
|
||||
describe('applyUrlRules', () => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { readFileSync } from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { expect } from 'vitest';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { FilterOptions } from '../type';
|
||||
import { htmlToMarkdown } from './htmlToMarkdown';
|
||||
|
|
|
|||
7
packages/web-crawler/vitest.config.ts
Normal file
7
packages/web-crawler/vitest.config.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
environment: 'node',
|
||||
},
|
||||
});
|
||||
|
|
@ -22,6 +22,7 @@ export default defineConfig({
|
|||
// https://github.com/lobehub/lobe-chat/pull/7265
|
||||
...coverageConfigDefaults.exclude,
|
||||
'__mocks__/**',
|
||||
'**/packages/**',
|
||||
// just ignore the migration code
|
||||
// we will use pglite in the future
|
||||
// so the coverage of this file is not important
|
||||
|
|
@ -38,6 +39,7 @@ export default defineConfig({
|
|||
'**/dist/**',
|
||||
'**/build/**',
|
||||
'**/apps/desktop/**',
|
||||
'**/packages/**',
|
||||
'src/database/server/**/**',
|
||||
'src/database/repositories/dataImporter/deprecated/**/**',
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in a new issue