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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
- import type { RunEvalOptions } from '../src/types';
- // Mock dependencies
- jest.mock('cli-progress', () => {
- const mockBar = {
- increment: jest.fn(),
- update: jest.fn(),
- getTotal: jest.fn().mockImplementation(function (this: any) {
- return this._total || 10;
- }),
- };
- return {
- default: {
- MultiBar: jest.fn().mockImplementation(() => ({
- create: jest.fn().mockImplementation((total: number) => {
- const bar = { ...mockBar, _total: total };
- return bar;
- }),
- stop: jest.fn(),
- })),
- Presets: {
- shades_classic: {},
- },
- },
- };
- });
- jest.mock('../src/logger', () => ({
- __esModule: true,
- default: {
- warn: jest.fn(),
- debug: jest.fn(),
- info: jest.fn(),
- error: jest.fn(),
- },
- logger: {
- warn: jest.fn(),
- debug: jest.fn(),
- info: jest.fn(),
- error: jest.fn(),
- },
- setLogLevel: jest.fn(),
- }));
- // Import after mocking - we need to extract ProgressBarManager from evaluator
- // Since it's a private class, we'll test it through its usage patterns
- describe('Progress Bar Management', () => {
- afterEach(() => {
- jest.clearAllMocks();
- });
- describe('ProgressBarManager Work Distribution', () => {
- it('should correctly separate serial and group (concurrent) tasks', () => {
- const runEvalOptions: Partial<RunEvalOptions>[] = [
- { test: { options: { runSerially: true } } },
- { test: {} },
- { test: { options: { runSerially: true } } },
- { test: {} },
- { test: {} },
- ];
- let serialCount = 0;
- let groupCount = 0;
- for (const option of runEvalOptions) {
- if (option.test?.options?.runSerially) {
- serialCount++;
- } else {
- groupCount++;
- }
- }
- expect(serialCount).toBe(2);
- expect(groupCount).toBe(3);
- });
- it('should map indices correctly to execution contexts', () => {
- const indexToContext = new Map();
- const runEvalOptions: Partial<RunEvalOptions>[] = [
- { test: { options: { runSerially: true } } }, // index 0 -> serial
- { test: {} }, // index 1 -> concurrent bar 0
- { test: { options: { runSerially: true } } }, // index 2 -> serial
- { test: {} }, // index 3 -> concurrent bar 1
- { test: {} }, // index 4 -> concurrent bar 2
- ];
- let concurrentCount = 0;
- const concurrency = 3;
- const maxBars = Math.min(concurrency, 20);
- for (let i = 0; i < runEvalOptions.length; i++) {
- const option = runEvalOptions[i];
- if (option.test?.options?.runSerially) {
- indexToContext.set(i, { phase: 'serial', barIndex: 0 });
- } else {
- indexToContext.set(i, {
- phase: 'concurrent',
- barIndex: concurrentCount % maxBars,
- });
- concurrentCount++;
- }
- }
- expect(indexToContext.get(0)).toEqual({ phase: 'serial', barIndex: 0 });
- expect(indexToContext.get(1)).toEqual({ phase: 'concurrent', barIndex: 0 });
- expect(indexToContext.get(2)).toEqual({ phase: 'serial', barIndex: 0 });
- expect(indexToContext.get(3)).toEqual({ phase: 'concurrent', barIndex: 1 });
- expect(indexToContext.get(4)).toEqual({ phase: 'concurrent', barIndex: 2 });
- });
- it('should calculate correct totals for each progress bar', () => {
- const concurrentCount = 10;
- const numBars = 3;
- const perBar = Math.floor(concurrentCount / numBars);
- const remainder = concurrentCount % numBars;
- const barTotals = [];
- for (let i = 0; i < numBars; i++) {
- const total = i < remainder ? perBar + 1 : perBar;
- barTotals.push(total);
- }
- expect(barTotals).toEqual([4, 3, 3]);
- expect(barTotals.reduce((a, b) => a + b, 0)).toBe(concurrentCount);
- });
- it('should handle dynamic comparison bar creation correctly', () => {
- // This test validates that comparison bars are created with the correct total
- // after we know the actual count of comparisons needed
- const cliProgress = require('cli-progress').default;
- const mockMultibar = new cliProgress.MultiBar();
- // Simulate creating progress bars without knowing comparison count initially
- mockMultibar.create(2, 0); // 2 serial tasks
- mockMultibar.create(3, 0); // 3 concurrent tasks
- // Later, when we know we need 5 comparisons, create the comparison bar
- mockMultibar.create(5, 0);
- // Verify the create method was called with correct totals
- expect(mockMultibar.create).toHaveBeenCalledTimes(3);
- expect(mockMultibar.create).toHaveBeenNthCalledWith(1, 2, 0);
- expect(mockMultibar.create).toHaveBeenNthCalledWith(2, 3, 0);
- expect(mockMultibar.create).toHaveBeenNthCalledWith(3, 5, 0);
- });
- });
- });
|