react-templates/test/src/rt-html-valid.unit.js

64 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-06-29 09:47:09 +02:00
'use strict'
const reactTemplates = require('../../src/reactTemplates')
2017-06-29 13:48:33 +02:00
const testUtils = require('./utils/testUtils')
2017-06-29 09:47:09 +02:00
const readFileNormalized = testUtils.readFileNormalized
const path = require('path')
const fsUtil = require('../../src/fsUtil')
const fs = require('fs')
2017-06-29 13:48:33 +02:00
const assert = require('assert')
2017-06-29 09:47:09 +02:00
2017-06-29 13:48:33 +02:00
const files = [
'scope.rt',
'scope-trailing-semicolon.rt',
'scope-variable-references.rt',
'lambda.rt',
'eval.rt',
'props.rt',
'custom-element.rt',
'style.rt',
'concat.rt',
'js-in-attr.rt',
'props-class.rt',
'rt-class.rt',
'className.rt',
'svg.rt',
'virtual.rt',
'scope-evaluated-after-repeat.rt',
'scope-evaluated-after-repeat2.rt',
'scope-evaluated-after-if.rt',
'scope-obj.rt',
'scope-reserved-tokens.rt',
'repeat-literal-collection.rt',
'include.rt'
]
2017-06-29 09:47:09 +02:00
2017-06-29 13:48:33 +02:00
describe('utils', () => {
describe('#convertText', () => {
it('should convert text successfully', () => {
const dataPath = path.resolve(__dirname, '..', 'data')
2017-06-29 09:47:09 +02:00
files.forEach(testFile => {
const filename = path.join(dataPath, testFile)
const options = {
readFileSync: fsUtil.createRelativeReadFileSync(filename),
modules: 'amd'
}
let actual = ''
let equal = false
try {
const html = fs.readFileSync(filename).toString()
2018-02-06 14:34:52 +01:00
const expected = testUtils.normalizeHtml(readFileNormalized(`${filename}.html`))
2017-06-29 09:47:09 +02:00
const code = reactTemplates.convertTemplateToReact(html, options).replace(/\r/g, '')
actual = testUtils.normalizeHtml(testUtils.codeToHtml(code))
2017-06-29 13:48:33 +02:00
equal = assert.equal(actual, expected, `${testFile}`)
2017-06-29 09:47:09 +02:00
} catch (e) {
console.log(testFile, e)
2017-06-29 13:48:33 +02:00
assert.fail(e)
2017-06-29 09:47:09 +02:00
}
if (!equal) {
2018-02-06 14:34:52 +01:00
fs.writeFileSync(`${filename}.actual.html`, actual)
2017-06-29 09:47:09 +02:00
}
})
})
2017-06-29 13:48:33 +02:00
})
})