Riven/riven/srcgen/node_modules/dot/test/process.test.js
Mingwei Samuel 74eb5fa045 Update example proxy for v2, use workspaces.
- `example/proxy` is new folder for `example_proxy`.
- `riven` is new folder for the main riven lib.
- Updated metadata to be an array and include HTTP method.
2021-09-09 14:31:39 -07:00

59 lines
1.5 KiB
JavaScript

'use strict';
var assert = require('assert');
var doT = require('..');
var fs = require('fs');
describe('doT.process', function() {
beforeEach(function() {
removeCompiledTemplateFiles();
});
afterEach(function() {
removeCompiledTemplateFiles();
});
function removeCompiledTemplateFiles() {
try { fs.unlinkSync('./test/templates/test.js'); } catch(e) {}
}
it('should compile all templates in folder', function() {
const templates = doT.process({path: './test/templates'});
var str = templates.test({data: 2});
assert.equal(str, '21');
var js = fs.statSync('./test/templates/test.js');
assert.ok(js.isFile());
// code below passes if the test is run without coverage using `npm run test-spec`
// because source code of doT.encodeHTMLSource is used inside compiled templates
// var fn = require('./templates/test.js');
// var str = fn({data: 2});
// assert.equal(str, '21');
});
it('should ignore varname with polluted object prototype', function() {
var currentLog = console.log;
console.log = log;
var logged;
Object.prototype.templateSettings = {varname: 'it=(console.log("executed"),{})'};
try {
const templates = doT.process({path: './test/templates'});
assert.notEqual(logged, 'executed');
// injected code can only be executed if undefined is passed to template function
templates.test();
assert.notEqual(logged, 'executed');
} finally {
console.log = currentLog;
}
function log(str) {
logged = str;
}
});
});