-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest2.js
114 lines (105 loc) · 3.26 KB
/
test2.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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 expect = require('chai').expect;
const { mkdtemp, instantiatePythonWidgets } = require('./util');
describe('test2', () => {
describe('python', () => {
it('should generate all the files', () => {
let fname = path.resolve(__dirname, 'definitions', 'test2.py');
let outdir = null;
return mkdtemp('widget-gen')
.then((d) => {
outdir = d;
return run(fname, ['python'], { output: outdir });
})
.then(() => {
return fs.readdir(outdir);
})
.then((dirFiles) => {
return new Promise((resolve, reject) => {
try {
expect(dirFiles).to.eql(['A.py', 'B.py', '__init__.py']);
instantiatePythonWidgets(outdir);
} finally {
rimraf(outdir, (error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
}
});
});
});
});
describe('javascript', () => {
it('should generate all the files', () => {
let fname = path.resolve(__dirname, 'definitions', 'test2.py');
let outdir = null;
return mkdtemp('widget-gen')
.then((d) => {
outdir = d;
return run(fname, ['javascript'], { output: outdir });
})
.then(() => {
return fs.readdir(outdir);
})
.then((dirFiles) => {
return new Promise((resolve, reject) => {
try {
expect(dirFiles).to.eql(['A.js', 'B.js', 'index.js']);
} finally {
rimraf(outdir, (error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
}
});
});
});
it('should generate a single file with all the definitions', () => {
let fname = path.resolve(__dirname, 'definitions', 'test2.py');
let outdir = null;
let outfile = null;
return mkdtemp('widget-gen')
.then((d) => {
outdir = d;
outfile = path.join(outdir, 'widgets.js');
return run(fname, ['javascript'], { output: outfile });
})
.then(() => {
return fs.readdir(outdir);
})
.then((dirFiles) => {
return new Promise((resolve, reject) => {
try {
expect(dirFiles).to.eql(['widgets.js']);
const content = fs.readFileSync(outfile, { encoding: 'utf-8' });
const pattern = /^var (\w(\w|[_0-9])*)Model = (\w(\w|[_0-9])*)Model.extend\({$/gm;
const names = [];
let match;
while ((match = pattern.exec(content))) {
names.push(match[1]);
}
expect(names.sort()).to.eql(['A', 'B']);
} finally {
rimraf(outdir, (error) => {
if (error) {
reject(error);
} else {
resolve();
}
});
}
});
});
});
});
});