mirror of
https://github.com/bobwen-dev/react-templates
synced 2025-04-12 00:56:39 +02:00
fixed broken html tests
Fixed html tests that were not running due to changed file name. Failing html tests now dump "actual" html instead of the code that generates it (.actual.html) Fixed title for rtStyle tests Removed compareAndWriteHtml() that is no longer needed
This commit is contained in:
parent
8623963796
commit
f3fc45f119
2
.gitignore
vendored
2
.gitignore
vendored
@ -27,3 +27,5 @@ npm-debug.log
|
||||
### Test Output ###
|
||||
test/data/**/*.rt.actual.js
|
||||
test/data/**/*.code.js
|
||||
test/data/**/*.actual.html
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
'use strict';
|
||||
// const _ = require('lodash');
|
||||
const reactTemplates = require('../../src/reactTemplates');
|
||||
const testUtils = require('./testUtils');
|
||||
const readFileNormalized = testUtils.readFileNormalized;
|
||||
const compareAndWriteHtml = testUtils.compareAndWriteHtml;
|
||||
const path = require('path');
|
||||
const fsUtil = require('../../src/fsUtil');
|
||||
const fs = require('fs');
|
||||
@ -35,7 +33,6 @@ module.exports = {
|
||||
'repeat-literal-collection.rt',
|
||||
'include.rt'
|
||||
];
|
||||
// t.plan(files.length);
|
||||
|
||||
files.forEach(testFile => {
|
||||
const filename = path.join(dataPath, testFile);
|
||||
@ -43,21 +40,21 @@ module.exports = {
|
||||
readFileSync: fsUtil.createRelativeReadFileSync(filename),
|
||||
modules: 'amd'
|
||||
};
|
||||
let code = '';
|
||||
let actual = '';
|
||||
let equal = false;
|
||||
try {
|
||||
const html = fs.readFileSync(filename).toString();
|
||||
const expected = testUtils.normalizeHtml(readFileNormalized(`${filename}.html`));
|
||||
code = reactTemplates.convertTemplateToReact(html, options).replace(/\r/g, '');
|
||||
const actual = testUtils.normalizeHtml(testUtils.codeToHtml(code));
|
||||
const equal = compareAndWriteHtml(t, actual, expected, filename);
|
||||
if (!equal) {
|
||||
fs.writeFileSync(`${filename}.code.js`, code);
|
||||
}
|
||||
const expected = testUtils.normalizeHtml(readFileNormalized(filename + '.html'));
|
||||
const code = reactTemplates.convertTemplateToReact(html, options).replace(/\r/g, '');
|
||||
actual = testUtils.normalizeHtml(testUtils.codeToHtml(code));
|
||||
equal = t.equal(actual, expected);
|
||||
} catch (e) {
|
||||
console.log(testFile, e);
|
||||
fs.writeFileSync(`${filename}.code.js`, code);
|
||||
t.fail(e);
|
||||
}
|
||||
if (!equal) {
|
||||
fs.writeFileSync(filename + '.actual.html', actual);
|
||||
}
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
@ -3,7 +3,7 @@ const rtStyle = require('../../src/rtStyle');
|
||||
|
||||
module.exports = {
|
||||
runTests(test) {
|
||||
test('html tests', t => {
|
||||
test('test rtStyle', t => {
|
||||
const text = '.text { background-color: #00346E; padding: 3px; }';
|
||||
const expected = '{\n "text": {\n "backgroundColor": "#00346E",\n "padding": 3\n }\n}';
|
||||
const actual = rtStyle.convertBody(text);
|
||||
|
@ -3,7 +3,7 @@ const test = require('tape');
|
||||
const path = require('path');
|
||||
const dataPath = path.resolve(__dirname, '..', 'data');
|
||||
|
||||
const specs = ['rt.invalid', 'rt.valid', 'utils', 'shell', 'rtStyle', 'fsUtil'];
|
||||
const specs = ['rt.invalid', 'rt.valid', 'rt-html-valid', 'utils', 'shell', 'rtStyle', 'fsUtil'];
|
||||
|
||||
specs
|
||||
.map(file => require(`./${file}.spec`))
|
||||
|
@ -34,25 +34,6 @@ function compareAndWrite(t, actual, expected, filename) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {*} t
|
||||
* @param {string} actual
|
||||
* @param {string} expected
|
||||
* @param {string} filename
|
||||
* @return {boolean} whether actual is equal to expected
|
||||
*/
|
||||
function compareAndWriteHtml(t, actual, expected, filename) {
|
||||
const $actual = cheerio.load(actual, {normalizeWhitespace: true});
|
||||
const $expected = cheerio.load(expected, {normalizeWhitespace: true});
|
||||
compareNodesList(t, $actual.root(), $expected.root(), filename);
|
||||
// t.equal(actual, expected, filename);
|
||||
// if (actual !== expected) {
|
||||
// fs.writeFileSync(filename + '.actual.js', actual);
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
}
|
||||
|
||||
function compareNodes(t, a, b, filename) {
|
||||
_.forEach(a.attribs, (v, k) => {
|
||||
if (v !== b.attribs[k]) {
|
||||
@ -117,6 +98,5 @@ module.exports = {
|
||||
readFile,
|
||||
joinDataPath,
|
||||
rtToHtml,
|
||||
codeToHtml,
|
||||
compareAndWriteHtml
|
||||
codeToHtml
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user