'use strict'; const DIR = __dirname + '/../../', COMMONDIR = DIR + 'common/', TMPLDIR = DIR + 'tmpl/', Util = require(COMMONDIR + 'util'), CloudFunc = require(COMMONDIR + 'cloudfunc'), files = require('files-io'), test = require('tape'), FS_DIR = TMPLDIR + 'fs/', EXPECT_PATH = __dirname + '/cloudfunc.html', TMPL_PATH = [ 'file', 'path', 'pathLink', 'link', ], JSON_FILES = { path : '/etc/X11/', files : [{ name: 'applnk', size: 'dir', date: '21.02.2016', uid : 0, mode: 'rwx r-x r-x' }, { name: 'prefdm', size: '1.30kb', date: '21.02.2016', uid : 0, mode: 'rwx r-x r-x' }] }; let Expect = '
' + '' + '' + '' + '' + '/' + '' + 'etc' + '/X11/' + '' + '
'; test('render', (t) => { const paths = {}; const filesList = TMPL_PATH .map((name) => { const path = FS_DIR + name + '.hbs'; paths[path] = name; return path; }) .concat(EXPECT_PATH); files.read(filesList, 'utf8', (error, files) => { const template = {}; if (error) throw(Error(error)); Util.time('CloudFunc.buildFromJSON'); Object.keys(files).forEach((path) => { const name = paths[path]; if (path !== EXPECT_PATH) template[name] = files[path]; }); const expect = files[EXPECT_PATH]; const result = CloudFunc.buildFromJSON({ prefix : '', data : JSON_FILES, template: template }); Expect += expect; let i; const isNotOk = Expect .split('') .some((item, number) => { const ret = result[number] !== item; if (ret) { i = number; } return ret; }); Util.timeEnd('CloudFunc.buildFromJSON'); if (isNotOk) { console.log( `Error in char number: ${i}\n`, `Expect: ${Expect.substr(i)}\n`, `Result: ${result.substr(i)}` ); console.log('buildFromJSON: Not OK'); } t.equal(Expect, result, 'should be equal rendered json data'); t.end(); }); });