forked from marko-js/marko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
widgets-compilation-tests.js
62 lines (50 loc) · 2.03 KB
/
widgets-compilation-tests.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require('./util/patch-module');
var fs = require('fs');
var path = require('path');
var testFilter = require('./util/autotest/test-filter');
var compiler = require('marko/compiler');
var expect = require('chai').expect;
require('marko/node-require').install();
describe('marko-widgets (compilation)', function() {
var testsPath = path.join(__dirname, './autotests/widgets-compilation');
var tests = fs.readdirSync(testsPath);
tests.forEach(function(testName) {
var itFunc = testFilter.isOnlyTest(testName) ? it.only : it;
itFunc('[' + testName + '] ', function(done) {
var testPath = path.join(testsPath, testName);
var templatePath = path.join(testPath, 'index.marko');
if (!fs.existsSync(templatePath)) {
templatePath = path.join(testPath, 'template.marko');
if (!fs.existsSync(templatePath)) {
return done(new Error('Template not found for test'));
}
}
var mainPath = path.join(testPath, '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);
done();
} else {
var actualSrc = compiler.compileFile(templatePath, main && main.compilerOptions);
var actualPath = path.join(testPath, './actual.js');
var expectedPath = path.join(testPath, './expected.js');
fs.writeFileSync(actualPath, actualSrc);
var expectedSrc = fs.readFileSync(expectedPath, 'utf-8');
expect(actualSrc).to.equal(expectedSrc);
done();
}
});
});
});