44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7- import assert from 'node:assert' ;
87import { describe , it } from 'node:test' ;
98
109import {
@@ -15,129 +14,82 @@ import type {ConsoleMessageData} from '../../src/McpResponse.js';
1514
1615describe ( 'consoleFormatter' , ( ) => {
1716 describe ( 'formatConsoleEventShort' , ( ) => {
18- it ( 'formats a console.log message' , ( ) => {
17+ it ( 'formats a console.log message' , t => {
1918 const message : ConsoleMessageData = {
2019 consoleMessageStableId : 1 ,
2120 type : 'log' ,
2221 message : 'Hello, world!' ,
2322 args : [ ] ,
2423 } ;
2524 const result = formatConsoleEventShort ( message ) ;
26- assert . equal ( result , 'msgid=1 [log] Hello, world!' ) ;
25+ t . assert . snapshot ?. ( result ) ;
2726 } ) ;
2827
29- it ( 'formats a console.log message with one argument' , ( ) => {
28+ it ( 'formats a console.log message with one argument' , t => {
3029 const message : ConsoleMessageData = {
3130 consoleMessageStableId : 2 ,
3231 type : 'log' ,
3332 message : 'Processing file:' ,
3433 args : [ 'file.txt' ] ,
3534 } ;
3635 const result = formatConsoleEventShort ( message ) ;
37- assert . equal ( result , 'msgid=2 [log] Processing file: Args: file.txt' ) ;
36+ t . assert . snapshot ?. ( result ) ;
3837 } ) ;
3938
40- it ( 'formats a console.log message with multiple arguments' , ( ) => {
39+ it ( 'formats a console.log message with multiple arguments' , t => {
4140 const message : ConsoleMessageData = {
4241 consoleMessageStableId : 3 ,
4342 type : 'log' ,
4443 message : 'Processing file:' ,
4544 args : [ 'file.txt' , 'another file' ] ,
4645 } ;
4746 const result = formatConsoleEventShort ( message ) ;
48- assert . equal ( result , 'msgid=3 [log] Processing file: Args: file.txt ...' ) ;
49- } ) ;
50-
51- it ( 'does not include args if message is the same as arg' , ( ) => {
52- const message : ConsoleMessageData = {
53- consoleMessageStableId : 4 ,
54- type : 'log' ,
55- message : 'Hello' ,
56- args : [ 'Hello' ] ,
57- } ;
58- const result = formatConsoleEventShort ( message ) ;
59- assert . equal ( result , 'msgid=4 [log] Hello' ) ;
47+ t . assert . snapshot ?.( result ) ;
6048 } ) ;
6149 } ) ;
6250
6351 describe ( 'formatConsoleEventVerbose' , ( ) => {
64- it ( 'formats a console.log message' , ( ) => {
52+ it ( 'formats a console.log message' , t => {
6553 const message : ConsoleMessageData = {
6654 consoleMessageStableId : 1 ,
6755 type : 'log' ,
6856 message : 'Hello, world!' ,
6957 args : [ ] ,
7058 } ;
7159 const result = formatConsoleEventVerbose ( message ) ;
72- assert . equal (
73- result ,
74- `Log> Hello, world!
75- ID: 1
76- Type: log` ,
77- ) ;
60+ t . assert . snapshot ?.( result ) ;
7861 } ) ;
7962
80- it ( 'formats a console.log message with one argument' , ( ) => {
63+ it ( 'formats a console.log message with one argument' , t => {
8164 const message : ConsoleMessageData = {
8265 consoleMessageStableId : 2 ,
8366 type : 'log' ,
8467 message : 'Processing file:' ,
8568 args : [ 'file.txt' ] ,
8669 } ;
8770 const result = formatConsoleEventVerbose ( message ) ;
88- assert . equal (
89- result ,
90- `Log> Processing file: Args: file.txt
91- ID: 2
92- Type: log` ,
93- ) ;
71+ t . assert . snapshot ?.( result ) ;
9472 } ) ;
9573
96- it ( 'formats a console.log message with multiple arguments' , ( ) => {
74+ it ( 'formats a console.log message with multiple arguments' , t => {
9775 const message : ConsoleMessageData = {
9876 consoleMessageStableId : 3 ,
9977 type : 'log' ,
10078 message : 'Processing file:' ,
10179 args : [ 'file.txt' , 'another file' ] ,
10280 } ;
10381 const result = formatConsoleEventVerbose ( message ) ;
104- assert . equal (
105- result ,
106- `Log> Processing file: Args: file.txt another file
107- ID: 3
108- Type: log` ,
109- ) ;
82+ t . assert . snapshot ?.( result ) ;
11083 } ) ;
11184
112- it ( 'formats a console.error message' , ( ) => {
85+ it ( 'formats a console.error message' , t => {
11386 const message : ConsoleMessageData = {
11487 consoleMessageStableId : 4 ,
11588 type : 'error' ,
11689 message : 'Something went wrong' ,
11790 } ;
11891 const result = formatConsoleEventVerbose ( message ) ;
119- assert . equal (
120- result ,
121- `Error> Something went wrong
122- ID: 4
123- Type: error` ,
124- ) ;
125- } ) ;
126-
127- it ( 'does not include args if message is the same as arg' , ( ) => {
128- const message : ConsoleMessageData = {
129- consoleMessageStableId : 5 ,
130- type : 'log' ,
131- message : 'Hello' ,
132- args : [ 'Hello' , 'World' ] ,
133- } ;
134- const result = formatConsoleEventVerbose ( message ) ;
135- assert . equal (
136- result ,
137- `Log> Hello Args: World
138- ID: 5
139- Type: log` ,
140- ) ;
92+ t . assert . snapshot ?.( result ) ;
14193 } ) ;
14294 } ) ;
14395} ) ;
0 commit comments