From f3fc45f1195ddd03b0f7a967884ee1b670e9c9eb Mon Sep 17 00:00:00 2001 From: Antonino Porcino Date: Tue, 2 Aug 2016 16:44:17 +0200 Subject: [PATCH] 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 --- .gitignore | 2 ++ test/src/rt-html-valid.spec.js | 21 +++++++++------------ test/src/rtStyle.spec.js | 2 +- test/src/test.js | 2 +- test/src/testUtils.js | 22 +--------------------- 5 files changed, 14 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 714ce61..46833c1 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ npm-debug.log ### Test Output ### test/data/**/*.rt.actual.js test/data/**/*.code.js +test/data/**/*.actual.html + diff --git a/test/src/rt-html-valid.spec.js b/test/src/rt-html-valid.spec.js index 9e23832..853b6a9 100644 --- a/test/src/rt-html-valid.spec.js +++ b/test/src/rt-html-valid.spec.js @@ -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(); }); diff --git a/test/src/rtStyle.spec.js b/test/src/rtStyle.spec.js index 3235b81..e33f581 100644 --- a/test/src/rtStyle.spec.js +++ b/test/src/rtStyle.spec.js @@ -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); diff --git a/test/src/test.js b/test/src/test.js index 12cd47b..7ed3b56 100644 --- a/test/src/test.js +++ b/test/src/test.js @@ -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`)) diff --git a/test/src/testUtils.js b/test/src/testUtils.js index 593af2c..c54a1b4 100644 --- a/test/src/testUtils.js +++ b/test/src/testUtils.js @@ -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 };