|
|
|
|
@ -4,7 +4,7 @@ import glob from 'tiny-glob/sync';
|
|
|
|
|
import * as path from 'path';
|
|
|
|
|
import * as fs from 'fs';
|
|
|
|
|
import * as colors from 'kleur';
|
|
|
|
|
export const assert = (assert$1 as unknown) as typeof assert$1 & { htmlEqual: (actual, expected, message?) => void };
|
|
|
|
|
export const assert = (assert$1 as unknown) as typeof assert$1 & { htmlEqual: (actual, expected, message?) => void, htmlEqualWithComments: (actual, expected, message?) => void };
|
|
|
|
|
|
|
|
|
|
// for coverage purposes, we need to test source files,
|
|
|
|
|
// but for sanity purposes, we need to test dist files
|
|
|
|
|
@ -118,6 +118,9 @@ function cleanChildren(node) {
|
|
|
|
|
node.removeChild(child);
|
|
|
|
|
child = previous;
|
|
|
|
|
}
|
|
|
|
|
} else if (child.nodeType === 8) {
|
|
|
|
|
// comment
|
|
|
|
|
// do nothing
|
|
|
|
|
} else {
|
|
|
|
|
cleanChildren(child);
|
|
|
|
|
}
|
|
|
|
|
@ -137,11 +140,11 @@ function cleanChildren(node) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function normalizeHtml(window, html) {
|
|
|
|
|
export function normalizeHtml(window, html, preserveComments = false) {
|
|
|
|
|
try {
|
|
|
|
|
const node = window.document.createElement('div');
|
|
|
|
|
node.innerHTML = html
|
|
|
|
|
.replace(/<!--.*?-->/g, '')
|
|
|
|
|
.replace(/(<!--.*?-->)/g, preserveComments ? '$1' : '')
|
|
|
|
|
.replace(/>[\s\r\n]+</g, '><')
|
|
|
|
|
.trim();
|
|
|
|
|
cleanChildren(node);
|
|
|
|
|
@ -162,6 +165,14 @@ export function setupHtmlEqual() {
|
|
|
|
|
message
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
// eslint-disable-next-line no-import-assign
|
|
|
|
|
assert.htmlEqualWithComments = (actual, expected, message) => {
|
|
|
|
|
assert.deepEqual(
|
|
|
|
|
normalizeHtml(window, actual, true),
|
|
|
|
|
normalizeHtml(window, expected, true),
|
|
|
|
|
message
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function loadConfig(file) {
|
|
|
|
|
|