player-yaml-html/test/index.js

29 lines
1.1 KiB
JavaScript
Raw Normal View History

const tape = require('tape')
const path = require('path')
const fs = require('fs')
const yamlToJson = require('../lib/yaml-to-json')
const jsonToHtml = require('../lib/json-to-html')
tape('test yaml to json', assert => {
const txt = fs.readFileSync(path.join(__dirname, 'fixtures', 'playlist.yml'), 'utf8')
const jsonData = yamlToJson(txt)
const expectedJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', 'expected-json.json'), 'utf8'))
assert.deepEqual(jsonData, expectedJson, 'json parsed as expected')
// console.log(JSON.stringify(jsonData, null, 2))
assert.end()
})
tape('test json to html', assert => {
const jsonData = JSON.parse(fs.readFileSync(path.join(__dirname, 'fixtures', 'expected-json.json'), 'utf8'))
const html = jsonToHtml(jsonData)
const expectedHtml = fs.readFileSync(path.join(__dirname, 'fixtures', 'expected-html.html'), 'utf8')
assert.equal(html.trim(), expectedHtml.trim(), 'html as expected')
assert.end()
})
// const filename = process.argv[1]
// const yamlTxt = fs.readFileSync(filename, 'utf-8')
// console.log(jsonToHtml(yamlToJson(yamlTxt)))