Skip to content

Commit

Permalink
Fails test if evaluator source text has errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Jun 7, 2018
1 parent 473ba53 commit f5adadb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/harness/evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -30,6 +35,14 @@ namespace evaluator {
function evaluate(result: compiler.CompilationResult, globals?: Record<string, any>) {
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);

Expand Down
12 changes: 6 additions & 6 deletions src/harness/unittests/evaluation/forAwaitOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ describe("forAwaitOfEvaluation", () => {
it("sync (es5)", async () => {
const result = evaluator.evaluateTypeScript(`
let i = 0;
const iterator = {
const iterator: IterableIterator<any> = {
[Symbol.iterator]() { return this; },
next() {
switch (i++) {
Expand All @@ -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);
Expand All @@ -28,7 +28,7 @@ describe("forAwaitOfEvaluation", () => {
it("sync (es2015)", async () => {
const result = evaluator.evaluateTypeScript(`
let i = 0;
const iterator = {
const iterator: IterableIterator<any> = {
[Symbol.iterator]() { return this; },
next() {
switch (i++) {
Expand All @@ -55,7 +55,7 @@ describe("forAwaitOfEvaluation", () => {
const result = evaluator.evaluateTypeScript(`
let i = 0;
const iterator = {
[Symbol.asyncIterator]() { return this; },
[Symbol.asyncIterator](): AsyncIterableIterator<any> { return this; },
async next() {
switch (i++) {
case 0: return { value: 1, done: false };
Expand All @@ -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);
Expand All @@ -81,7 +81,7 @@ describe("forAwaitOfEvaluation", () => {
const result = evaluator.evaluateTypeScript(`
let i = 0;
const iterator = {
[Symbol.asyncIterator]() { return this; },
[Symbol.asyncIterator](): AsyncIterableIterator<any> { return this; },
async next() {
switch (i++) {
case 0: return { value: 1, done: false };
Expand Down

0 comments on commit f5adadb

Please sign in to comment.