2018-08-27 21:04:15 +00:00
|
|
|
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';
|
2018-08-27 21:04:15 +00:00
|
|
|
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);
|
|
|
|
|
2023-03-06 17:45:20 +00:00
|
|
|
let hbs_testfilesDir = path.join(dirname, 'hbs_testfiles');
|
|
|
|
let testPartialDir = path.join(hbs_testfilesDir, '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 () => {
|
2018-08-27 21:04:15 +00:00
|
|
|
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 () => {
|
2023-03-06 17:45:20 +00:00
|
|
|
smarthbs.compileDirectory(hbs_testfilesDir, testResultDir, 'data.json');
|
2018-08-27 21:04:15 +00:00
|
|
|
});
|
2017-02-19 03:12:17 +00:00
|
|
|
|
2017-05-01 14:57:53 +00:00
|
|
|
tap.test('', async () => {
|
2018-08-27 21:04:15 +00:00
|
|
|
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');
|
2018-08-27 21:04:15 +00:00
|
|
|
});
|
2017-05-01 14:57:53 +00:00
|
|
|
|
|
|
|
tap.test('', async () => {
|
2018-08-27 21:04:15 +00:00
|
|
|
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',
|
|
|
|
},
|
|
|
|
},
|
2018-08-27 21:04:15 +00:00
|
|
|
});
|
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');
|
2018-08-27 21:04:15 +00:00
|
|
|
});
|
2017-05-01 14:57:53 +00:00
|
|
|
|
2018-08-27 21:04:15 +00:00
|
|
|
tap.start();
|