Skip to content

Commit 0d280e7

Browse files
committed
feat: remove read env
1 parent 1067878 commit 0d280e7

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

.github/workflows/fastgpt-test.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: 'FastGPT-Test'
22
on:
33
pull_request:
4+
workflow_dispatch:
45

56
jobs:
67
test:
@@ -20,7 +21,7 @@ jobs:
2021
- name: 'Install Deps'
2122
run: pnpm install
2223
- name: 'Test'
23-
run: pnpm run test:all
24+
run: pnpm run test
2425
- name: 'Report Coverage'
2526
# Set if: always() to also generate the report if tests are failing
2627
# Only works if you set `reportOnFailure: true` in your vite config as specified above

test/setup.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { readFileSync } from 'fs';
1+
import { existsSync, readFileSync } from 'fs';
22
import mongoose from '@fastgpt/service/common/mongo';
33
import { connectMongo } from '@fastgpt/service/common/mongo/init';
44
import { initGlobalVariables } from '@/service/common/system';
@@ -66,19 +66,21 @@ beforeAll(async () => {
6666
await connectMongo();
6767

6868
// await getInitConfig();
69-
const str = readFileSync('projects/app/.env.local', 'utf-8');
70-
const lines = str.split('\n');
71-
const systemEnv: Record<string, string> = {};
72-
for (const line of lines) {
73-
const [key, value] = line.split('=');
74-
if (key && value && !key.startsWith('#')) {
75-
systemEnv[key] = value;
76-
vi.stubEnv(key, value);
69+
if (existsSync('projects/app/.env.local')) {
70+
const str = readFileSync('projects/app/.env.local', 'utf-8');
71+
const lines = str.split('\n');
72+
const systemEnv: Record<string, string> = {};
73+
for (const line of lines) {
74+
const [key, value] = line.split('=');
75+
if (key && value && !key.startsWith('#')) {
76+
systemEnv[key] = value;
77+
vi.stubEnv(key, value);
78+
}
7779
}
80+
systemEnv.oneapiUrl = systemEnv['ONEAPI_URL'];
81+
global.systemEnv = systemEnv as any;
82+
await setupModels();
7883
}
79-
systemEnv.oneapiUrl = systemEnv['ONEAPI_URL'];
80-
global.systemEnv = systemEnv as any;
81-
await setupModels();
8284
});
8385

8486
afterAll(async () => {

vitest.config.mts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ export default defineConfig({
55
coverage: {
66
enabled: true,
77
reporter: ['text', 'json', 'html'],
8-
all: false
8+
all: false,
9+
reportOnFailure: true
910
},
1011
outputFile: 'test-results.json',
1112
setupFiles: ['./test/setup.ts'],

0 commit comments

Comments
 (0)