-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest.setup.js
More file actions
87 lines (77 loc) · 2.51 KB
/
vitest.setup.js
File metadata and controls
87 lines (77 loc) · 2.51 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Vitest setup file
* This file is executed before running tests
*/
import { vi } from 'vitest';
import * as Arrow from 'apache-arrow';
import { ArrowVector } from './src/core/storage/ArrowVector.js';
// Export ArrowVector through the global object for access from tests
globalThis.__TinyFrameArrowVector = ArrowVector;
// Enable debug mode for all tests
const DEBUG = true;
// Check if Apache Arrow is available
let arrowAvailable = false;
try {
// Output information about the loaded Arrow module
if (DEBUG) {
console.log('Apache Arrow module keys:', Object.keys(Arrow));
console.log(
'Arrow.vectorFromArray exists:',
typeof Arrow.vectorFromArray === 'function',
);
console.log(
'Arrow.Table exists:',
typeof Arrow.Table === 'object' || typeof Arrow.Table === 'function',
);
console.log('Arrow.Float64 exists:', typeof Arrow.Float64 === 'function');
}
// Check if Arrow has the required functions
if (Arrow && typeof Arrow.vectorFromArray === 'function') {
arrowAvailable = true;
console.log('Apache Arrow successfully loaded in test environment');
// Create a test vector for verification
if (DEBUG) {
try {
const testVector = Arrow.vectorFromArray(['test']);
console.log('Test vector created successfully:', {
type: testVector.constructor.name,
length: testVector.length,
});
} catch (err) {
console.error('Failed to create test vector:', err);
}
}
} else {
console.warn('Apache Arrow loaded but vectorFromArray function not found');
}
} catch (e) {
console.error('Error loading Apache Arrow:', e);
arrowAvailable = false;
}
// Output Arrow availability for tests
console.log('Arrow availability for tests:', arrowAvailable);
// Mock Apache Arrow only if it is not installed or not functional
if (!arrowAvailable) {
console.log('Mocking Apache Arrow with test adapter');
vi.mock(
'apache-arrow',
() => import('./test/mocks/apache-arrow-adapter.js'),
{ virtual: true },
);
}
// Suppress console warnings during tests, but only if Arrow is not installed
if (!arrowAvailable) {
const originalWarn = console.warn;
console.warn = function (message, ...args) {
// Ignore specific Apache Arrow warnings
if (
message &&
(message.includes('Apache Arrow adapter not available') ||
message.includes('Error using Arrow adapter'))
) {
return;
}
// Pass through other warnings
originalWarn.apply(console, [message, ...args]);
};
}