diff --git a/src/testRunner/unittests/convertToAsyncFunction.ts b/src/testRunner/unittests/convertToAsyncFunction.ts index a1e8169e45..186b9059a3 100644 --- a/src/testRunner/unittests/convertToAsyncFunction.ts +++ b/src/testRunner/unittests/convertToAsyncFunction.ts @@ -363,6 +363,8 @@ interface Array {}` const diagnostics = languageService.getSuggestionDiagnostics(f.path); const diagnostic = find(diagnostics, diagnostic => diagnostic.messageText === diagnosticDescription.message); assert.exists(diagnostic); + assert.equal(diagnostic!.start, context.span.start); + assert.equal(diagnostic!.length, context.span.length); const actions = codefix.getFixes(context); const action = find(actions, action => action.description === codeFixDescription.message)!; @@ -423,6 +425,10 @@ interface Array {}` _testConvertToAsyncFunction("convertToAsyncFunction_basic", ` function [#|f|](): Promise{ return fetch('https://typescriptlang.org').then(result => { console.log(result) }); +}`); + _testConvertToAsyncFunction("convertToAsyncFunction_basicNoReturnTypeAnnotation", ` +function [#|f|]() { + return fetch('https://typescriptlang.org').then(result => { console.log(result) }); }`); _testConvertToAsyncFunction("convertToAsyncFunction_basicWithComments", ` function [#|f|](): Promise{ @@ -436,6 +442,10 @@ function [#|f|](): Promise{ _testConvertToAsyncFunction("convertToAsyncFunction_ArrowFunction", ` [#|():Promise => {|] return fetch('https://typescriptlang.org').then(result => console.log(result)); +}`); + _testConvertToAsyncFunction("convertToAsyncFunction_ArrowFunctionNoAnnotation", ` +[#|() => {|] + return fetch('https://typescriptlang.org').then(result => console.log(result)); }`); _testConvertToAsyncFunction("convertToAsyncFunction_Catch", ` function [#|f|]():Promise { @@ -1178,6 +1188,12 @@ function [#|f|]() { } `); + _testConvertToAsyncFunction("convertToAsyncFunction_simpleFunctionExpression", ` +const [#|foo|] = function () { + return fetch('https://typescriptlang.org').then(result => { console.log(result) }); +} +`); + }); diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_ArrowFunctionNoAnnotation.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_ArrowFunctionNoAnnotation.js new file mode 100644 index 0000000000..500d546971 --- /dev/null +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_ArrowFunctionNoAnnotation.js @@ -0,0 +1,11 @@ +// ==ORIGINAL== + +/*[#|*/() => {/*|]*/ + return fetch('https://typescriptlang.org').then(result => console.log(result)); +} +// ==ASYNC FUNCTION::Convert to async function== + +async () => { + const result = await fetch('https://typescriptlang.org'); + return console.log(result); +} \ No newline at end of file diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_ArrowFunctionNoAnnotation.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_ArrowFunctionNoAnnotation.ts new file mode 100644 index 0000000000..500d546971 --- /dev/null +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_ArrowFunctionNoAnnotation.ts @@ -0,0 +1,11 @@ +// ==ORIGINAL== + +/*[#|*/() => {/*|]*/ + return fetch('https://typescriptlang.org').then(result => console.log(result)); +} +// ==ASYNC FUNCTION::Convert to async function== + +async () => { + const result = await fetch('https://typescriptlang.org'); + return console.log(result); +} \ No newline at end of file diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_basicNoReturnTypeAnnotation.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_basicNoReturnTypeAnnotation.js new file mode 100644 index 0000000000..8aec78c667 --- /dev/null +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_basicNoReturnTypeAnnotation.js @@ -0,0 +1,11 @@ +// ==ORIGINAL== + +function /*[#|*/f/*|]*/() { + return fetch('https://typescriptlang.org').then(result => { console.log(result) }); +} +// ==ASYNC FUNCTION::Convert to async function== + +async function f() { + const result = await fetch('https://typescriptlang.org'); + console.log(result); +} \ No newline at end of file diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_basicNoReturnTypeAnnotation.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_basicNoReturnTypeAnnotation.ts new file mode 100644 index 0000000000..8aec78c667 --- /dev/null +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_basicNoReturnTypeAnnotation.ts @@ -0,0 +1,11 @@ +// ==ORIGINAL== + +function /*[#|*/f/*|]*/() { + return fetch('https://typescriptlang.org').then(result => { console.log(result) }); +} +// ==ASYNC FUNCTION::Convert to async function== + +async function f() { + const result = await fetch('https://typescriptlang.org'); + console.log(result); +} \ No newline at end of file diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.js b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.js new file mode 100644 index 0000000000..a92497ca93 --- /dev/null +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.js @@ -0,0 +1,12 @@ +// ==ORIGINAL== + +const /*[#|*/foo/*|]*/ = function () { + return fetch('https://typescriptlang.org').then(result => { console.log(result) }); +} + +// ==ASYNC FUNCTION::Convert to async function== + +const foo = async function () { + const result = await fetch('https://typescriptlang.org'); + console.log(result); +} diff --git a/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.ts b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.ts new file mode 100644 index 0000000000..a92497ca93 --- /dev/null +++ b/tests/baselines/reference/convertToAsyncFunction/convertToAsyncFunction_simpleFunctionExpression.ts @@ -0,0 +1,12 @@ +// ==ORIGINAL== + +const /*[#|*/foo/*|]*/ = function () { + return fetch('https://typescriptlang.org').then(result => { console.log(result) }); +} + +// ==ASYNC FUNCTION::Convert to async function== + +const foo = async function () { + const result = await fetch('https://typescriptlang.org'); + console.log(result); +}