|
1 | | -import { getEmoji, normalizeSuite, stripAnsi } from '../../src/ctrf/helpers.js' |
2 | | - |
3 | | -describe('getEmoji', () => { |
4 | | - it('returns the correct emoji for "passed"', () => { |
5 | | - expect(getEmoji('passed')).toBe('✅') |
6 | | - }) |
7 | | - |
8 | | - it('returns the correct emoji for "failed"', () => { |
9 | | - expect(getEmoji('failed')).toBe('❌') |
10 | | - }) |
11 | | - |
12 | | - it('returns the correct emoji for "skipped"', () => { |
13 | | - expect(getEmoji('skipped')).toBe('⏭️') |
14 | | - }) |
15 | | - |
16 | | - it('returns the correct emoji for "pending"', () => { |
17 | | - expect(getEmoji('pending')).toBe('⏳') |
18 | | - }) |
19 | | - |
20 | | - it('returns the correct emoji for "other"', () => { |
21 | | - expect(getEmoji('other')).toBe('❓') |
22 | | - }) |
23 | | - |
24 | | - it('returns the correct emoji for "build"', () => { |
25 | | - expect(getEmoji('build')).toBe('🏗️') |
26 | | - }) |
27 | | - |
28 | | - it('returns the correct emoji for "duration"', () => { |
29 | | - expect(getEmoji('duration')).toBe('⏱️') |
30 | | - }) |
31 | | - |
32 | | - it('returns the correct emoji for "flaky"', () => { |
33 | | - expect(getEmoji('flaky')).toBe('🍂') |
34 | | - }) |
35 | | - |
36 | | - it('returns the correct emoji for "tests"', () => { |
37 | | - expect(getEmoji('tests')).toBe('📝') |
38 | | - }) |
39 | | - |
40 | | - it('returns the correct emoji for "result"', () => { |
41 | | - expect(getEmoji('result')).toBe('🧪') |
42 | | - }) |
43 | | -}) |
44 | | - |
45 | | -describe('normalizeSuite', () => { |
46 | | - it('handles array format (new CTRF format) with default separator', () => { |
47 | | - const suiteArray = ['string.test.ts', 'String Helpers', 'splitLines'] |
48 | | - const result = normalizeSuite(suiteArray) |
49 | | - expect(result).toBe('string.test.ts > String Helpers > splitLines') |
50 | | - }) |
51 | | - |
52 | | - it('handles array format with custom separator', () => { |
53 | | - const suiteArray = ['suite1', 'suite2', 'suite3'] |
54 | | - const result = normalizeSuite(suiteArray, ' / ') |
55 | | - expect(result).toBe('suite1 / suite2 / suite3') |
56 | | - }) |
57 | | - |
58 | | - it('handles string format (legacy CTRF format)', () => { |
59 | | - const suiteString = 'string.test.ts > String Helpers > splitLines' |
60 | | - const result = normalizeSuite(suiteString) |
61 | | - expect(result).toBe('string.test.ts > String Helpers > splitLines') |
62 | | - }) |
63 | | - |
64 | | - it('returns undefined when suite is undefined', () => { |
65 | | - const result = normalizeSuite(undefined) |
66 | | - expect(result).toBeUndefined() |
67 | | - }) |
68 | | - |
69 | | - it('handles empty array', () => { |
70 | | - const result = normalizeSuite([]) |
71 | | - expect(result).toBe('') |
72 | | - }) |
73 | | - |
74 | | - it('handles single element array', () => { |
75 | | - const result = normalizeSuite(['suite1']) |
76 | | - expect(result).toBe('suite1') |
77 | | - }) |
78 | | - |
79 | | - it('handles empty string', () => { |
80 | | - const result = normalizeSuite('') |
81 | | - expect(result).toBeUndefined() |
82 | | - }) |
83 | | -}) |
84 | | - |
85 | | -describe('stripAnsi', () => { |
86 | | - it('removes ANSI escape codes from a string', () => { |
87 | | - const ansiString = '\u001b[31mHello\u001b[39m' |
88 | | - const result = stripAnsi(ansiString) |
89 | | - expect(result).toBe('Hello') |
90 | | - }) |
91 | | - |
92 | | - it('returns the same string if no ANSI codes are present', () => { |
93 | | - const normalString = 'Just a normal string' |
94 | | - const result = stripAnsi(normalString) |
95 | | - expect(result).toBe(normalString) |
96 | | - }) |
97 | | - |
98 | | - it('handles empty strings correctly', () => { |
99 | | - const emptyString = '' |
100 | | - const result = stripAnsi(emptyString) |
101 | | - expect(result).toBe('') |
102 | | - }) |
103 | | - |
104 | | - it('throws a TypeError if the input is not a string', () => { |
105 | | - // @ts-expect-error Testing runtime error |
106 | | - expect(() => stripAnsi(123)).toThrow(TypeError) |
107 | | - // @ts-expect-error Testing runtime error |
108 | | - expect(() => stripAnsi(null)).toThrow(TypeError) |
109 | | - // @ts-expect-error Testing runtime error |
110 | | - expect(() => stripAnsi(undefined)).toThrow(TypeError) |
111 | | - // @ts-expect-error Testing runtime error |
112 | | - expect(() => stripAnsi({})).toThrow(TypeError) |
113 | | - }) |
114 | | -}) |
| 1 | +import { getEmoji, normalizeSuite, stripAnsi } from "../../src/ctrf/helpers.js"; |
| 2 | + |
| 3 | +describe("getEmoji", () => { |
| 4 | + it('returns the correct emoji for "passed"', () => { |
| 5 | + expect(getEmoji("passed")).toBe("✅"); |
| 6 | + }); |
| 7 | + |
| 8 | + it('returns the correct emoji for "failed"', () => { |
| 9 | + expect(getEmoji("failed")).toBe("❌"); |
| 10 | + }); |
| 11 | + |
| 12 | + it('returns the correct emoji for "skipped"', () => { |
| 13 | + expect(getEmoji("skipped")).toBe("⏭️"); |
| 14 | + }); |
| 15 | + |
| 16 | + it('returns the correct emoji for "pending"', () => { |
| 17 | + expect(getEmoji("pending")).toBe("⏳"); |
| 18 | + }); |
| 19 | + |
| 20 | + it('returns the correct emoji for "other"', () => { |
| 21 | + expect(getEmoji("other")).toBe("❓"); |
| 22 | + }); |
| 23 | + |
| 24 | + it('returns the correct emoji for "build"', () => { |
| 25 | + expect(getEmoji("build")).toBe("🏗️"); |
| 26 | + }); |
| 27 | + |
| 28 | + it('returns the correct emoji for "duration"', () => { |
| 29 | + expect(getEmoji("duration")).toBe("⏱️"); |
| 30 | + }); |
| 31 | + |
| 32 | + it('returns the correct emoji for "flaky"', () => { |
| 33 | + expect(getEmoji("flaky")).toBe("🍂"); |
| 34 | + }); |
| 35 | + |
| 36 | + it('returns the correct emoji for "tests"', () => { |
| 37 | + expect(getEmoji("tests")).toBe("📝"); |
| 38 | + }); |
| 39 | + |
| 40 | + it('returns the correct emoji for "result"', () => { |
| 41 | + expect(getEmoji("result")).toBe("🧪"); |
| 42 | + }); |
| 43 | +}); |
| 44 | + |
| 45 | +describe("normalizeSuite", () => { |
| 46 | + it("handles array format (new CTRF format) with default separator", () => { |
| 47 | + const suiteArray = ["string.test.ts", "String Helpers", "splitLines"]; |
| 48 | + const result = normalizeSuite(suiteArray); |
| 49 | + expect(result).toBe("string.test.ts > String Helpers > splitLines"); |
| 50 | + }); |
| 51 | + |
| 52 | + it("handles array format with custom separator", () => { |
| 53 | + const suiteArray = ["suite1", "suite2", "suite3"]; |
| 54 | + const result = normalizeSuite(suiteArray, " / "); |
| 55 | + expect(result).toBe("suite1 / suite2 / suite3"); |
| 56 | + }); |
| 57 | + |
| 58 | + it("handles string format (legacy CTRF format)", () => { |
| 59 | + const suiteString = "string.test.ts > String Helpers > splitLines"; |
| 60 | + const result = normalizeSuite(suiteString); |
| 61 | + expect(result).toBe("string.test.ts > String Helpers > splitLines"); |
| 62 | + }); |
| 63 | + |
| 64 | + it("returns undefined when suite is undefined", () => { |
| 65 | + const result = normalizeSuite(undefined); |
| 66 | + expect(result).toBeUndefined(); |
| 67 | + }); |
| 68 | + |
| 69 | + it("handles empty array", () => { |
| 70 | + const result = normalizeSuite([]); |
| 71 | + expect(result).toBe(""); |
| 72 | + }); |
| 73 | + |
| 74 | + it("handles single element array", () => { |
| 75 | + const result = normalizeSuite(["suite1"]); |
| 76 | + expect(result).toBe("suite1"); |
| 77 | + }); |
| 78 | + |
| 79 | + it("handles empty string", () => { |
| 80 | + const result = normalizeSuite(""); |
| 81 | + expect(result).toBeUndefined(); |
| 82 | + }); |
| 83 | +}); |
| 84 | + |
| 85 | +describe("stripAnsi", () => { |
| 86 | + it("removes ANSI escape codes from a string", () => { |
| 87 | + const ansiString = "\u001b[31mHello\u001b[39m"; |
| 88 | + const result = stripAnsi(ansiString); |
| 89 | + expect(result).toBe("Hello"); |
| 90 | + }); |
| 91 | + |
| 92 | + it("returns the same string if no ANSI codes are present", () => { |
| 93 | + const normalString = "Just a normal string"; |
| 94 | + const result = stripAnsi(normalString); |
| 95 | + expect(result).toBe(normalString); |
| 96 | + }); |
| 97 | + |
| 98 | + it("handles empty strings correctly", () => { |
| 99 | + const emptyString = ""; |
| 100 | + const result = stripAnsi(emptyString); |
| 101 | + expect(result).toBe(""); |
| 102 | + }); |
| 103 | + |
| 104 | + it("throws a TypeError if the input is not a string", () => { |
| 105 | + // @ts-expect-error Testing runtime error |
| 106 | + expect(() => stripAnsi(123)).toThrow(TypeError); |
| 107 | + // @ts-expect-error Testing runtime error |
| 108 | + expect(() => stripAnsi(null)).toThrow(TypeError); |
| 109 | + // @ts-expect-error Testing runtime error |
| 110 | + expect(() => stripAnsi(undefined)).toThrow(TypeError); |
| 111 | + // @ts-expect-error Testing runtime error |
| 112 | + expect(() => stripAnsi({})).toThrow(TypeError); |
| 113 | + }); |
| 114 | +}); |
0 commit comments