Marko v3: Allow compiler test to have a checkError() function

This commit is contained in:
Patrick Steele-Idem 2016-01-18 20:14:38 -07:00
parent 7c3bc9bc50
commit 307ddc1b06

View File

@ -5,14 +5,39 @@ chai.config.includeStack = true;
var path = require('path');
var compiler = require('../compiler');
var autotest = require('./autotest');
var fs = require('fs');
describe('compiler', function() {
var autoTestDir = path.join(__dirname, 'fixtures/compiler/autotest');
autotest.scanDir(autoTestDir, function run(dir) {
var templatePath = path.join(dir, 'template.marko');
var compiledSrc = compiler.compileFile(templatePath);
return compiledSrc;
var mainPath = path.join(dir, 'test.js');
var main;
if (fs.existsSync(mainPath)) {
main = require(mainPath);
}
if (main && main.checkError) {
var e;
try {
compiler.compileFile(templatePath);
} catch(_e) {
e = _e;
}
if (!e) {
throw new Error('Error expected');
}
main.checkError(e);
return '$PASS$';
} else {
var compiledSrc = compiler.compileFile(templatePath);
return compiledSrc;
}
});
});