Skip to content

Commit 3ad6a66

Browse files
author
Benjamin Lichtman
committed
Add tests and validate diagnostic spans
1 parent 158f0b0 commit 3ad6a66

7 files changed

+84
-0
lines changed

src/testRunner/unittests/convertToAsyncFunction.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ interface Array<T> {}`
363363
const diagnostics = languageService.getSuggestionDiagnostics(f.path);
364364
const diagnostic = find(diagnostics, diagnostic => diagnostic.messageText === diagnosticDescription.message);
365365
assert.exists(diagnostic);
366+
assert.equal(diagnostic!.start, context.span.start);
367+
assert.equal(diagnostic!.length, context.span.length);
366368

367369
const actions = codefix.getFixes(context);
368370
const action = find(actions, action => action.description === codeFixDescription.message)!;
@@ -423,6 +425,10 @@ interface Array<T> {}`
423425
_testConvertToAsyncFunction("convertToAsyncFunction_basic", `
424426
function [#|f|](): Promise<void>{
425427
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
428+
}`);
429+
_testConvertToAsyncFunction("convertToAsyncFunction_basicNoReturnTypeAnnotation", `
430+
function [#|f|]() {
431+
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
426432
}`);
427433
_testConvertToAsyncFunction("convertToAsyncFunction_basicWithComments", `
428434
function [#|f|](): Promise<void>{
@@ -436,6 +442,10 @@ function [#|f|](): Promise<void>{
436442
_testConvertToAsyncFunction("convertToAsyncFunction_ArrowFunction", `
437443
[#|():Promise<void> => {|]
438444
return fetch('https://typescriptlang.org').then(result => console.log(result));
445+
}`);
446+
_testConvertToAsyncFunction("convertToAsyncFunction_ArrowFunctionNoAnnotation", `
447+
[#|() => {|]
448+
return fetch('https://typescriptlang.org').then(result => console.log(result));
439449
}`);
440450
_testConvertToAsyncFunction("convertToAsyncFunction_Catch", `
441451
function [#|f|]():Promise<void> {
@@ -1178,6 +1188,12 @@ function [#|f|]() {
11781188
}
11791189
`);
11801190

1191+
_testConvertToAsyncFunction("convertToAsyncFunction_simpleFunctionExpression", `
1192+
const [#|foo|] = function () {
1193+
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
1194+
}
1195+
`);
1196+
11811197

11821198
});
11831199

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ==ORIGINAL==
2+
3+
/*[#|*/() => {/*|]*/
4+
return fetch('https://typescriptlang.org').then(result => console.log(result));
5+
}
6+
// ==ASYNC FUNCTION::Convert to async function==
7+
8+
async () => {
9+
const result = await fetch('https://typescriptlang.org');
10+
return console.log(result);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ==ORIGINAL==
2+
3+
/*[#|*/() => {/*|]*/
4+
return fetch('https://typescriptlang.org').then(result => console.log(result));
5+
}
6+
// ==ASYNC FUNCTION::Convert to async function==
7+
8+
async () => {
9+
const result = await fetch('https://typescriptlang.org');
10+
return console.log(result);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
5+
}
6+
// ==ASYNC FUNCTION::Convert to async function==
7+
8+
async function f() {
9+
const result = await fetch('https://typescriptlang.org');
10+
console.log(result);
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ==ORIGINAL==
2+
3+
function /*[#|*/f/*|]*/() {
4+
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
5+
}
6+
// ==ASYNC FUNCTION::Convert to async function==
7+
8+
async function f() {
9+
const result = await fetch('https://typescriptlang.org');
10+
console.log(result);
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// ==ORIGINAL==
2+
3+
const /*[#|*/foo/*|]*/ = function () {
4+
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
5+
}
6+
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
const foo = async function () {
10+
const result = await fetch('https://typescriptlang.org');
11+
console.log(result);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// ==ORIGINAL==
2+
3+
const /*[#|*/foo/*|]*/ = function () {
4+
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
5+
}
6+
7+
// ==ASYNC FUNCTION::Convert to async function==
8+
9+
const foo = async function () {
10+
const result = await fetch('https://typescriptlang.org');
11+
console.log(result);
12+
}

0 commit comments

Comments
 (0)