@@ -8,6 +8,14 @@ const { codes: {
88 ERR_INVALID_ARG_TYPE
99} } = require ( '../errors' ) ;
1010
11+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
12+ function endsWith ( str , search , this_len ) {
13+ if ( this_len === undefined || this_len > str . length ) {
14+ this_len = str . length ;
15+ }
16+ return str . substring ( this_len - search . length , this_len ) === search ;
17+ }
18+
1119let blue = '' ;
1220let green = '' ;
1321let red = '' ;
@@ -230,7 +238,7 @@ function createErrDiff(actual, expected, operator) {
230238 // a trailing comma. In that case it is actually identical and we should
231239 // mark it as such.
232240 let divergingLines = actualLine !== expectedLine &&
233- ( ! actualLine . endsWith ( ',' ) ||
241+ ( ! endsWith ( actualLine , ',' ) ||
234242 actualLine . slice ( 0 , - 1 ) !== expectedLine ) ;
235243 // If the expected line has a trailing comma but is otherwise identical,
236244 // add a comma at the end of the actual line. Otherwise the output could
@@ -242,7 +250,7 @@ function createErrDiff(actual, expected, operator) {
242250 // ]
243251 //
244252 if ( divergingLines &&
245- expectedLine . endsWith ( ',' ) &&
253+ endsWith ( expectedLine , ',' ) &&
246254 expectedLine . slice ( 0 , - 1 ) === actualLine ) {
247255 divergingLines = false ;
248256 actualLine += ',' ;
0 commit comments