mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
extract code from test
This commit is contained in:
parent
56b8f58bb7
commit
008d370fe0
44
test/src/util.js
Normal file
44
test/src/util.js
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
'use strict';
|
||||||
|
var cheerio = require('cheerio');
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} html
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
function normalizeHtml(html) {
|
||||||
|
return cheerio.load(html, {normalizeWhitespace: true}).html()
|
||||||
|
.replace(/>\s+/mg, '>')
|
||||||
|
.replace(/\s+</mg, '<')
|
||||||
|
.replace(/>\s+</mg, '><');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {*} t
|
||||||
|
* @param {string} actual
|
||||||
|
* @param {string} expected
|
||||||
|
* @param {string} filename
|
||||||
|
* @return {boolean} whether actual is equal to expected
|
||||||
|
*/
|
||||||
|
function compareAndWrite(t, actual, expected, filename) {
|
||||||
|
t.equal(actual, expected, filename);
|
||||||
|
if (actual !== expected) {
|
||||||
|
fs.writeFileSync(filename + '.actual.js', actual);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} filename
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
function readFileNormalized(filename) {
|
||||||
|
return fs.readFileSync(filename).toString().replace(/\r/g, '').trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
normalizeHtml: normalizeHtml,
|
||||||
|
compareAndWrite: compareAndWrite,
|
||||||
|
readFileNormalized: readFileNormalized
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user