smarthbs/test/test.ts

47 lines
1.5 KiB
TypeScript
Raw Normal View History

import { expect, tap } from '@pushrocks/tapbundle';
2022-07-24 13:30:19 +00:00
import * as smarthbs from '../ts/index.js';
import * as smartpath from '@pushrocks/smartpath';
import * as path from 'path';
2017-02-19 03:12:17 +00:00
2022-07-24 13:30:19 +00:00
const dirname = smartpath.get.dirnameFromImportMetaUrl(import.meta.url);
let testHbsDir = path.join(dirname, 'hbs_testfiles');
let testPartialDir = path.join(testHbsDir, 'partials');
2022-07-24 13:30:19 +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);
2022-07-24 13:30:19 +00:00
expect(templateVars).toContain('firstVar');
expect(templateVars).toContain('secondVar');
});
2017-05-01 14:57:53 +00:00
tap.test('', async () => {
let templateString =
'{{{firstVar}}} {{secondVar}} {{thirdVar}} {{fourthVar}} {{fourthVar.someKey}} {{fourthVar.otherKey.nextKey}}';
2017-05-01 14:57:53 +00:00
let missingVars = await smarthbs.checkVarsSatisfaction(templateString, {
firstVar: 'hi',
secondVar: 'hello',
fourthVar: {
otherKey: {
2022-07-24 13:30:19 +00:00
nextKey: 'wow',
},
},
});
2022-07-24 13:30:19 +00:00
expect(missingVars).toContain('thirdVar');
expect(missingVars).toContain('fourthVar.someKey');
expect(missingVars).not.toContain('secondVar');
expect(missingVars).not.toContain('fourthVar.otherKey.nextKey');
});
2017-05-01 14:57:53 +00:00
tap.start();