@@ -4,7 +4,7 @@ import glob from 'tiny-glob/sync';
44import * as path from 'path' ;
55import * as fs from 'fs' ;
66import * as colors from 'kleur' ;
7- export const assert = ( assert$1 as unknown ) as typeof assert$1 & { htmlEqual : ( actual , expected , message ?) => void , htmlEqualWithComments : ( actual , expected , message ?) => void } ;
7+ export const assert = ( assert$1 as unknown ) as typeof assert$1 & { htmlEqual : ( actual , expected , message ?) => void , htmlEqualWithOptions : ( actual , expected , options , message ?) => void } ;
88
99// for coverage purposes, we need to test source files,
1010// but for sanity purposes, we need to test dist files
@@ -140,7 +140,7 @@ function cleanChildren(node) {
140140 }
141141}
142142
143- export function normalizeHtml ( window , html , { removeDataSvelte = false , preserveComments = false } : { removeDataSvelte ?: boolean , preserveComments ?: boolean } = { } ) {
143+ export function normalizeHtml ( window , html , { removeDataSvelte = false , preserveComments = false } : { removeDataSvelte ?: boolean , preserveComments ?: boolean } ) {
144144 try {
145145 const node = window . document . createElement ( 'div' ) ;
146146 node . innerHTML = html
@@ -155,7 +155,12 @@ export function normalizeHtml(window, html, { removeDataSvelte = false, preserve
155155 }
156156}
157157
158- export function setupHtmlEqual ( options ?: { removeDataSvelte ?: boolean } ) {
158+ export function normalizeNewline ( html : string ) {
159+ // return html.trim().replace(/\r\n/g, '\n')
160+ return html . replace ( / \r \n / g, '\n' ) ;
161+ }
162+
163+ export function setupHtmlEqual ( options : { removeDataSvelte ?: boolean } = { } ) {
159164 const window = env ( ) ;
160165
161166 // eslint-disable-next-line no-import-assign
@@ -167,10 +172,14 @@ export function setupHtmlEqual(options?: { removeDataSvelte?: boolean }) {
167172 ) ;
168173 } ;
169174 // eslint-disable-next-line no-import-assign
170- assert . htmlEqualWithComments = ( actual , expected , message ) => {
175+ assert . htmlEqualWithOptions = ( actual , expected , { preserveComments , withoutNormalizeHtml } , message ) => {
171176 assert . deepEqual (
172- normalizeHtml ( window , actual , { ...options , preserveComments : true } ) ,
173- normalizeHtml ( window , expected , { ...options , preserveComments : true } ) ,
177+ withoutNormalizeHtml
178+ ? normalizeNewline ( actual ) . replace ( / ( \s d a t a - s v e l t e = " [ ^ " ] + " ) / g, options . removeDataSvelte ? '' : '$1' )
179+ : normalizeHtml ( window , actual , { ...options , preserveComments } ) ,
180+ withoutNormalizeHtml
181+ ? normalizeNewline ( expected ) . replace ( / ( \s d a t a - s v e l t e = " [ ^ " ] + " ) / g, options . removeDataSvelte ? '' : '$1' )
182+ : normalizeHtml ( window , expected , { ...options , preserveComments } ) ,
174183 message
175184 ) ;
176185 } ;
0 commit comments