Merge pull request #24677 from Microsoft/checkEvaluatorSyntax
Fails test if evaluator source text has errors
This commit is contained in:
commit
942c42bf29
|
@ -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<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);
|
||||
|
||||
|
|
|
@ -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++) {
|
||||
|
@ -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<any> = {
|
||||
[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<any> { 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<any> { return this; },
|
||||
async next() {
|
||||
switch (i++) {
|
||||
case 0: return { value: 1, done: false };
|
||||
|
|
Loading…
Reference in a new issue