Skip to content

Commit 6575d93

Browse files
committed
Fails test if evaluator source text has errors
1 parent a14f034 commit 6575d93

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/harness/evaluator.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ namespace evaluator {
66
function compile(sourceText: string, options?: ts.CompilerOptions) {
77
const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false);
88
fs.writeFileSync(sourceFile, sourceText);
9-
const compilerOptions: ts.CompilerOptions = { target: ts.ScriptTarget.ES5, module: ts.ModuleKind.CommonJS, lib: ["lib.esnext.d.ts"], ...options };
9+
const compilerOptions: ts.CompilerOptions = {
10+
target: ts.ScriptTarget.ES5,
11+
module: ts.ModuleKind.CommonJS,
12+
lib: ["lib.esnext.d.ts", "lib.dom.d.ts"],
13+
...options
14+
};
1015
const host = new fakes.CompilerHost(fs, compilerOptions);
1116
return compiler.compileFiles(host, [sourceFile], compilerOptions);
1217
}
@@ -30,6 +35,14 @@ namespace evaluator {
3035
function evaluate(result: compiler.CompilationResult, globals?: Record<string, any>) {
3136
globals = { Symbol: FakeSymbol, ...globals };
3237

38+
if (ts.some(result.diagnostics)) {
39+
assert.ok(/*value*/ false, "Syntax error in evaluation source text:\n" + ts.formatDiagnostics(result.diagnostics, {
40+
getCanonicalFileName: file => file,
41+
getCurrentDirectory: () => "",
42+
getNewLine: () => "\n"
43+
}));
44+
}
45+
3346
const output = result.getOutput(sourceFile, "js")!;
3447
assert.isDefined(output);
3548

src/harness/unittests/evaluation/forAwaitOf.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ describe("forAwaitOfEvaluation", () => {
22
it("sync (es5)", async () => {
33
const result = evaluator.evaluateTypeScript(`
44
let i = 0;
5-
const iterator = {
5+
const iterator: IterableIterator<any> = {
66
[Symbol.iterator]() { return this; },
77
next() {
88
switch (i++) {
@@ -18,7 +18,7 @@ describe("forAwaitOfEvaluation", () => {
1818
for await (const item of iterator) {
1919
output.push(item);
2020
}
21-
}`);
21+
}`, { downlevelIteration: true });
2222
await result.main();
2323
assert.strictEqual(result.output[0], 1);
2424
assert.strictEqual(result.output[1], 2);
@@ -28,7 +28,7 @@ describe("forAwaitOfEvaluation", () => {
2828
it("sync (es2015)", async () => {
2929
const result = evaluator.evaluateTypeScript(`
3030
let i = 0;
31-
const iterator = {
31+
const iterator: IterableIterator<any> = {
3232
[Symbol.iterator]() { return this; },
3333
next() {
3434
switch (i++) {
@@ -55,7 +55,7 @@ describe("forAwaitOfEvaluation", () => {
5555
const result = evaluator.evaluateTypeScript(`
5656
let i = 0;
5757
const iterator = {
58-
[Symbol.asyncIterator]() { return this; },
58+
[Symbol.asyncIterator](): AsyncIterableIterator<any> { return this; },
5959
async next() {
6060
switch (i++) {
6161
case 0: return { value: 1, done: false };
@@ -70,7 +70,7 @@ describe("forAwaitOfEvaluation", () => {
7070
for await (const item of iterator) {
7171
output.push(item);
7272
}
73-
}`);
73+
}`, { downlevelIteration: true });
7474
await result.main();
7575
assert.strictEqual(result.output[0], 1);
7676
assert.instanceOf(result.output[1], Promise);
@@ -81,7 +81,7 @@ describe("forAwaitOfEvaluation", () => {
8181
const result = evaluator.evaluateTypeScript(`
8282
let i = 0;
8383
const iterator = {
84-
[Symbol.asyncIterator]() { return this; },
84+
[Symbol.asyncIterator](): AsyncIterableIterator<any> { return this; },
8585
async next() {
8686
switch (i++) {
8787
case 0: return { value: 1, done: false };

0 commit comments

Comments
 (0)