diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 2886c43f091..797bc12a42b 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -419,6 +419,16 @@ class ProjectRunner extends RunnerBase { // }) //}); } + + after(() => { + // Mocha holds onto the closure environment of the describe callback even after the test is done. + // Therefore we have to clean out large objects after the test is done. + nodeCompilerResult = undefined; + amdCompilerResult = undefined; + testCase = undefined; + testFileText = undefined; + testCaseJustName = undefined; + }); }); } } \ No newline at end of file diff --git a/src/harness/rwcRunner.ts b/src/harness/rwcRunner.ts index a9d90409d4b..882620a69da 100644 --- a/src/harness/rwcRunner.ts +++ b/src/harness/rwcRunner.ts @@ -46,143 +46,162 @@ module RWC { } export function runRWCTest(jsonPath: string) { - var harnessCompiler = Harness.Compiler.getCompiler(); - var opts: ts.ParsedCommandLine; + describe("Testing a RWC project: " + jsonPath, () => { + var harnessCompiler = Harness.Compiler.getCompiler(); + var opts: ts.ParsedCommandLine; - var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath)); - var errors = ''; + var ioLog: IOLog = JSON.parse(Harness.IO.readFile(jsonPath)); + var errors = ''; - it('has parsable options', () => { - runWithIOLog(ioLog, () => { - opts = ts.parseCommandLine(ioLog.arguments); - assert.equal(opts.errors.length, 0); - }); - }); - - var inputFiles: { unitName: string; content: string; }[] = []; - var otherFiles: { unitName: string; content: string; }[] = []; - var compilerResult: Harness.Compiler.CompilerResult; - var compilerOptions: ts.CompilerOptions; - it('can compile', () => { - runWithIOLog(ioLog, () => { - harnessCompiler.reset(); - - // Load the files - ts.forEach(opts.filenames, fileName => { - inputFiles.push(getHarnessCompilerInputUnit(fileName)); - }); - - if (!opts.options.noLib) { - // Find the lib.d.ts file in the input file and add it to the input files list - var libFile = ts.forEach(ioLog.filesRead, fileRead=> Harness.isLibraryFile(fileRead.path) ? fileRead.path : undefined); - if (libFile) { - inputFiles.push(getHarnessCompilerInputUnit(libFile)); - } - } - - ts.forEach(ioLog.filesRead, fileRead => { - var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileRead.path)); - var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath); - if (!inInputList) { - // Add the file to other files - otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); - } - }); - - // do not use lib since we already read it in above - opts.options.noLib = true; - - // Emit the results - compilerOptions = harnessCompiler.compileFiles(inputFiles, otherFiles, compileResult => { - compilerResult = compileResult; - }, /*settingsCallback*/ undefined, opts.options); + after(() => { + // Mocha holds onto the closure environment of the describe callback even after the test is done. + // Therefore we have to clean out large objects after the test is done. + harnessCompiler = undefined; + opts = undefined; + ioLog = undefined; + errors = undefined; + inputFiles = undefined; + otherFiles = undefined; + compilerResult = undefined; + compilerOptions = undefined; + baselineOpts = undefined; + baseName = undefined; + declFileCompilationResult = undefined; }); - function getHarnessCompilerInputUnit(fileName: string) { - var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileName)); - try { - var content = sys.readFile(resolvedPath); + + it('has parsable options', () => { + runWithIOLog(ioLog, () => { + opts = ts.parseCommandLine(ioLog.arguments); + assert.equal(opts.errors.length, 0); + }); + }); + + var inputFiles: { unitName: string; content: string; }[] = []; + var otherFiles: { unitName: string; content: string; }[] = []; + var compilerResult: Harness.Compiler.CompilerResult; + var compilerOptions: ts.CompilerOptions; + it('can compile', () => { + runWithIOLog(ioLog, () => { + harnessCompiler.reset(); + + // Load the files + ts.forEach(opts.filenames, fileName => { + inputFiles.push(getHarnessCompilerInputUnit(fileName)); + }); + + if (!opts.options.noLib) { + // Find the lib.d.ts file in the input file and add it to the input files list + var libFile = ts.forEach(ioLog.filesRead, fileRead=> Harness.isLibraryFile(fileRead.path) ? fileRead.path : undefined); + if (libFile) { + inputFiles.push(getHarnessCompilerInputUnit(libFile)); + } + } + + ts.forEach(ioLog.filesRead, fileRead => { + var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileRead.path)); + var inInputList = ts.forEach(inputFiles, inputFile=> inputFile.unitName === resolvedPath); + if (!inInputList) { + // Add the file to other files + otherFiles.push(getHarnessCompilerInputUnit(fileRead.path)); + } + }); + + // do not use lib since we already read it in above + opts.options.noLib = true; + + // Emit the results + compilerOptions = harnessCompiler.compileFiles(inputFiles, otherFiles, compileResult => { + compilerResult = compileResult; + }, /*settingsCallback*/ undefined, opts.options); + }); + + function getHarnessCompilerInputUnit(fileName: string) { + var resolvedPath = Harness.Path.switchToForwardSlashes(sys.resolvePath(fileName)); + try { + var content = sys.readFile(resolvedPath); + } + catch (e) { + // Leave content undefined. + } + return { unitName: resolvedPath, content: content }; } - catch (e) { - // Leave content undefined. - } - return { unitName: resolvedPath, content: content }; - } - }); + }); - // Baselines - var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' }; - var baseName = /(.*)\/(.*).json/.exec(Harness.Path.switchToForwardSlashes(jsonPath))[2]; + // Baselines + var baselineOpts: Harness.Baseline.BaselineOptions = { Subfolder: 'rwc' }; + var baseName = /(.*)\/(.*).json/.exec(Harness.Path.switchToForwardSlashes(jsonPath))[2]; - // Compile .d.ts files - var declFileCompilationResult: { - declInputFiles: { unitName: string; content: string }[]; - declOtherFiles: { unitName: string; content: string }[]; - declResult: Harness.Compiler.CompilerResult; - }; - it('Correct compiler generated.d.ts', () => { - declFileCompilationResult = harnessCompiler.compileDeclarationFiles(inputFiles, otherFiles, compilerResult, /*settingscallback*/ undefined, compilerOptions); - }); + // Compile .d.ts files + var declFileCompilationResult: { + declInputFiles: { unitName: string; content: string }[]; + declOtherFiles: { unitName: string; content: string }[]; + declResult: Harness.Compiler.CompilerResult; + }; + it('Correct compiler generated.d.ts', () => { + declFileCompilationResult = harnessCompiler.compileDeclarationFiles(inputFiles, otherFiles, compilerResult, /*settingscallback*/ undefined, compilerOptions); + }); - it('has the expected emitted code', () => { - Harness.Baseline.runBaseline('has the expected emitted code', baseName + '.output.js', () => { - return collateOutputs(compilerResult.files, s => SyntacticCleaner.clean(s)); - }, false, baselineOpts); - }); - - it('has the expected declaration file content', () => { - Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => { - if (compilerResult.errors.length || !compilerResult.declFilesCode.length) { - return null; - } - return collateOutputs(compilerResult.declFilesCode); - }, false, baselineOpts); - }); - - it('has the expected source maps', () => { - Harness.Baseline.runBaseline('has the expected source maps', baseName + '.map', () => { - if (!compilerResult.sourceMaps.length) { - return null; - } - - return collateOutputs(compilerResult.sourceMaps); - }, false, baselineOpts); - }); - - it('has correct source map record', () => { - if (compilerOptions.sourceMap) { - Harness.Baseline.runBaseline('has correct source map record', baseName + '.sourcemap.txt', () => { - return compilerResult.getSourceMapRecord(); + it('has the expected emitted code', () => { + Harness.Baseline.runBaseline('has the expected emitted code', baseName + '.output.js', () => { + return collateOutputs(compilerResult.files, s => SyntacticCleaner.clean(s)); }, false, baselineOpts); - } - }); + }); - it('has the expected errors', () => { - Harness.Baseline.runBaseline('has the expected errors', baseName + '.errors.txt', () => { - if (compilerResult.errors.length === 0) { - return null; - } + it('has the expected declaration file content', () => { + Harness.Baseline.runBaseline('has the expected declaration file content', baseName + '.d.ts', () => { + if (compilerResult.errors.length || !compilerResult.declFilesCode.length) { + return null; + } + return collateOutputs(compilerResult.declFilesCode); + }, false, baselineOpts); + }); - return Harness.Compiler.getErrorBaseline(inputFiles.concat(otherFiles), compilerResult.errors); - }, false, baselineOpts); - }); - - it('has no errors in generated declaration files', () => { - if (compilerOptions.declaration && !compilerResult.errors.length) { - Harness.Baseline.runBaseline('has no errors in generated declaration files', baseName + '.dts.errors.txt', () => { - if (declFileCompilationResult.declResult.errors.length === 0) { + it('has the expected source maps', () => { + Harness.Baseline.runBaseline('has the expected source maps', baseName + '.map', () => { + if (!compilerResult.sourceMaps.length) { return null; } - return Harness.Compiler.minimalDiagnosticsToString(declFileCompilationResult.declResult.errors) + - sys.newLine + sys.newLine + - Harness.Compiler.getErrorBaseline(declFileCompilationResult.declInputFiles.concat(declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.errors); + return collateOutputs(compilerResult.sourceMaps); }, false, baselineOpts); - } - }); + }); - // TODO: Type baselines (need to refactor out from compilerRunner) + it('has correct source map record', () => { + if (compilerOptions.sourceMap) { + Harness.Baseline.runBaseline('has correct source map record', baseName + '.sourcemap.txt', () => { + return compilerResult.getSourceMapRecord(); + }, false, baselineOpts); + } + }); + + it('has the expected errors', () => { + Harness.Baseline.runBaseline('has the expected errors', baseName + '.errors.txt', () => { + if (compilerResult.errors.length === 0) { + return null; + } + + return Harness.Compiler.getErrorBaseline(inputFiles.concat(otherFiles), compilerResult.errors); + }, false, baselineOpts); + }); + + it('has no errors in generated declaration files', () => { + if (compilerOptions.declaration && !compilerResult.errors.length) { + Harness.Baseline.runBaseline('has no errors in generated declaration files', baseName + '.dts.errors.txt', () => { + if (declFileCompilationResult.declResult.errors.length === 0) { + return null; + } + + return Harness.Compiler.minimalDiagnosticsToString(declFileCompilationResult.declResult.errors) + + sys.newLine + sys.newLine + + Harness.Compiler.getErrorBaseline(declFileCompilationResult.declInputFiles.concat(declFileCompilationResult.declOtherFiles), declFileCompilationResult.declResult.errors); + }, false, baselineOpts); + } + }); + + // TODO: Type baselines (need to refactor out from compilerRunner) + }); } } @@ -208,8 +227,6 @@ class RWCRunner extends RunnerBase { } private runTest(jsonFilename: string) { - describe("Testing a RWC project: " + jsonFilename, () => { - RWC.runRWCTest(jsonFilename); - }); + RWC.runRWCTest(jsonFilename); } } \ No newline at end of file