forked from Dretch/typescript-declarations-for-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
40 lines (29 loc) · 1.25 KB
/
test.ts
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
/// <reference path="./lib/node-0.11.d.ts" />
/// <reference path="./lib/nodeunit.d.ts" />
import child_process = require('child_process');
import fs = require('fs');
import nodeunit = require('nodeunit');
// the first line of the output contains the date, so we can't compare it safely
function removeFirstLine(s: string):string {
var i = s.indexOf('\n');
return s.substring(i + 1);
}
exports.testGenerator = function(test: nodeunit.Test):void {
test.expect(1);
child_process.exec(
'tsc --module commonjs generator.ts && node generator.js ./test-data/jsduck ./test-data/actual-output.d.ts',
function(error, stdout, stderr) {
if (error !== null) {
console.error('Error calling generator: ' + stderr);
}
var actual = removeFirstLine(fs.readFileSync('./test-data/actual-output.d.ts', 'utf8')),
expected = removeFirstLine(fs.readFileSync('./test-data/expected-output.d.ts', 'utf8'));
// don't delete the output when it is wrong - we might need to inspect it
if (actual === expected) {
fs.unlinkSync('./test-data/actual-output.d.ts');
}
test.equal(actual, expected);
test.done();
}
);
};