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 Output ###
|
||||||
test/data/**/*.rt.actual.js
|
test/data/**/*.rt.actual.js
|
||||||
test/data/**/*.code.js
|
test/data/**/*.code.js
|
||||||
|
test/data/**/*.actual.html
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
// const _ = require('lodash');
|
|
||||||
const reactTemplates = require('../../src/reactTemplates');
|
const reactTemplates = require('../../src/reactTemplates');
|
||||||
const testUtils = require('./testUtils');
|
const testUtils = require('./testUtils');
|
||||||
const readFileNormalized = testUtils.readFileNormalized;
|
const readFileNormalized = testUtils.readFileNormalized;
|
||||||
const compareAndWriteHtml = testUtils.compareAndWriteHtml;
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fsUtil = require('../../src/fsUtil');
|
const fsUtil = require('../../src/fsUtil');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@ -35,7 +33,6 @@ module.exports = {
|
|||||||
'repeat-literal-collection.rt',
|
'repeat-literal-collection.rt',
|
||||||
'include.rt'
|
'include.rt'
|
||||||
];
|
];
|
||||||
// t.plan(files.length);
|
|
||||||
|
|
||||||
files.forEach(testFile => {
|
files.forEach(testFile => {
|
||||||
const filename = path.join(dataPath, testFile);
|
const filename = path.join(dataPath, testFile);
|
||||||
@ -43,21 +40,21 @@ module.exports = {
|
|||||||
readFileSync: fsUtil.createRelativeReadFileSync(filename),
|
readFileSync: fsUtil.createRelativeReadFileSync(filename),
|
||||||
modules: 'amd'
|
modules: 'amd'
|
||||||
};
|
};
|
||||||
let code = '';
|
let actual = '';
|
||||||
|
let equal = false;
|
||||||
try {
|
try {
|
||||||
const html = fs.readFileSync(filename).toString();
|
const html = fs.readFileSync(filename).toString();
|
||||||
const expected = testUtils.normalizeHtml(readFileNormalized(`${filename}.html`));
|
const expected = testUtils.normalizeHtml(readFileNormalized(filename + '.html'));
|
||||||
code = reactTemplates.convertTemplateToReact(html, options).replace(/\r/g, '');
|
const code = reactTemplates.convertTemplateToReact(html, options).replace(/\r/g, '');
|
||||||
const actual = testUtils.normalizeHtml(testUtils.codeToHtml(code));
|
actual = testUtils.normalizeHtml(testUtils.codeToHtml(code));
|
||||||
const equal = compareAndWriteHtml(t, actual, expected, filename);
|
equal = t.equal(actual, expected);
|
||||||
if (!equal) {
|
|
||||||
fs.writeFileSync(`${filename}.code.js`, code);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(testFile, e);
|
console.log(testFile, e);
|
||||||
fs.writeFileSync(`${filename}.code.js`, code);
|
|
||||||
t.fail(e);
|
t.fail(e);
|
||||||
}
|
}
|
||||||
|
if (!equal) {
|
||||||
|
fs.writeFileSync(filename + '.actual.html', actual);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -3,7 +3,7 @@ const rtStyle = require('../../src/rtStyle');
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
runTests(test) {
|
runTests(test) {
|
||||||
test('html tests', t => {
|
test('test rtStyle', t => {
|
||||||
const text = '.text { background-color: #00346E; padding: 3px; }';
|
const text = '.text { background-color: #00346E; padding: 3px; }';
|
||||||
const expected = '{\n "text": {\n "backgroundColor": "#00346E",\n "padding": 3\n }\n}';
|
const expected = '{\n "text": {\n "backgroundColor": "#00346E",\n "padding": 3\n }\n}';
|
||||||
const actual = rtStyle.convertBody(text);
|
const actual = rtStyle.convertBody(text);
|
||||||
|
@ -3,7 +3,7 @@ const test = require('tape');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const dataPath = path.resolve(__dirname, '..', 'data');
|
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
|
specs
|
||||||
.map(file => require(`./${file}.spec`))
|
.map(file => require(`./${file}.spec`))
|
||||||
|
@ -34,25 +34,6 @@ function compareAndWrite(t, actual, expected, filename) {
|
|||||||
return true;
|
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) {
|
function compareNodes(t, a, b, filename) {
|
||||||
_.forEach(a.attribs, (v, k) => {
|
_.forEach(a.attribs, (v, k) => {
|
||||||
if (v !== b.attribs[k]) {
|
if (v !== b.attribs[k]) {
|
||||||
@ -117,6 +98,5 @@ module.exports = {
|
|||||||
readFile,
|
readFile,
|
||||||
joinDataPath,
|
joinDataPath,
|
||||||
rtToHtml,
|
rtToHtml,
|
||||||
codeToHtml,
|
codeToHtml
|
||||||
compareAndWriteHtml
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user