-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_custom_template.js
61 lines (53 loc) · 1.57 KB
/
test_custom_template.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
require('source-map-support').install();
const run = require('../lib/run').run;
const rimraf = require('rimraf');
const path = require('path');
const fs = require('fs-extra');
const os = require('os');
const expect = require('chai').expect;
function mkdtemp(prefix) {
return fs.mkdtemp(path.join(os.tmpdir(), prefix));
}
describe('custom template', () => {
it('should generate all the files', () => {
let fname = path.resolve(__dirname, 'definitions', 'test2.py');
let tname = path.resolve(__dirname, 'custom_template.njk');
let outdir = null;
return mkdtemp('widget-gen')
.then((d) => {
outdir = d;
return run(fname, ['ts'], {
output: outdir,
templateFile: tname,
});
})
.then(() => {
return fs.readdir(outdir);
})
.then((dirFiles) => {
return new Promise((resolve, reject) => {
try {
expect(dirFiles).to.eql(['A.ts', 'B.ts', 'index.ts']);
const pattern = /^ {4}this\.foo = 42;$/m;
dirFiles.forEach((fn) => {
if (fn === 'index.ts') {
return;
}
const content = fs.readFileSync(path.join(outdir, fn), {
encoding: 'utf-8',
});
expect(pattern.test(content), `file: ${fn}`).to.eql(true);
});
} finally {
rimraf(outdir, (error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
}
});
});
});
});