Add tests

This commit is contained in:
Benjamin Lichtman 2018-09-17 11:33:47 -07:00
parent 1b9507ad06
commit ad43020c8b
10 changed files with 132 additions and 4 deletions

View File

@ -817,7 +817,7 @@ function [#|f|]() {
);
_testConvertToAsyncFunction("convertToAsyncFunction_Scope1", `
function [#|f|]() {
var var1:Promise<Response>, var2;
var var1: Response, var2;
return fetch('https://typescriptlang.org').then( _ =>
Promise.resolve().then( res => {
var2 = "test";
@ -1190,6 +1190,30 @@ function [#|f|]() {
function res(result) {
return Promise.resolve().then(x => console.log(result));
}
`);
_testConvertToAsyncFunction("convertToAsyncFunction_callbackReturnsPromise", `
function [#|f|]() {
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length)).then(x => console.log(x + 5));
}
`);
_testConvertToAsyncFunction("convertToAsyncFunction_callbackReturnsPromiseInBlock", `
function [#|f|]() {
return fetch('https://typescriptlang.org').then(s => { return Promise.resolve(s.statusText.length) }).then(x => x + 5);
}
`);
_testConvertToAsyncFunction("convertToAsyncFunction_callbackReturnsFixablePromise", `
function [#|f|]() {
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText).then(st => st.length)).then(x => console.log(x + 5));
}
`);
_testConvertToAsyncFunction("convertToAsyncFunction_callbackReturnsPromiseLastInChain", `
function [#|f|]() {
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length));
}
`);
});

View File

@ -1,7 +1,7 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/() {
var var1:Promise<Response>, var2;
var var1: Response, var2;
return fetch('https://typescriptlang.org').then( _ =>
Promise.resolve().then( res => {
var2 = "test";
@ -18,11 +18,11 @@ function /*[#|*/f/*|]*/() {
// ==ASYNC FUNCTION::Convert to async function==
async function f() {
var var1:Promise<Response>, var2;
var var1: Response, var2;
await fetch('https://typescriptlang.org');
const res = await Promise.resolve();
var2 = "test";
const res_1 = fetch("https://microsoft.com");
const res_1 = await fetch("https://microsoft.com");
const response = var1 === res_1;
return res(response);
}

View File

@ -0,0 +1,14 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/() {
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText).then(st => st.length)).then(x => console.log(x + 5));
}
// ==ASYNC FUNCTION::Convert to async function==
async function f() {
const s = await fetch('https://typescriptlang.org');
const st = await Promise.resolve(s.statusText);
const x = st.length;
return console.log(x + 5);
}

View File

@ -0,0 +1,14 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/() {
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText).then(st => st.length)).then(x => console.log(x + 5));
}
// ==ASYNC FUNCTION::Convert to async function==
async function f() {
const s = await fetch('https://typescriptlang.org');
const st = await Promise.resolve(s.statusText);
const x = st.length;
return console.log(x + 5);
}

View File

@ -0,0 +1,13 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/() {
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length)).then(x => console.log(x + 5));
}
// ==ASYNC FUNCTION::Convert to async function==
async function f() {
const s = await fetch('https://typescriptlang.org');
const x = await Promise.resolve(s.statusText.length);
return console.log(x + 5);
}

View File

@ -0,0 +1,13 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/() {
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length)).then(x => console.log(x + 5));
}
// ==ASYNC FUNCTION::Convert to async function==
async function f() {
const s = await fetch('https://typescriptlang.org');
const x = await Promise.resolve(s.statusText.length);
return console.log(x + 5);
}

View File

@ -0,0 +1,13 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/() {
return fetch('https://typescriptlang.org').then(s => { return Promise.resolve(s.statusText.length) }).then(x => x + 5);
}
// ==ASYNC FUNCTION::Convert to async function==
async function f() {
const s = await fetch('https://typescriptlang.org');
const x = await Promise.resolve(s.statusText.length);
return x + 5;
}

View File

@ -0,0 +1,13 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/() {
return fetch('https://typescriptlang.org').then(s => { return Promise.resolve(s.statusText.length) }).then(x => x + 5);
}
// ==ASYNC FUNCTION::Convert to async function==
async function f() {
const s = await fetch('https://typescriptlang.org');
const x = await Promise.resolve(s.statusText.length);
return x + 5;
}

View File

@ -0,0 +1,12 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/() {
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length));
}
// ==ASYNC FUNCTION::Convert to async function==
async function f() {
const s = await fetch('https://typescriptlang.org');
return Promise.resolve(s.statusText.length);
}

View File

@ -0,0 +1,12 @@
// ==ORIGINAL==
function /*[#|*/f/*|]*/() {
return fetch('https://typescriptlang.org').then(s => Promise.resolve(s.statusText.length));
}
// ==ASYNC FUNCTION::Convert to async function==
async function f() {
const s = await fetch('https://typescriptlang.org');
return Promise.resolve(s.statusText.length);
}