-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathconsoleFormatter.test.ts
More file actions
133 lines (121 loc) · 3.89 KB
/
consoleFormatter.test.ts
File metadata and controls
133 lines (121 loc) · 3.89 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
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
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {describe, it} from 'node:test';
import type {ConsoleMessageData} from '../../src/formatters/consoleFormatter.js';
import {
formatConsoleEventShort,
formatConsoleEventVerbose,
} from '../../src/formatters/consoleFormatter.js';
import {getMockAggregatedIssue} from '../utils.js';
describe('consoleFormatter', () => {
describe('formatConsoleEventShort', () => {
it('formats a console.log message', t => {
const message: ConsoleMessageData = {
consoleMessageStableId: 1,
type: 'log',
message: 'Hello, world!',
args: [],
};
const result = formatConsoleEventShort(message);
t.assert.snapshot?.(result);
});
it('formats a console.log message with one argument', t => {
const message: ConsoleMessageData = {
consoleMessageStableId: 2,
type: 'log',
message: 'Processing file:',
args: ['file.txt'],
};
const result = formatConsoleEventShort(message);
t.assert.snapshot?.(result);
});
it('formats a console.log message with multiple arguments', t => {
const message: ConsoleMessageData = {
consoleMessageStableId: 3,
type: 'log',
message: 'Processing file:',
args: ['file.txt', 'another file'],
};
const result = formatConsoleEventShort(message);
t.assert.snapshot?.(result);
});
});
describe('formatConsoleEventVerbose', () => {
it('formats a console.log message', t => {
const message: ConsoleMessageData = {
consoleMessageStableId: 1,
type: 'log',
message: 'Hello, world!',
args: [],
};
const result = formatConsoleEventVerbose(message);
t.assert.snapshot?.(result);
});
it('formats a console.log message with one argument', t => {
const message: ConsoleMessageData = {
consoleMessageStableId: 2,
type: 'log',
message: 'Processing file:',
args: ['file.txt'],
};
const result = formatConsoleEventVerbose(message);
t.assert.snapshot?.(result);
});
it('formats a console.log message with multiple arguments', t => {
const message: ConsoleMessageData = {
consoleMessageStableId: 3,
type: 'log',
message: 'Processing file:',
args: ['file.txt', 'another file'],
};
const result = formatConsoleEventVerbose(message);
t.assert.snapshot?.(result);
});
it('formats a console.error message', t => {
const message: ConsoleMessageData = {
consoleMessageStableId: 4,
type: 'error',
message: 'Something went wrong',
};
const result = formatConsoleEventVerbose(message);
t.assert.snapshot?.(result);
});
});
it('formats a console.log message with issue type', t => {
const testGenericIssue = {
details: () => {
return {
violatingNodeId: 2,
violatingNodeAttribute: 'test',
};
},
};
const mockAggregatedIssue = getMockAggregatedIssue();
const mockDescription = {
file: 'mock.md',
links: [
{link: 'http://example.com/learnmore', linkTitle: 'Learn more'},
{
link: 'http://example.com/another-learnmore',
linkTitle: 'Learn more 2',
},
],
};
mockAggregatedIssue.getDescription.returns(mockDescription);
// @ts-expect-error generic issue stub bypass
mockAggregatedIssue.getGenericIssues.returns(new Set([testGenericIssue]));
const mockDescriptionFileContent =
'# Mock Issue Title\n\nThis is a mock issue description';
const message: ConsoleMessageData = {
consoleMessageStableId: 5,
type: 'issue',
description: mockDescriptionFileContent,
item: mockAggregatedIssue,
};
const result = formatConsoleEventVerbose(message);
t.assert.snapshot?.(result);
});
});