Skip to content

Commit 552833a

Browse files
Copilotsilverwind
andcommitted
Simplify test to validate log line filtering behavior
Co-authored-by: silverwind <115237+silverwind@users.noreply.github.com>
1 parent 91d2ff8 commit 552833a

File tree

1 file changed

+54
-79
lines changed

1 file changed

+54
-79
lines changed

web_src/js/components/RepoActionView.test.ts

Lines changed: 54 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -18,93 +18,68 @@ function shouldHideLine(line: LogLine): boolean {
1818
return false;
1919
}
2020

21-
test('shouldHideLine filters workflow commands starting with ::add-matcher::', () => {
22-
const line: LogLine = {
23-
index: 1,
24-
timestamp: 1000,
25-
message: '::add-matcher::.github/problem-matcher.json',
26-
};
27-
expect(shouldHideLine(line)).toBe(true);
28-
});
29-
30-
test('shouldHideLine filters workflow commands starting with ##[add-matcher]', () => {
31-
const line: LogLine = {
32-
index: 2,
33-
timestamp: 1001,
34-
message: '##[add-matcher].github/eslint.json',
35-
};
36-
expect(shouldHideLine(line)).toBe(true);
37-
});
21+
// Simulate the filtering behavior of appendLogs
22+
function filterLogLines(logLines: LogLine[]): LogLine[] {
23+
return logLines.filter((line) => !shouldHideLine(line));
24+
}
3825

39-
test('shouldHideLine filters workflow commands starting with ::workflow-command', () => {
40-
const line: LogLine = {
41-
index: 3,
42-
timestamp: 1002,
43-
message: '::workflow-command::some-command',
44-
};
45-
expect(shouldHideLine(line)).toBe(true);
46-
});
26+
test('filters workflow command lines from log output', () => {
27+
// Input: log lines including workflow commands that should be hidden
28+
const inputLogLines: LogLine[] = [
29+
{index: 1, timestamp: 1000, message: 'Starting build process'},
30+
{index: 2, timestamp: 1001, message: '::add-matcher::.github/problem-matcher.json'},
31+
{index: 3, timestamp: 1002, message: 'Running tests...'},
32+
{index: 4, timestamp: 1003, message: '##[add-matcher].github/eslint.json'},
33+
{index: 5, timestamp: 1004, message: 'Test suite started'},
34+
{index: 6, timestamp: 1005, message: '::workflow-command::echo some-output'},
35+
{index: 7, timestamp: 1006, message: 'All tests passed'},
36+
{index: 8, timestamp: 1007, message: '::remove-matcher::owner=eslint'},
37+
{index: 9, timestamp: 1008, message: 'Build complete'},
38+
];
4739

48-
test('shouldHideLine filters workflow commands starting with ::remove-matcher', () => {
49-
const line: LogLine = {
50-
index: 4,
51-
timestamp: 1003,
52-
message: '::remove-matcher::owner=eslint',
53-
};
54-
expect(shouldHideLine(line)).toBe(true);
55-
});
40+
// Expected output: only non-workflow-command lines
41+
const expectedVisibleMessages = [
42+
'Starting build process',
43+
'Running tests...',
44+
'Test suite started',
45+
'All tests passed',
46+
'Build complete',
47+
];
5648

57-
test('shouldHideLine does not filter normal log lines', () => {
58-
const line: LogLine = {
59-
index: 5,
60-
timestamp: 1004,
61-
message: 'Normal log line without workflow commands',
62-
};
63-
expect(shouldHideLine(line)).toBe(false);
64-
});
49+
// Filter the lines
50+
const visibleLines = filterLogLines(inputLogLines);
6551

66-
test('shouldHideLine does not filter lines with workflow commands not at the start', () => {
67-
const line: LogLine = {
68-
index: 6,
69-
timestamp: 1005,
70-
message: 'Some text before ::add-matcher:: in the middle',
71-
};
72-
expect(shouldHideLine(line)).toBe(false);
73-
});
52+
// Assert the correct number of lines are visible
53+
expect(visibleLines.length).toBe(5);
7454

75-
test('shouldHideLine handles group commands (should not hide them)', () => {
76-
const groupLine: LogLine = {
77-
index: 7,
78-
timestamp: 1006,
79-
message: '::group::Build Step',
80-
};
81-
expect(shouldHideLine(groupLine)).toBe(false);
55+
// Assert the visible lines contain the expected messages
56+
const visibleMessages = visibleLines.map((line) => line.message);
57+
expect(visibleMessages).toEqual(expectedVisibleMessages);
8258

83-
const endGroupLine: LogLine = {
84-
index: 8,
85-
timestamp: 1007,
86-
message: '::endgroup::',
87-
};
88-
expect(shouldHideLine(endGroupLine)).toBe(false);
59+
// Assert that workflow command lines are not in the output
60+
expect(visibleMessages).not.toContain('::add-matcher::.github/problem-matcher.json');
61+
expect(visibleMessages).not.toContain('##[add-matcher].github/eslint.json');
62+
expect(visibleMessages).not.toContain('::workflow-command::echo some-output');
63+
expect(visibleMessages).not.toContain('::remove-matcher::owner=eslint');
8964
});
9065

91-
test('shouldHideLine handles various log formats', () => {
92-
const testCases = [
93-
{message: '::add-matcher::', expected: true},
94-
{message: '##[add-matcher]', expected: true},
95-
{message: '::workflow-command', expected: true},
96-
{message: '::remove-matcher', expected: true},
97-
{message: 'Build started', expected: false},
98-
{message: 'Error: test failed', expected: false},
99-
{message: ' ::add-matcher::.github/test.json', expected: false}, // with leading space
66+
test('preserves non-workflow command lines including group commands', () => {
67+
const inputLogLines: LogLine[] = [
68+
{index: 1, timestamp: 1000, message: 'Normal log line'},
69+
{index: 2, timestamp: 1001, message: '::group::Installation'},
70+
{index: 3, timestamp: 1002, message: 'Installing dependencies'},
71+
{index: 4, timestamp: 1003, message: '::add-matcher::.github/npm.json'},
72+
{index: 5, timestamp: 1004, message: '::endgroup::'},
73+
{index: 6, timestamp: 1005, message: 'Done'},
10074
];
10175

102-
for (const [index, {message, expected}] of testCases.entries()) {
103-
const line: LogLine = {
104-
index: index + 10,
105-
timestamp: 2000 + index,
106-
message,
107-
};
108-
expect(shouldHideLine(line)).toBe(expected);
109-
}
76+
const visibleLines = filterLogLines(inputLogLines);
77+
78+
// Should have 5 lines (all except the ::add-matcher:: line)
79+
expect(visibleLines.length).toBe(5);
80+
81+
const visibleMessages = visibleLines.map((line) => line.message);
82+
expect(visibleMessages).toContain('::group::Installation');
83+
expect(visibleMessages).toContain('::endgroup::');
84+
expect(visibleMessages).not.toContain('::add-matcher::.github/npm.json');
11085
});

0 commit comments

Comments
 (0)