2017-05-01 14:57:53 +00:00
|
|
|
import { expect, tap } from 'tapbundle'
|
2017-02-19 03:12:17 +00:00
|
|
|
import * as smarthbs from '../dist/index'
|
|
|
|
import * as path from 'path'
|
|
|
|
|
|
|
|
let testHbsDir = path.join(__dirname, 'hbs_testfiles')
|
|
|
|
let testPartialDir = path.join(testHbsDir, 'partials')
|
2017-05-01 14:57:53 +00:00
|
|
|
let testResultDir = path.join(__dirname, 'testresult')
|
2017-05-10 14:55:25 +00:00
|
|
|
|
2017-05-01 14:57:53 +00:00
|
|
|
tap.test('smarthbs -> should create partials', async () => {
|
|
|
|
await smarthbs.registerPartialDir(testPartialDir)
|
|
|
|
})
|
2017-02-19 03:12:17 +00:00
|
|
|
|
2017-05-01 14:57:53 +00:00
|
|
|
tap.test('smarthbs -> should compile a directory', async () => {
|
|
|
|
smarthbs.compileDirectory(testHbsDir, testResultDir, 'data.json')
|
|
|
|
})
|
2017-02-19 03:12:17 +00:00
|
|
|
|
2017-05-01 14:57:53 +00:00
|
|
|
tap.test('', async () => {
|
|
|
|
let templateString = '{{{firstVar}}} {{secondVar}}'
|
|
|
|
let templateVars = await smarthbs.findVarsInHbsString(templateString)
|
|
|
|
expect(templateVars).to.include('firstVar')
|
|
|
|
expect(templateVars).to.include('secondVar')
|
|
|
|
})
|
|
|
|
|
|
|
|
tap.test('', async () => {
|
|
|
|
let templateString = '{{{firstVar}}} {{secondVar}} {{thirdVar}} {{fourthVar}} {{fourthVar.someKey}} {{fourthVar.otherKey.nextKey}}'
|
|
|
|
let missingVars = await smarthbs.checkVarsSatisfaction(templateString, {
|
|
|
|
firstVar: 'hi',
|
|
|
|
secondVar: 'hello',
|
|
|
|
fourthVar: {
|
|
|
|
otherKey: {
|
|
|
|
nextKey: 'wow'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
expect(missingVars).to.contain('thirdVar', 'fourthVar.someKey')
|
|
|
|
expect(missingVars).to.not.contain('secondVar', 'fourthVar.otherKey.nextKey')
|
|
|
|
})
|
|
|
|
|
|
|
|
tap.start()
|