088e61812a
- tests are not compiled with babel and must thus be in es5 - we don't use polyfills, so we need to make sure no functions aren't used that are not supported by popular browsers. (like Object.assign in Safari and IE11) - Boths are errors that usually only appear when running tests in SauceLabs, which happens only on _after_ merging a PR.
37 lines
919 B
JavaScript
37 lines
919 B
JavaScript
require('./common');
|
|
|
|
var fs = require('fs'),
|
|
vm = require('vm');
|
|
|
|
global.Handlebars = 'no-conflict';
|
|
|
|
var filename = 'dist/handlebars.js';
|
|
if (global.minimizedTest) {
|
|
filename = 'dist/handlebars.min.js';
|
|
}
|
|
var distHandlebars = fs.readFileSync(require.resolve('../../' + filename), 'utf-8');
|
|
vm.runInThisContext(distHandlebars, filename);
|
|
|
|
global.CompilerContext = {
|
|
browser: true,
|
|
|
|
compile: function(template, options) {
|
|
var templateSpec = handlebarsEnv.precompile(template, options);
|
|
return handlebarsEnv.template(safeEval(templateSpec));
|
|
},
|
|
compileWithPartial: function(template, options) {
|
|
return handlebarsEnv.compile(template, options);
|
|
}
|
|
};
|
|
|
|
function safeEval(templateSpec) {
|
|
/* eslint-disable no-eval, no-console */
|
|
try {
|
|
return eval('(' + templateSpec + ')');
|
|
} catch (err) {
|
|
console.error(templateSpec);
|
|
throw err;
|
|
}
|
|
/* eslint-enable no-eval, no-console */
|
|
}
|