From f5adadb42ad497d81ad30f19567adbf75f56426b 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 793fb800f6ae0..168fda1d7670e 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 b02a45860b909..ece32e2426740 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 };