Skip to content

Commit f64a5ca

Browse files
authored
add test (#6498)
1 parent 95f0166 commit f64a5ca

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

projects/sandbox/test/integration/functional.test.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface TestCase {
2121
codeReturnMatch?: Record<string, any>; // 部分匹配
2222
errorMatch?: RegExp; // 错误信息匹配
2323
hasLog?: boolean; // 是否有日志输出
24+
logMatch?: RegExp; // 日志内容匹配
2425
};
2526
}
2627

@@ -49,6 +50,9 @@ function runMatrix(getPool: () => ProcessPool | PythonProcessPool, cases: TestCa
4950
expect(result.data?.log).toBeTruthy();
5051
expect(result.data!.log!.length).toBeGreaterThan(0);
5152
}
53+
if (tc.expect.logMatch) {
54+
expect(result.data?.log).toMatch(tc.expect.logMatch);
55+
}
5256
});
5357
}
5458
}
@@ -195,15 +199,40 @@ describe('JS 功能测试', () => {
195199
);
196200
});
197201

198-
// --- console.log 日志 ---
202+
// --- console 日志 ---
199203
describe('日志输出', () => {
200204
runMatrix(
201205
() => pool,
202206
[
203207
{
204208
name: 'console.log 被捕获',
205209
code: `async function main() { console.log('debug info'); return { done: true }; }`,
206-
expect: { success: true, codeReturn: { done: true }, hasLog: true }
210+
expect: { success: true, codeReturn: { done: true }, logMatch: /debug info/ }
211+
},
212+
{
213+
name: 'console.error 不报错,内容被捕获',
214+
code: `async function main() { console.error('err msg'); return { done: true }; }`,
215+
expect: { success: true, codeReturn: { done: true }, logMatch: /err msg/ }
216+
},
217+
{
218+
name: 'console.warn 不报错,内容被捕获',
219+
code: `async function main() { console.warn('warn msg'); return { done: true }; }`,
220+
expect: { success: true, codeReturn: { done: true }, logMatch: /warn msg/ }
221+
},
222+
{
223+
name: 'console.info 不报错,内容被捕获',
224+
code: `async function main() { console.info('info msg'); return { done: true }; }`,
225+
expect: { success: true, codeReturn: { done: true }, logMatch: /info msg/ }
226+
},
227+
{
228+
name: 'console.debug 不报错,内容被捕获',
229+
code: `async function main() { console.debug('debug msg'); return { done: true }; }`,
230+
expect: { success: true, codeReturn: { done: true }, logMatch: /debug msg/ }
231+
},
232+
{
233+
name: '多次 console 调用均被捕获',
234+
code: `async function main() { console.log('a'); console.warn('b'); console.error('c'); return { done: true }; }`,
235+
expect: { success: true, codeReturn: { done: true }, logMatch: /a/ }
207236
}
208237
]
209238
);
@@ -602,6 +631,25 @@ describe('Python 功能测试', () => {
602631
);
603632
});
604633

634+
// --- print 日志 ---
635+
describe('日志输出', () => {
636+
runMatrix(
637+
() => pool,
638+
[
639+
{
640+
name: 'print 被捕获',
641+
code: `def main():\n print('hello log')\n return {'done': True}`,
642+
expect: { success: true, codeReturn: { done: true }, logMatch: /hello log/ }
643+
},
644+
{
645+
name: '多次 print 均被捕获',
646+
code: `def main():\n print('line1')\n print('line2')\n return {'done': True}`,
647+
expect: { success: true, logMatch: /line1/ }
648+
}
649+
]
650+
);
651+
});
652+
605653
// --- 错误处理 ---
606654
describe('错误处理', () => {
607655
runMatrix(

0 commit comments

Comments
 (0)