ghtool 0.10.6

A command-line tool for interacting with Github API with some specialized features oriented around Checks
Documentation
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
use crate::commands::command::CheckError;
use eyre::Result;
use lazy_static::lazy_static;
use regex::Regex;

const TIMESTAMP_PATTERN: &str = r"(?P<timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+Z)";

lazy_static! {
    /// Regex to match a timestamp and single space after it
    static ref TIMESTAMP: Regex = Regex::new(&format!(r"{TIMESTAMP_PATTERN}\s?")).unwrap();
    static ref JEST_FAIL_LINE: Regex =
        Regex::new(r"(?P<fail>FAIL)\s+(?P<path>[a-zA-Z0-9._-]*/[a-zA-Z0-9./_-]*)").unwrap();
    static ref ESCAPE_SEQUENCE: Regex = Regex::new(r"\x1B\[\d+(;\d+)*m").unwrap();
    static ref FAIL_START: Regex = Regex::new(r"(\x1B\[\d+(;\d+)*m)+\s?FAIL").unwrap();
}

fn find_fail_start(log: &str) -> Option<usize> {
    // First handle test_jest_in_docker case: ... |^[[0m FAIL src/b.test.ts
    // In this case, we should get the position where FAIL starts
    // Otherwise try to find left most escape sequence position before FAIL
    log.find("\u{1b}[0m FAIL")
        .and_then(|_| log.find("FAIL"))
        .or_else(|| FAIL_START.find(log).map(|m| m.start()))
        .or_else(|| log.find("FAIL"))
}

#[derive(Debug, Clone, PartialEq)]
pub struct JestPath {
    pub path: String,
    pub lines: Vec<String>,
}

#[derive(PartialEq, Debug)]
enum State {
    LookingForFail,
    ParsingFail,
}

#[derive(Debug)]
pub struct JestLogParser {
    state: State,
    current_fail: Option<CheckError>,
    all_fails: Vec<CheckError>,
    current_fail_start_col: usize,
    current_fail_lines: Vec<String>,
}

impl JestLogParser {
    pub fn new() -> Self {
        JestLogParser {
            state: State::LookingForFail,
            current_fail: None,
            all_fails: Vec::new(),
            current_fail_start_col: 0,
            current_fail_lines: Vec::new(),
        }
    }

    fn parse_line(&mut self, raw_line: &str) -> Result<(), eyre::Error> {
        let line_no_ansi = String::from_utf8(strip_ansi_escapes::strip(raw_line.as_bytes()))?;
        let line_no_timestamp = TIMESTAMP.replace(raw_line, "");

        match self.state {
            State::LookingForFail => {
                if let Some(caps) = JEST_FAIL_LINE.captures(&line_no_ansi) {
                    // Attempt to find the column where the colored FAIL text starts.
                    // This column position will be used to determine where jest output starts.
                    // We can't just take everything after timestamp because there's possibility
                    // that jest is running inside docker-compose in which case there would be
                    // service name after timestamp.
                    // https://github.com/raine/ghtool/assets/11027/c349807a-cad1-45cb-b02f-4d5020bb3c23
                    self.current_fail_start_col = find_fail_start(&line_no_timestamp).unwrap();
                    let path = caps.name("path").unwrap().as_str().to_string();
                    // Get line discarding things before the column where FAIL starts
                    let line = line_no_timestamp
                        .chars()
                        .skip(self.current_fail_start_col)
                        .collect::<String>();
                    self.current_fail = Some(CheckError {
                        lines: vec![line.to_string()],
                        path,
                    });
                    self.state = State::ParsingFail;
                }
            }
            State::ParsingFail => {
                let next_char_from_fail =
                    find_next_non_ansi_char(&line_no_timestamp, self.current_fail_start_col);

                // https://github.com/raine/ghtool/assets/11027/08dd631e-391c-4277-8eab-75fe55d9e659
                if line_no_timestamp.len() > self.current_fail_start_col
                    && next_char_from_fail.is_some()
                    && next_char_from_fail != Some(' ')
                {
                    let mut current_fail = std::mem::take(&mut self.current_fail).unwrap();

                    // Remove trailing empty lines
                    if let Some(last_non_empty_line) =
                        current_fail.lines.iter().rposition(|line| !line.is_empty())
                    {
                        current_fail.lines.truncate(last_non_empty_line + 1);
                    }

                    self.all_fails.push(current_fail);
                    self.current_fail_lines = Vec::new();
                    self.state = State::LookingForFail;
                } else {
                    // Get line discarding things before the column where FAIL starts
                    let line = line_no_timestamp
                        .chars()
                        .skip(self.current_fail_start_col)
                        .collect::<String>();

                    self.current_fail.as_mut().unwrap().lines.push(line);
                }
            }
        }
        Ok(())
    }

    pub fn parse(log: &str) -> Result<Vec<CheckError>> {
        let mut parser = JestLogParser::new();

        for line in log.lines() {
            parser.parse_line(line)?;
        }

        Ok(parser.get_output())
    }

    pub fn get_output(self) -> Vec<CheckError> {
        self.all_fails
            .into_iter()
            .fold(Vec::new(), |mut acc, fail| {
                if !acc.contains(&fail) {
                    acc.push(fail);
                }
                acc
            })
    }
}

impl Default for JestLogParser {
    fn default() -> Self {
        Self::new()
    }
}

fn find_next_non_ansi_char(str: &str, start_col: usize) -> Option<char> {
    let bytes = str.as_bytes();
    let mut index = start_col;

    while index < bytes.len() {
        if bytes[index] == 0x1B {
            // found an ESC character, start skipping the ANSI sequence
            index += 1; // skip the ESC character
            if index < bytes.len() && bytes[index] == b'[' {
                index += 1; // skip the '[' character
                            // skip until we find a letter indicating the end of the ANSI sequence
                while index < bytes.len() && !bytes[index].is_ascii_alphabetic() {
                    index += 1;
                }
            }
        } else {
            // found a non-ANSI escape character
            return str[index..].chars().next();
        }
        index += 1;
    }

    None
}

// Tests
#[cfg(test)]
mod tests {
    use super::*;
    use pretty_assertions::assert_eq;

    #[test]
    fn test_extract_failing_tests() {
        let logs = r#"
2021-05-04T18:24:29.000Z FAIL src/components/MyComponent/MyComponent.test.tsx
2021-05-04T18:24:29.000Z   ● Test suite failed to run
2021-05-04T18:24:29.000Z     TypeError: Cannot read property 'foo' of undefined
2021-05-04T18:24:29.000Z
2021-05-04T18:24:29.000Z       1 | import React from 'react';
2021-05-04T18:24:29.000Z PASS src/components/MyComponent/MyComponent.test.tsx
2021-05-04T18:24:29.000Z FAIL src/components/MyComponent/MyComponent2.test.tsx
2021-05-04T18:24:29.000Z   ● Test suite failed to run
2021-05-04T18:24:29.000Z     TypeError: Cannot read property 'foo' of undefined
2021-05-04T18:24:29.000Z
2021-05-04T18:24:29.000Z       1 | import React from 'react';
2021-05-04T18:24:29.000Z PASS src/components/MyComponent/MyComponent2.test.tsx"#;

        let failing_tests = JestLogParser::parse(logs).unwrap();
        assert_eq!(
            failing_tests,
            vec![
                CheckError {
                    path: "src/components/MyComponent/MyComponent.test.tsx".to_string(),
                    lines: vec![
                        "FAIL src/components/MyComponent/MyComponent.test.tsx".to_string(),
                        "  ● Test suite failed to run".to_string(),
                        "    TypeError: Cannot read property 'foo' of undefined".to_string(),
                        "".to_string(),
                        "      1 | import React from 'react';".to_string(),
                    ]
                },
                CheckError {
                    path: "src/components/MyComponent/MyComponent2.test.tsx".to_string(),
                    lines: vec![
                        "FAIL src/components/MyComponent/MyComponent2.test.tsx".to_string(),
                        "  ● Test suite failed to run".to_string(),
                        "    TypeError: Cannot read property 'foo' of undefined".to_string(),
                        "".to_string(),
                        "      1 | import React from 'react';".to_string(),
                    ]
                },
            ]
        );
    }

    #[test]
    fn test_extract_failing_tests_2() {
        let logs = r#"
2023-06-28T21:11:38.9421220Z > ghtool-test-repo@1.0.0 test
2023-06-28T21:11:38.9428514Z > jest ./src --color --ci --shard=1/2
2023-06-28T21:11:38.9429089Z 
2023-06-28T21:11:43.1619050Z  FAIL  src/test2.test.ts
2023-06-28T21:11:43.1623893Z   test2
2023-06-28T21:11:43.1629746Z     ✓ succeeds (3 ms)
2023-06-28T21:11:43.1630396Z     ✕ fails (5 ms)
2023-06-28T21:11:43.1630949Z 
2023-06-28T21:11:43.1631448Z   ● test2 › fails
2023-06-28T21:11:43.1631750Z 
2023-06-28T21:11:43.1632455Z     expect(received).toBe(expected) // Object.is equality
2023-06-28T21:11:43.1633081Z 
2023-06-28T21:11:43.1633381Z     Expected: false
2023-06-28T21:11:43.1633800Z     Received: true
2023-06-28T21:11:43.1634250Z 
2023-06-28T21:11:43.1634753Z        5 |
2023-06-28T21:11:43.1635444Z        6 |   it("fails", () => {
2023-06-28T21:11:43.1636318Z     >  7 |     expect(true).toBe(false);
2023-06-28T21:11:43.1637060Z          |                  ^
2023-06-28T21:11:43.1642719Z        8 |   });
2023-06-28T21:11:43.1647216Z        9 | });
2023-06-28T21:11:43.1648590Z       10 |
2023-06-28T21:11:43.1649650Z 
2023-06-28T21:11:43.1651496Z       at Object.<anonymous> (src/test2.test.ts:7:18)
2023-06-28T21:11:43.1652032Z 
2023-06-28T21:11:43.1664383Z Test Suites: 1 failed, 1 total
2023-06-28T21:11:43.1665139Z Tests:       1 failed, 1 passed, 2 total
2023-06-28T21:11:43.1665683Z Snapshots:   0 total
2023-06-28T21:11:43.1666152Z Time:        3.464 s
2023-06-28T21:11:43.1666769Z Ran all test suites matching /.\/src/i."#;

        let failing_tests = JestLogParser::parse(logs).unwrap();
        assert_eq!(
            failing_tests,
            vec![CheckError {
                path: "src/test2.test.ts".to_string(),
                lines: vec![
                    "FAIL  src/test2.test.ts".to_string(),
                    " test2".to_string(),
                    "   ✓ succeeds (3 ms)".to_string(),
                    "   ✕ fails (5 ms)".to_string(),
                    "".to_string(),
                    " ● test2 › fails".to_string(),
                    "".to_string(),
                    "   expect(received).toBe(expected) // Object.is equality".to_string(),
                    "".to_string(),
                    "   Expected: false".to_string(),
                    "   Received: true".to_string(),
                    "".to_string(),
                    "      5 |".to_string(),
                    "      6 |   it(\"fails\", () => {".to_string(),
                    "   >  7 |     expect(true).toBe(false);".to_string(),
                    "        |                  ^".to_string(),
                    "      8 |   });".to_string(),
                    "      9 | });".to_string(),
                    "     10 |".to_string(),
                    "".to_string(),
                    "     at Object.<anonymous> (src/test2.test.ts:7:18)".to_string(),
                ],
            },]
        );
    }

    #[test]
    fn test_extract_failing_test_files() {
        let logs = r#"
2021-05-04T18:24:29.000Z FAIL src/components/MyComponent/MyComponent.test.tsx
2021-05-04T18:24:29.000Z   ● Test suite failed to run
2021-05-04T18:24:29.000Z     TypeError: Cannot read property 'foo' of undefined
2021-05-04T18:24:29.000Z
2021-05-04T18:24:29.000Z       1 | import React from 'react';
2021-05-04T18:24:29.000Z PASS src/components/MyComponent/MyComponent2.test.tsx
2021-05-04T18:24:29.000Z FAIL src/components/MyComponent/MyComponent3.test.tsx
2021-05-04T18:24:29.000Z   ● Test suite failed to run
2021-05-04T18:24:29.000Z     TypeError: Cannot read property 'foo' of undefined
2021-05-04T18:24:29.000Z
2021-05-04T18:24:29.000Z       1 | import React from 'react';
2021-05-04T18:24:29.000Z PASS src/components/MyComponent/MyComponent4.test.tsx"#;

        let failing_tests = JestLogParser::parse(logs).unwrap();
        let failing_test_files: Vec<String> = failing_tests
            .iter()
            .map(|jest_path| jest_path.path.clone())
            .collect();

        assert_eq!(
            failing_test_files,
            vec![
                "src/components/MyComponent/MyComponent.test.tsx".to_string(),
                "src/components/MyComponent/MyComponent3.test.tsx".to_string(),
            ]
        );
    }

    #[test]
    fn test_remove_duplicate_check_errors() {
        let logs = r#"
2023-09-14T12:22:30.2648458Z
2023-09-14T12:22:30.2648458Z FAIL src/components/MyComponent/MyComponent3.test.tsx
2023-09-14T12:22:30.2648458Z   ● Test suite failed to run
2023-09-14T12:22:30.2648458Z     TypeError: Cannot read property 'foo' of undefined
2023-09-14T12:22:30.2648458Z
2023-09-14T12:22:30.2648458Z       1 | import React from 'react';
2023-09-14T12:22:30.2648458Z 
2023-09-14T12:22:30.2649146Z Summary of all failing tests
2023-09-14T12:22:30.2648458Z FAIL src/components/MyComponent/MyComponent3.test.tsx
2023-09-14T12:22:30.2648458Z   ● Test suite failed to run
2023-09-14T12:22:30.2648458Z     TypeError: Cannot read property 'foo' of undefined
2023-09-14T12:22:30.2648458Z
2023-09-14T12:22:30.2648458Z       1 | import React from 'react';
2023-09-14T12:22:30.2673693Z 
2023-09-14T12:22:30.2673711Z 
2023-09-14T12:22:30.2678119Z Test Suites: 1 failed, 67 passed, 68 total
2023-09-14T12:22:30.2679079Z Tests:       1 failed, 469 passed, 470 total
2023-09-14T12:22:30.2680281Z Snapshots:   60 passed, 60 total
2023-09-14T12:22:30.2680933Z Time:        216.339 s
        "#;

        let failing_tests = JestLogParser::parse(logs).unwrap();
        assert_eq!(failing_tests.len(), 1);
    }

    #[test]
    fn test_jest_in_docker() {
        let logs = r#"
2023-12-14T12:24:25.7014935Z test_1            | $ jest -c jest.config.test.js
2023-12-14T12:24:43.7723478Z test_1            | PASS src/a.test.ts (16.764 s)
2023-12-14T12:24:53.1189316Z test_1            | FAIL src/b.test.ts
2023-12-14T12:24:53.1486488Z test_1            |   ● test › return test things
2023-12-14T12:24:53.1488314Z test_1            |
2023-12-14T12:24:53.1489247Z test_1            |     expect(received).toMatchObject(expected)
2023-12-14T12:24:53.1490238Z test_1            |
2023-12-14T12:24:53.1490994Z test_1            |     - Expected  - 1
2023-12-14T12:24:53.1491871Z test_1            |     + Received  + 0
2023-12-14T12:24:53.1492657Z test_1            |
2023-12-14T12:24:53.1493405Z test_1            |     @@ -17,9 +17,8 @@
2023-12-14T12:24:53.1662308Z test_1            |     -       "testId": undefined,
2023-12-14T12:24:53.1684564Z test_1            |           },
2023-12-14T12:24:53.1724498Z test_1            |         },
2023-12-14T12:24:53.1764019Z test_1            |       ]
2023-12-14T12:24:53.1788159Z test_1            |
2023-12-14T12:24:53.1790147Z test_1            |     > 62 |     expect(result).toMatchObject([
2023-12-14T12:24:53.1790859Z test_1            |          |                    ^
2023-12-14T12:24:53.1794182Z test_1            |
2023-12-14T12:24:53.1794946Z test_1            |       at Object.<anonymous> (src/a.test.ts:62:20)
2023-12-14T12:24:53.1841737Z test_1            |
2023-12-14T12:24:53.4683252Z test_1            | PASS src/b.test.ts
        "#;

        let failing_tests = JestLogParser::parse(logs).unwrap();

        assert_eq!(
            failing_tests,
            vec![CheckError {
                path: "src/b.test.ts".to_string(),
                lines: vec![
                    "FAIL src/b.test.ts".to_string(),
                    "  ● test › return test things".to_string(),
                    "".to_string(),
                    "    expect(received).toMatchObject(expected)".to_string(),
                    "".to_string(),
                    "    - Expected  - 1".to_string(),
                    "    + Received  + 0".to_string(),
                    "".to_string(),
                    "    @@ -17,9 +17,8 @@".to_string(),
                    "    -       \"testId\": undefined,".to_string(),
                    "          },".to_string(),
                    "        },".to_string(),
                    "      ]".to_string(),
                    "".to_string(),
                    "    > 62 |     expect(result).toMatchObject([".to_string(),
                    "         |                    ^".to_string(),
                    "".to_string(),
                    "      at Object.<anonymous> (src/a.test.ts:62:20)".to_string(),
                ],
            }]
        );
    }

    #[test]
    fn test_find_fail_position() {
        let test_cases = vec![
            (
                "2023-12-14T12:24:53.1189316Z test_1            | FAIL src/b.test.ts",
                Some(58),
            ),
            (
                "2024-05-11T20:45:16.0032874Z  FAIL  src/test2.test.ts (61.458 s)",
                Some(29),
            ),
            (
                "2024-05-29T08:34:09.8655201Z   FAIL src/a.spec.tsx (14728 ms)",
                Some(31),
            ),
            (
                "2024-05-11T20:45:16.0032874Z  FAIL  src/test2.test.ts (61.458 s)",
                Some(29),
            ),
        ];

        for (input, expected) in test_cases {
            assert_eq!(find_fail_start(input), expected);
        }
    }

    #[test]
    fn test_escape_sequence() {
        assert!(ESCAPE_SEQUENCE.is_match(""));
    }

    #[test]
    fn test_colors() {
        let logs = r#"
2024-05-11T20:44:13.9945728Z $ jest ./src --color --ci --shard=1/2
2024-05-11T20:45:16.0032874Z  FAIL  src/test2.test.ts (61.458 s)
2024-05-11T20:45:16.0034300Z   test2
2024-05-11T20:45:16.0037347Z     ✓ succeeds (1 ms)
2024-05-11T20:45:16.0038258Z     ✕ fails (2 ms)
2024-05-11T20:45:16.0039034Z     ✓ foo (60001 ms)
2024-05-11T20:45:16.0039463Z 
2024-05-11T20:45:16.0039981Z   ● test2 › fails
2024-05-11T20:45:16.0040506Z 
2024-05-11T20:45:16.0041462Z     expect(received).toBe(expected) // Object.is equality
2024-05-11T20:45:16.0045857Z 
2024-05-11T20:45:16.0046210Z     Expected: false
2024-05-11T20:45:16.0046774Z     Received: true
2024-05-11T20:45:16.0047256Z 
2024-05-11T20:45:16.0047765Z        5 |
2024-05-11T20:45:16.0048791Z        6 |   it("fails", () => {
2024-05-11T20:45:16.0051048Z     >  7 |     expect(true).toBe(false);
2024-05-11T20:45:16.0052427Z          |                  ^
2024-05-11T20:45:16.0053352Z        8 |   });
2024-05-11T20:45:16.0054060Z        9 |
2024-05-11T20:45:16.0055164Z       10 |   it("foo", async () => {
2024-05-11T20:45:16.0056008Z 
2024-05-11T20:45:16.0057064Z       at Object.<anonymous> (src/test2.test.ts:7:18)
2024-05-11T20:45:16.0057817Z 
2024-05-11T20:45:16.0064933Z Test Suites: 1 failed, 1 total
2024-05-11T20:45:16.0065943Z Tests:       1 failed, 2 passed, 3 total
2024-05-11T20:45:16.0066489Z Snapshots:   0 total
2024-05-11T20:45:16.0066847Z Time:        61.502 s
2024-05-11T20:45:16.0067359Z Ran all test suites matching /.\/src/i.
        "#;

        let failing_tests = JestLogParser::parse(logs).unwrap();
        assert_eq!(
            failing_tests,
            vec![CheckError {
                path: "src/test2.test.ts".to_string(),
                lines: vec![
                    "\u{1b}[0m\u{1b}[7m\u{1b}[1m\u{1b}[31m FAIL \u{1b}[39m\u{1b}[22m\u{1b}[27m\u{1b}[0m \u{1b}[2msrc/\u{1b}[22m\u{1b}[1mtest2.test.ts\u{1b}[22m (\u{1b}[0m\u{1b}[1m\u{1b}[41m61.458 s\u{1b}[49m\u{1b}[22m\u{1b}[0m)".to_string(),
                    "  test2".to_string(),
                    "    \u{1b}[32m✓\u{1b}[39m \u{1b}[2msucceeds (1 ms)\u{1b}[22m".to_string(),
                    "    \u{1b}[31m✕\u{1b}[39m \u{1b}[2mfails (2 ms)\u{1b}[22m".to_string(),
                    "    \u{1b}[32m✓\u{1b}[39m \u{1b}[2mfoo (60001 ms)\u{1b}[22m".to_string(),
                    "".to_string(),
                    "\u{1b}[1m\u{1b}[31m  \u{1b}[1m● \u{1b}[22m\u{1b}[1mtest2 › fails\u{1b}[39m\u{1b}[22m".to_string(),
                    "".to_string(),
                    "    \u{1b}[2mexpect(\u{1b}[22m\u{1b}[31mreceived\u{1b}[39m\u{1b}[2m).\u{1b}[22mtoBe\u{1b}[2m(\u{1b}[22m\u{1b}[32mexpected\u{1b}[39m\u{1b}[2m) // Object.is equality\u{1b}[22m".to_string(),
                    "".to_string(),
                    "    Expected: \u{1b}[32mfalse\u{1b}[39m".to_string(),
                    "    Received: \u{1b}[31mtrue\u{1b}[39m".to_string(),
                    "\u{1b}[2m\u{1b}[22m".to_string(),
                    "\u{1b}[2m    \u{1b}[0m \u{1b}[90m  5 |\u{1b}[39m\u{1b}[0m\u{1b}[22m".to_string(),
                    "\u{1b}[2m    \u{1b}[0m \u{1b}[90m  6 |\u{1b}[39m   it(\u{1b}[32m\"fails\"\u{1b}[39m\u{1b}[33m,\u{1b}[39m () \u{1b}[33m=>\u{1b}[39m {\u{1b}[0m\u{1b}[22m".to_string(),
                    "\u{1b}[2m    \u{1b}[0m\u{1b}[31m\u{1b}[1m>\u{1b}[22m\u{1b}[2m\u{1b}[39m\u{1b}[90m  7 |\u{1b}[39m     expect(\u{1b}[36mtrue\u{1b}[39m)\u{1b}[33m.\u{1b}[39mtoBe(\u{1b}[36mfalse\u{1b}[39m)\u{1b}[33m;\u{1b}[39m\u{1b}[0m\u{1b}[22m".to_string(),
                    "\u{1b}[2m    \u{1b}[0m \u{1b}[90m    |\u{1b}[39m                  \u{1b}[31m\u{1b}[1m^\u{1b}[22m\u{1b}[2m\u{1b}[39m\u{1b}[0m\u{1b}[22m".to_string(),
                    "\u{1b}[2m    \u{1b}[0m \u{1b}[90m  8 |\u{1b}[39m   })\u{1b}[33m;\u{1b}[39m\u{1b}[0m\u{1b}[22m".to_string(),
                    "\u{1b}[2m    \u{1b}[0m \u{1b}[90m  9 |\u{1b}[39m\u{1b}[0m\u{1b}[22m".to_string(),
                    "\u{1b}[2m    \u{1b}[0m \u{1b}[90m 10 |\u{1b}[39m   it(\u{1b}[32m\"foo\"\u{1b}[39m\u{1b}[33m,\u{1b}[39m \u{1b}[36masync\u{1b}[39m () \u{1b}[33m=>\u{1b}[39m {\u{1b}[0m\u{1b}[22m".to_string(),
                    "\u{1b}[2m\u{1b}[22m".to_string(),
                    "\u{1b}[2m      \u{1b}[2mat Object.<anonymous> (\u{1b}[22m\u{1b}[2m\u{1b}[0m\u{1b}[36msrc/test2.test.ts\u{1b}[39m\u{1b}[0m\u{1b}[2m:7:18)\u{1b}[22m\u{1b}[2m\u{1b}[22m".to_string(),
                ]
            },]
        );
    }

    #[test]
    fn test_more_colors() {
        let logs = r#"
2024-05-29T08:34:09.8655201Z   FAIL src/a.spec.tsx (14728 ms)
2024-05-29T08:34:09.8656607Z     utilityFunction
2024-05-29T08:34:09.8658244Z       ✕ should perform action correctly (29 ms)
2024-05-29T08:34:11.2518625Z ##[group]PASS src/FeatureSection.spec.tsx (44752 ms)
2024-05-29T08:37:56.8027075Z Summary of all failing tests
2024-05-29T08:37:56.8042690Z  FAIL  packages/foo/src/a.spec.tsx (14.728 s)
2024-05-29T08:37:56.8045558Z   ● utilityFunction › should perform action correctly
2024-05-29T08:37:56.8046501Z
2024-05-29T08:37:56.8046955Z     TypeError: Cannot read properties of undefined (reading 'property')
2024-05-29T08:37:56.8047659Z 
2024-05-29T08:37:56.8048616Z       228 |               // To handle undefined properties safely
2024-05-29T08:37:56.8049807Z       229 |               isEnabled:
2024-05-29T08:37:56.8051465Z     > 230 |                 object.property.mode === 'active',
2024-05-29T08:37:56.8052724Z           |                                      ^
2024-05-29T08:37:56.8053954Z       231 |               ...(isEnabled ? { isEnabled } : {}),
2024-05-29T08:37:56.8055365Z       232 |             };
2024-05-29T08:37:56.8056071Z       233 |           }),
2024-05-29T08:37:56.8056615Z 
2024-05-29T08:37:56.8062690Z       at property (src/fileA.ts:230:38)
2024-05-29T08:37:56.8063920Z           at Array.map (<anonymous>)
2024-05-29T08:37:56.8065216Z       at map (src/fileA.ts:200:45)
2024-05-29T08:37:56.8067038Z           at Array.reduce (<anonymous>)
2024-05-29T08:37:56.8068351Z       at reduce (src/fileA.ts:196:61)
2024-05-29T08:37:56.8118331Z
2024-05-29T08:37:56.8118337Z
2024-05-29T08:37:56.8125241Z Test Suites: 1 failed, 1 skipped, 100 passed, 100 of 100 total
2024-05-29T08:37:56.8127233Z Tests:       1 failed, 21 skipped, 2 todo, 100 passed, 100 total
            "#;
        let failing_tests = JestLogParser::parse(logs).unwrap();
        assert_eq!(
            failing_tests,
            vec![
                CheckError {
                    path: "src/a.spec.tsx".to_string(),
                    lines: vec![
                        "\u{1b}[1m\u{1b}[31m\u{1b}[7mFAIL\u{1b}[27m\u{1b}[39m\u{1b}[22m src/a.spec.tsx (\u{1b}[31m\u{1b}[7m14728 ms\u{1b}[27m\u{1b}[39m)".to_string(),
                        "  utilityFunction".to_string(),
                        "    \u{1b}[31m✕\u{1b}[39m should perform action correctly (29 ms)".to_string(),
                    ],
                },
                CheckError {
                    path: "packages/foo/src/a.spec.tsx".to_string(),
                    lines: vec![
                        "\u{1b}[0m\u{1b}[7m\u{1b}[1m\u{1b}[31m FAIL \u{1b}[39m\u{1b}[22m\u{1b}[27m\u{1b}[0m \u{1b}[2mpackages/foo/src/\u{1b}[22m\u{1b}[1ma.spec.tsx\u{1b}[22m (\u{1b}[0m\u{1b}[1m\u{1b}[41m14.728 s\u{1b}[49m\u{1b}[22m\u{1b}[0m)".to_string(),
                        "\u{1b}[1m\u{1b}[31m  \u{1b}[1m● \u{1b}[22m\u{1b}[1mutilityFunction › should perform action correctly\u{1b}[39m\u{1b}[22m".to_string(),
                        "".to_string(),
                        "    TypeError: Cannot read properties of undefined (reading 'property')".to_string(),
                        "\u{1b}[2m\u{1b}[22m".to_string(),
                        "\u{1b}[2m    \u{1b}[0m \u{1b}[90m 228 |\u{1b}[39m               \u{1b}[90m// To handle undefined properties safely\u{1b}[39m\u{1b}[22m".to_string(),
                        "\u{1b}[2m     \u{1b}[90m 229 |\u{1b}[39m               isEnabled\u{1b}[33m:\u{1b}[39m\u{1b}[22m".to_string(),
                        "\u{1b}[2m    \u{1b}[31m\u{1b}[1m>\u{1b}[22m\u{1b}[2m\u{1b}[39m\u{1b}[90m 230 |\u{1b}[39m                 object\u{1b}[33m.\u{1b}[39mproperty\u{1b}[33m.\u{1b}[39mmode \u{1b}[33m===\u{1b}[39m \u{1b}[32m'active'\u{1b}[39m\u{1b}[33m,\u{1b}[39m\u{1b}[22m".to_string(),
                        "\u{1b}[2m     \u{1b}[90m     |\u{1b}[39m                                      \u{1b}[31m\u{1b}[1m^\u{1b}[22m\u{1b}[2m\u{1b}[39m\u{1b}[22m".to_string(),
                        "\u{1b}[2m     \u{1b}[90m 231 |\u{1b}[39m               \u{1b}[33m...\u{1b}[39m(isEnabled \u{1b}[33m?\u{1b}[39m { isEnabled } \u{1b}[33m:\u{1b}[39m {})\u{1b}[33m,\u{1b}[39m\u{1b}[22m".to_string(),
                        "\u{1b}[2m     \u{1b}[90m 232 |\u{1b}[39m             }\u{1b}[33m;\u{1b}[39m\u{1b}[22m".to_string(),
                        "\u{1b}[2m     \u{1b}[90m 233 |\u{1b}[39m           })\u{1b}[33m,\u{1b}[39m\u{1b}[0m\u{1b}[22m".to_string(),
                        "\u{1b}[2m\u{1b}[22m".to_string(),
                        "\u{1b}[2m      \u{1b}[2mat property (\u{1b}[22m\u{1b}[2msrc/fileA.ts\u{1b}[2m:230:38)\u{1b}[22m\u{1b}[2m\u{1b}[22m".to_string(),
                        "\u{1b}[2m          at Array.map (<anonymous>)\u{1b}[22m".to_string(),
                        "\u{1b}[2m      \u{1b}[2mat map (\u{1b}[22m\u{1b}[2msrc/fileA.ts\u{1b}[2m:200:45)\u{1b}[22m\u{1b}[2m\u{1b}[22m".to_string(),
                        "\u{1b}[2m          at Array.reduce (<anonymous>)\u{1b}[22m".to_string(),
                        "\u{1b}[2m      \u{1b}[2mat reduce (\u{1b}[22m\u{1b}[2msrc/fileA.ts\u{1b}[2m:196:61)\u{1b}[22m\u{1b}[2m\u{1b}[22m".to_string(),
                    ],
                },
            ]
        );
    }

    #[test]
    fn test_find_next_non_ansi_char() {
        let str = " \u{1b}[32m\u{1b}[31m ";
        let start_col = 1;
        assert_eq!(find_next_non_ansi_char(str, start_col), Some(' '));
    }
}