From 6575d930fcef27bad248c62c03a675af3b99609d Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 4 Jun 2018 17:05:46 -0700 Subject: [PATCH] Fails test if evaluator source text has errors --- src/harness/evaluator.ts | 15 ++++++++++++++- src/harness/unittests/evaluation/forAwaitOf.ts | 12 ++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/harness/evaluator.ts b/src/harness/evaluator.ts index 793fb800f6..168fda1d76 100644 --- a/src/harness/evaluator.ts +++ b/src/harness/evaluator.ts @@ -6,7 +6,12 @@ namespace evaluator { function compile(sourceText: string, options?: ts.CompilerOptions) { const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false); fs.writeFileSync(sourceFile, sourceText); - const compilerOptions: ts.CompilerOptions = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS, lib: ["lib.esnext.d.ts"], ...options }; + const compilerOptions: ts.CompilerOptions = { + target: ts.ScriptTarget.ES5, + module: ts.ModuleKind.CommonJS, + lib: ["lib.esnext.d.ts", "lib.dom.d.ts"], + ...options + }; const host = new fakes.CompilerHost(fs, compilerOptions); return compiler.compileFiles(host, [sourceFile], compilerOptions); } @@ -30,6 +35,14 @@ namespace evaluator { function evaluate(result: compiler.CompilationResult, globals?: Record) { globals = { Symbol: FakeSymbol, ...globals }; + if (ts.some(result.diagnostics)) { + assert.ok(/*value*/ false, "Syntax error in evaluation source text:\n" + ts.formatDiagnostics(result.diagnostics, { + getCanonicalFileName: file => file, + getCurrentDirectory: () => "", + getNewLine: () => "\n" + })); + } + const output = result.getOutput(sourceFile, "js")!; assert.isDefined(output); diff --git a/src/harness/unittests/evaluation/forAwaitOf.ts b/src/harness/unittests/evaluation/forAwaitOf.ts index 066b8daf0d..20ab5eed0c 100644 --- a/src/harness/unittests/evaluation/forAwaitOf.ts +++ b/src/harness/unittests/evaluation/forAwaitOf.ts @@ -2,7 +2,7 @@ describe("forAwaitOfEvaluation", () => { it("sync (es5)", async () => { const result = evaluator.evaluateTypeScript(` let i = 0; - const iterator = { + const iterator: IterableIterator = { [Symbol.iterator]() { return this; }, next() { switch (i++) { @@ -18,7 +18,7 @@ describe("forAwaitOfEvaluation", () => { for await (const item of iterator) { output.push(item); } - }`); + }`, { downlevelIteration: true }); await result.main(); assert.strictEqual(result.output[0], 1); assert.strictEqual(result.output[1], 2); @@ -28,7 +28,7 @@ describe("forAwaitOfEvaluation", () => { it("sync (es2015)", async () => { const result = evaluator.evaluateTypeScript(` let i = 0; - const iterator = { + const iterator: IterableIterator = { [Symbol.iterator]() { return this; }, next() { switch (i++) { @@ -55,7 +55,7 @@ describe("forAwaitOfEvaluation", () => { const result = evaluator.evaluateTypeScript(` let i = 0; const iterator = { - [Symbol.asyncIterator]() { return this; }, + [Symbol.asyncIterator](): AsyncIterableIterator { return this; }, async next() { switch (i++) { case 0: return { value: 1, done: false }; @@ -70,7 +70,7 @@ describe("forAwaitOfEvaluation", () => { for await (const item of iterator) { output.push(item); } - }`); + }`, { downlevelIteration: true }); await result.main(); assert.strictEqual(result.output[0], 1); assert.instanceOf(result.output[1], Promise); @@ -81,7 +81,7 @@ describe("forAwaitOfEvaluation", () => { const result = evaluator.evaluateTypeScript(` let i = 0; const iterator = { - [Symbol.asyncIterator]() { return this; }, + [Symbol.asyncIterator](): AsyncIterableIterator { return this; }, async next() { switch (i++) { case 0: return { value: 1, done: false };