From 4e21f1e548d63fe24b67222d266438cc741d9faf Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 3 Sep 2014 10:37:03 -0700 Subject: [PATCH 1/3] Import Definitlly typed unit tests into the RWC suite --- .gitignore | 1 + scripts/importDefinitllyTypedTests.ts | 124 ++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 scripts/importDefinitllyTypedTests.ts diff --git a/.gitignore b/.gitignore index af48864ed87..5e3e235ae1b 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ tests/services/baselines/prototyping/local/* tests/services/browser/typescriptServices.js scripts/processDiagnosticMessages.d.ts scripts/processDiagnosticMessages.js +scripts/importDefinitllyTypedTests.js src/harness/*.js rwc-report.html *.swp diff --git a/scripts/importDefinitllyTypedTests.ts b/scripts/importDefinitllyTypedTests.ts new file mode 100644 index 00000000000..caa6be0063a --- /dev/null +++ b/scripts/importDefinitllyTypedTests.ts @@ -0,0 +1,124 @@ +declare var require: any, process: any; +declare var __dirname: any; + +var fs = require("fs"); +var path = require("path"); +var child_process = require('child_process'); + +var tscRoot = path.join(__dirname, "..\\"); +var tscPath = path.join(tscRoot, "built", "instrumented", "tsc.js"); +var rwcTestPath = path.join(tscRoot, "tests", "cases", "rwc", "dt"); +var definitelyTypedRoot = process.argv[2]; + +function fileExtensionIs(path: string, extension: string): boolean { + var pathLen = path.length; + var extLen = extension.length; + return pathLen > extLen && path.substr(pathLen - extLen, extLen).toLocaleLowerCase() === extension.toLocaleLowerCase(); +} + +function copyFileSync(source, destination) { + var text = fs.readFileSync(source); + fs.writeFileSync(destination, text); +} + +function importDefinitelyTypedTest(testCaseName: string, testFiles: string[], responseFile: string ) { + var cmd = "node " + tscPath + " --module commonjs " + testFiles.join(" "); + if (responseFile) cmd += " @" + responseFile; + + var testDirectoryName = testCaseName + "_" + Math.floor((Math.random() * 10000) + 1); + var testDirectoryPath = path.join(process.env["temp"], testDirectoryName); + if (fs.existsSync(testDirectoryPath)) { + throw new Error("Could not create test directory"); + } + fs.mkdirSync(testDirectoryPath); + + child_process.exec(cmd, { + maxBuffer: 1 * 1024 * 1024, + cwd: testDirectoryPath + }, (error, stdout, stderr) => { + //console.log("importing " + testCaseName + " ..."); + //console.log(cmd); + + if (error) { + console.log("importing " + testCaseName + " ..."); + console.log(cmd); + console.log("==> error " + JSON.stringify(error)); + console.log("==> stdout " + String(stdout)); + console.log("==> stderr " + String(stderr)); + console.log("\r\n"); + return; + } + + // copy generated file to output location + var outputFilePath = path.join(testDirectoryPath, "iocapture0.json"); + var testCasePath = path.join(rwcTestPath, "DefinitelyTyped_" + testCaseName + ".json"); + copyFileSync(outputFilePath, testCasePath); + + //console.log("output generated at: " + outputFilePath); + + if (!fs.existsSync(testCasePath)) { + throw new Error("could not find test case at: " + testCasePath); + } + else { + fs.unlinkSync(outputFilePath); + fs.rmdirSync(testDirectoryPath); + //console.log("testcase generated at: " + testCasePath); + //console.log("Done."); + } + //console.log("\r\n"); + + }) + .on('error', function (error) { + console.log("==> error " + JSON.stringify(error)); + console.log("\r\n"); + }); +} + +function importDefinitelyTypedTests(definitelyTypedRoot: string): void { + fs.readdir(definitelyTypedRoot, (err, subDirectorys) => { + if (err) throw err; + + subDirectorys + .filter(d => ["_infrastructure", "node_modules", ".git"].indexOf(d) >= 0) + .filter(i => fs.statSync(path.join(definitelyTypedRoot, i)).isDirectory()) + .forEach(d => { + var directoryPath = path.join(definitelyTypedRoot, d); + fs.readdir(directoryPath, function (err, files) { + if (err) throw err; + + var tsFiles = []; + var testFiles = []; + var paramFile; + + files + .map(f => path.join(directoryPath, f)) + .forEach(f => { + if (fileExtensionIs(f, ".ts")) tsFiles.push(f); + else if (fileExtensionIs(f, ".tscparams")) paramFile = f; + + if (fileExtensionIs(f, "-tests.ts")) testFiles.push(f); + }); + + if (testFiles.length === 0) { + // no test files but multiple d.ts's, e.g. winjs + var regexp = new RegExp(d + "(([-][0-9])|([\.]d[\.]ts))"); + if (tsFiles.length > 1 && tsFiles.every(t => fileExtensionIs(t, ".d.ts") && regexp.test(t))) { + tsFiles.forEach(filename => { + importDefinitelyTypedTest(path.basename(filename, ".d.ts"), [filename], paramFile); + }); + } + else { + importDefinitelyTypedTest(d, tsFiles, paramFile); + } + } + else { + testFiles.forEach(filename => { + importDefinitelyTypedTest(path.basename(filename, "-tests.ts"), [filename], paramFile); + }); + } + }); + }) + }); +} + +importDefinitelyTypedTests(definitelyTypedRoot); \ No newline at end of file From 08130e0ba9bfc37abec740f747062cce362b7e4f Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 3 Sep 2014 10:37:32 -0700 Subject: [PATCH 2/3] increase the timeout for RWC tests --- Jakefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Jakefile b/Jakefile index b803f23eae8..a4341f8ed00 100644 --- a/Jakefile +++ b/Jakefile @@ -360,10 +360,15 @@ task("runtests", ["tests", builtLocalDirectory], function() { if(fs.existsSync(testConfigFile)) { fs.unlinkSync(testConfigFile); } + if(tests) { writeTestConfigFile(tests, testConfigFile); } + if (tests && tests.toLocaleLowerCase() === "rwc") { + testTimeout = 50000; + } + colors = process.env.colors || process.env.color colors = colors ? ' --no-colors ' : '' tests = tests ? ' -g ' + tests : ''; From c952750327ffc1e97ffbbf80008307d85e40c923 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Wed, 3 Sep 2014 13:10:31 -0700 Subject: [PATCH 3/3] Fix typo in file name --- .gitignore | 2 +- ...ortDefinitllyTypedTests.ts => importDefinitelyTypedTests.ts} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename scripts/{importDefinitllyTypedTests.ts => importDefinitelyTypedTests.ts} (100%) diff --git a/.gitignore b/.gitignore index 5e3e235ae1b..ebffa462811 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,7 @@ tests/services/baselines/prototyping/local/* tests/services/browser/typescriptServices.js scripts/processDiagnosticMessages.d.ts scripts/processDiagnosticMessages.js -scripts/importDefinitllyTypedTests.js +scripts/importDefinitelyTypedTests.js src/harness/*.js rwc-report.html *.swp diff --git a/scripts/importDefinitllyTypedTests.ts b/scripts/importDefinitelyTypedTests.ts similarity index 100% rename from scripts/importDefinitllyTypedTests.ts rename to scripts/importDefinitelyTypedTests.ts