Add tests and validate diagnostic spans
This commit is contained in:
parent
158f0b0c0b
commit
3ad6a66e69
7 changed files with 84 additions and 0 deletions
|
@ -363,6 +363,8 @@ interface Array<T> {}`
|
|||
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<T> {}`
|
|||
_testConvertToAsyncFunction("convertToAsyncFunction_basic", `
|
||||
function [#|f|](): Promise<void>{
|
||||
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<void>{
|
||||
|
@ -436,6 +442,10 @@ function [#|f|](): Promise<void>{
|
|||
_testConvertToAsyncFunction("convertToAsyncFunction_ArrowFunction", `
|
||||
[#|():Promise<void> => {|]
|
||||
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<void> {
|
||||
|
@ -1178,6 +1188,12 @@ function [#|f|]() {
|
|||
}
|
||||
`);
|
||||
|
||||
_testConvertToAsyncFunction("convertToAsyncFunction_simpleFunctionExpression", `
|
||||
const [#|foo|] = function () {
|
||||
return fetch('https://typescriptlang.org').then(result => { console.log(result) });
|
||||
}
|
||||
`);
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
Loading…
Reference in a new issue