Created
July 30, 2015 18:29
-
-
Save RyanCavanaugh/8ab57044691c08b1c226 to your computer and use it in GitHub Desktop.
Faster DefinitelyTyped test script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="node_modules/typescript/bin/typescriptServices.d.ts" /> | |
/// <reference path="node/node.d.ts" /> | |
import fs = require('fs'); | |
let libdts = 'node_modules/typescript/bin/lib.d.ts'; | |
eval(fs.readFileSync('node_modules/typescript/bin/typescriptServices.js', 'utf-8')); | |
function runTestFolder(dir: string) { | |
let files = fs.readdirSync(dir); | |
let testFiles = files.filter(f => /\.ts$/.test(f) && !/\.d\.ts$/.test(f)); | |
testFiles.forEach(test => { | |
test = dir + '/' + test; | |
console.log('Run test ' + test); | |
let tscParams = test + '.tscparams'; | |
let opts = ts.getDefaultCompilerOptions(); | |
opts.module = ts.ModuleKind.CommonJS; | |
opts.target = ts.ScriptTarget.ES5; | |
let files = [test]; | |
if (fs.existsSync(tscParams)) { | |
let content = fs.readFileSync(tscParams, 'utf-8'); | |
let cmdLine = ts.parseCommandLine(content.split(/ /g)); | |
opts = cmdLine.options; | |
} | |
let prog = ts.createProgram([test, libdts], opts); | |
let diags = prog.getSemanticDiagnostics(); | |
prog.getSourceFiles().forEach(s => { | |
diags = diags.concat(prog.getSyntacticDiagnostics(s)); | |
diags = diags.concat(prog.getSemanticDiagnostics(s)); | |
}); | |
diags.forEach(d => { | |
console.log(' ' + ts.flattenDiagnosticMessageText(d.messageText, '\r\n')); | |
}); | |
}); | |
} | |
fs.readdir('.', (err, files) => { | |
// files = files.filter(f => f.indexOf('react') >= 0); | |
files.forEach(file => { | |
if(!(file.substr(0, 1) === '_') && fs.lstatSync(file).isDirectory()) { | |
runTestFolder(file); | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment