MCPcopy
hub / github.com/jestjs/jest / convertAnsi

Function convertAnsi

packages/jest-snapshot/src/__tests__/printSnapshot.test.ts:71–132  ·  view source on GitHub ↗
(val: string)

Source from the content-addressed store, hash-verified

69);
70
71const convertAnsi = (val: string): string => {
72 // Trailing spaces in common lines have yellow background color.
73 let isYellowBackground = false;
74
75 return val.replace(ansiRegex(), match => {
76 switch (match) {
77 case styles.inverse.open:
78 return '<i>';
79 case styles.inverse.close:
80 return '</i>';
81
82 case styles.bold.open:
83 return '<b>';
84 case styles.dim.open:
85 return '<d>';
86 case styles.bold.close:
87 case styles.dim.close:
88 return '</>';
89
90 case styles.green.open:
91 return '<g>';
92 case aOpenForeground1:
93 case aOpenForeground2:
94 case aOpenForeground3:
95 return '<m>';
96 case styles.red.open:
97 return '<r>';
98 case bOpenForeground1:
99 case bOpenForeground2:
100 case bOpenForeground3:
101 return '<t>'; // teal/cyan/aqua
102 case styles.yellow.open:
103 return '<y>';
104 case styles.cyan.close:
105 case styles.green.close:
106 case styles.magenta.close:
107 case styles.red.close:
108 case styles.yellow.close:
109 return '</>';
110
111 case styles.bgYellow.open:
112 isYellowBackground = true;
113 return '<Y>';
114
115 case aOpenBackground1:
116 case bOpenBackground1:
117 case aOpenBackground2:
118 case bOpenBackground2:
119 case aOpenBackground3:
120 case bOpenBackground3:
121 isYellowBackground = false;
122 return '';
123
124 case styles.bgYellow.close:
125 // The same code closes any background color.
126 return isYellowBackground ? '</Y>' : '';
127
128 default:

Callers 2

serializeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected