-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-utils.test.ts
More file actions
47 lines (40 loc) · 1.4 KB
/
Copy pathtest-utils.test.ts
File metadata and controls
47 lines (40 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { describe, expect, it, vi } from 'bun:test';
import { createMockLogCollector, createMockTrace } from '../test-utils';
describe('worker test utilities', () => {
it('only mirrors trace and log events to console when test diagnostics are enabled', async () => {
const previousDebugValue = process.env.SENTRIS_DEBUG_TESTS;
const logSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
try {
delete process.env.SENTRIS_DEBUG_TESTS;
createMockTrace().record({
type: 'NODE_STARTED',
nodeRef: 'node-1',
message: 'started',
});
await createMockLogCollector().append({
level: 'info',
message: 'hello',
});
expect(logSpy).not.toHaveBeenCalled();
process.env.SENTRIS_DEBUG_TESTS = '1';
createMockTrace().record({
type: 'NODE_COMPLETED',
nodeRef: 'node-2',
message: 'finished',
});
await createMockLogCollector().append({
level: 'warn',
message: 'careful',
});
expect(logSpy).toHaveBeenCalledWith('TRACE:', 'NODE_COMPLETED', 'node-2', 'finished');
expect(logSpy).toHaveBeenCalledWith('LOG:', 'warn', 'careful');
} finally {
logSpy.mockRestore();
if (previousDebugValue === undefined) {
delete process.env.SENTRIS_DEBUG_TESTS;
} else {
process.env.SENTRIS_DEBUG_TESTS = previousDebugValue;
}
}
});
});