-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupTests.ts
More file actions
88 lines (77 loc) · 2.19 KB
/
setupTests.ts
File metadata and controls
88 lines (77 loc) · 2.19 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
88
/**
* Jest setup file for global test configuration
*/
import '@testing-library/jest-dom';
import { jest, beforeAll, afterAll, expect } from '@jest/globals';
// Mock window.performance for timing tests
Object.defineProperty(window, 'performance', {
value: {
now: jest.fn(() => Date.now()),
mark: jest.fn(),
measure: jest.fn(),
},
writable: true,
});
// Mock console methods to reduce noise in tests
const originalError = console.error;
const originalWarn = console.warn;
beforeAll(() => {
console.error = (...args: any[]) => {
if (
typeof args[0] === 'string' &&
args[0].includes('Warning: ReactDOM.render is deprecated')
) {
return;
}
originalError.call(console, ...args);
};
console.warn = (...args: any[]) => {
if (
typeof args[0] === 'string' &&
args[0].includes('deprecated')
) {
return;
}
originalWarn.call(console, ...args);
};
});
afterAll(() => {
console.error = originalError;
console.warn = originalWarn;
});
// Global test utilities (types defined in types/jest.d.ts)
// Custom matchers
expect.extend({
toBeValidMachineCode(received: number[]) {
const pass = Array.isArray(received) &&
received.every(byte => Number.isInteger(byte) && byte >= 0 && byte <= 255);
if (pass) {
return {
message: () => `expected ${received} not to be valid machine code`,
pass: true,
};
} else {
return {
message: () => `expected ${received} to be valid machine code (array of bytes 0-255)`,
pass: false,
};
}
},
toBeValidAssemblyResult(received: any) {
const pass = received &&
typeof received === 'object' &&
Array.isArray(received.machineCode) &&
(received.error === null || typeof received.error === 'string');
if (pass) {
return {
message: () => `expected ${JSON.stringify(received)} not to be valid AssembleResult`,
pass: true,
};
} else {
return {
message: () => `expected ${JSON.stringify(received)} to be valid AssembleResult with machineCode array and error string|null`,
pass: false,
};
}
},
});