-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathruntime.test.ts
More file actions
52 lines (45 loc) · 1.86 KB
/
Copy pathruntime.test.ts
File metadata and controls
52 lines (45 loc) · 1.86 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
48
49
50
51
52
import { _resetBunWarning, isBunRuntime, warnIfBunRuntime } from '@crawlee/utils';
afterEach(() => {
_resetBunWarning();
delete (globalThis as any).Bun;
});
describe('isBunRuntime', () => {
test('returns false when Bun global is not present', () => {
delete (globalThis as any).Bun;
expect(isBunRuntime()).toBe(false);
});
test('returns true when Bun global is present', () => {
(globalThis as any).Bun = { version: '1.0.0' };
expect(isBunRuntime()).toBe(true);
});
});
describe('warnIfBunRuntime', () => {
test('does nothing when not running under Bun', () => {
delete (globalThis as any).Bun;
const logger = { warning: vitest.fn() };
warnIfBunRuntime(logger);
expect(logger.warning).not.toHaveBeenCalled();
});
test('calls logger.warning when running under Bun', () => {
(globalThis as any).Bun = { version: '1.0.0' };
const logger = { warning: vitest.fn() };
warnIfBunRuntime(logger);
expect(logger.warning).toHaveBeenCalledTimes(1);
expect(logger.warning).toHaveBeenCalledWith(expect.stringContaining('ImpitHttpClient'));
});
test('only warns once even if called multiple times', () => {
(globalThis as any).Bun = { version: '1.0.0' };
const logger = { warning: vitest.fn() };
warnIfBunRuntime(logger);
warnIfBunRuntime(logger);
warnIfBunRuntime(logger);
expect(logger.warning).toHaveBeenCalledTimes(1);
});
test('falls back to console.warn when no logger is provided', () => {
(globalThis as any).Bun = { version: '1.0.0' };
const spy = vitest.spyOn(console, 'warn').mockImplementation(() => {});
warnIfBunRuntime();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith(expect.stringContaining('ImpitHttpClient'));
});
});