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) {
|
function compile(sourceText: string, options?: ts.CompilerOptions) {
|
||||||
const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false);
|
const fs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false);
|
||||||
fs.writeFileSync(sourceFile, sourceText);
|
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);
|
const host = new fakes.CompilerHost(fs, compilerOptions);
|
||||||
return compiler.compileFiles(host, [sourceFile], compilerOptions);
|
return compiler.compileFiles(host, [sourceFile], compilerOptions);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +35,14 @@ namespace evaluator {
|
||||||
function evaluate(result: compiler.CompilationResult, globals?: Record<string, any>) {
|
function evaluate(result: compiler.CompilationResult, globals?: Record<string, any>) {
|
||||||
globals = { Symbol: FakeSymbol, ...globals };
|
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")!;
|
const output = result.getOutput(sourceFile, "js")!;
|
||||||
assert.isDefined(output);
|
assert.isDefined(output);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ describe("forAwaitOfEvaluation", () => {
|
||||||
it("sync (es5)", async () => {
|
it("sync (es5)", async () => {
|
||||||
const result = evaluator.evaluateTypeScript(`
|
const result = evaluator.evaluateTypeScript(`
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const iterator = {
|
const iterator: IterableIterator<any> = {
|
||||||
[Symbol.iterator]() { return this; },
|
[Symbol.iterator]() { return this; },
|
||||||
next() {
|
next() {
|
||||||
switch (i++) {
|
switch (i++) {
|
||||||
|
@ -18,7 +18,7 @@ describe("forAwaitOfEvaluation", () => {
|
||||||
for await (const item of iterator) {
|
for await (const item of iterator) {
|
||||||
output.push(item);
|
output.push(item);
|
||||||
}
|
}
|
||||||
}`);
|
}`, { downlevelIteration: true });
|
||||||
await result.main();
|
await result.main();
|
||||||
assert.strictEqual(result.output[0], 1);
|
assert.strictEqual(result.output[0], 1);
|
||||||
assert.strictEqual(result.output[1], 2);
|
assert.strictEqual(result.output[1], 2);
|
||||||
|
@ -28,7 +28,7 @@ describe("forAwaitOfEvaluation", () => {
|
||||||
it("sync (es2015)", async () => {
|
it("sync (es2015)", async () => {
|
||||||
const result = evaluator.evaluateTypeScript(`
|
const result = evaluator.evaluateTypeScript(`
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const iterator = {
|
const iterator: IterableIterator<any> = {
|
||||||
[Symbol.iterator]() { return this; },
|
[Symbol.iterator]() { return this; },
|
||||||
next() {
|
next() {
|
||||||
switch (i++) {
|
switch (i++) {
|
||||||
|
@ -55,7 +55,7 @@ describe("forAwaitOfEvaluation", () => {
|
||||||
const result = evaluator.evaluateTypeScript(`
|
const result = evaluator.evaluateTypeScript(`
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const iterator = {
|
const iterator = {
|
||||||
[Symbol.asyncIterator]() { return this; },
|
[Symbol.asyncIterator](): AsyncIterableIterator<any> { return this; },
|
||||||
async next() {
|
async next() {
|
||||||
switch (i++) {
|
switch (i++) {
|
||||||
case 0: return { value: 1, done: false };
|
case 0: return { value: 1, done: false };
|
||||||
|
@ -70,7 +70,7 @@ describe("forAwaitOfEvaluation", () => {
|
||||||
for await (const item of iterator) {
|
for await (const item of iterator) {
|
||||||
output.push(item);
|
output.push(item);
|
||||||
}
|
}
|
||||||
}`);
|
}`, { downlevelIteration: true });
|
||||||
await result.main();
|
await result.main();
|
||||||
assert.strictEqual(result.output[0], 1);
|
assert.strictEqual(result.output[0], 1);
|
||||||
assert.instanceOf(result.output[1], Promise);
|
assert.instanceOf(result.output[1], Promise);
|
||||||
|
@ -81,7 +81,7 @@ describe("forAwaitOfEvaluation", () => {
|
||||||
const result = evaluator.evaluateTypeScript(`
|
const result = evaluator.evaluateTypeScript(`
|
||||||
let i = 0;
|
let i = 0;
|
||||||
const iterator = {
|
const iterator = {
|
||||||
[Symbol.asyncIterator]() { return this; },
|
[Symbol.asyncIterator](): AsyncIterableIterator<any> { return this; },
|
||||||
async next() {
|
async next() {
|
||||||
switch (i++) {
|
switch (i++) {
|
||||||
case 0: return { value: 1, done: false };
|
case 0: return { value: 1, done: false };
|
||||||
|
|
Loading…
Reference in a new issue