mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Marko v3: Allow compiler test to have a checkError() function
This commit is contained in:
parent
7c3bc9bc50
commit
307ddc1b06
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user