Comparing version 0.26.1 to 0.27.0
@@ -26,3 +26,3 @@ /** | ||
/** | ||
* Asserts that `expression` throws an error. | ||
* Asserts that `expression` throws an error. Will not ignore syntax errors. | ||
* | ||
@@ -29,0 +29,0 @@ * @param expression - Expression that should throw an error. |
@@ -48,3 +48,3 @@ "use strict"; | ||
/** | ||
* Asserts that `expression` throws an error. | ||
* Asserts that `expression` throws an error. Will not ignore syntax errors. | ||
* | ||
@@ -51,0 +51,0 @@ * @param expression - Expression that should throw an error. |
@@ -15,3 +15,3 @@ "use strict"; | ||
// List of diagnostic codes which should be ignored inside `expectError` statements | ||
const expectErrordiagnosticCodesToIgnore = new Set([ | ||
const expectErrorDiagnosticCodesToIgnore = new Set([ | ||
interfaces_1.DiagnosticCode.ArgumentTypeIsNotAssignableToParameterType, | ||
@@ -34,2 +34,6 @@ interfaces_1.DiagnosticCode.PropertyDoesNotExistOnType, | ||
interfaces_1.DiagnosticCode.ExpressionNotCallable, | ||
interfaces_1.DiagnosticCode.TypeNotAssignableWithExactOptionalPropertyTypes, | ||
interfaces_1.DiagnosticCode.TypeNotAssignableToParameterWithExactOptionalPropertyTypes, | ||
interfaces_1.DiagnosticCode.TypeNotAssignableTypeOfTargetWithExactOptionalPropertyTypes, | ||
interfaces_1.DiagnosticCode.IndexSignatureOnlyPermitsReading, | ||
interfaces_1.DiagnosticCode.OnlyVoidFunctionIsNewCallable, | ||
@@ -56,11 +60,19 @@ interfaces_1.DiagnosticCode.ExpressionNotConstructable, | ||
} | ||
if (!expectErrordiagnosticCodesToIgnore.has(diagnostic.code)) { | ||
return 'preserve'; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const diagnosticFileName = diagnostic.file.fileName; | ||
for (const [location] of expectedErrors) { | ||
for (const [location, error] of expectedErrors) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const start = diagnostic.start; | ||
// Diagnostic is inside of `expectError` clause | ||
if (diagnosticFileName === location.fileName && start > location.start && start < location.end) { | ||
// Ignore syntactical errors | ||
if (diagnostic.code < 2000) { | ||
expectedErrors.delete(location); | ||
return 'preserve'; | ||
} | ||
// Set diagnostic code on `ExpectedError` to log | ||
if (!expectErrorDiagnosticCodesToIgnore.has(diagnostic.code)) { | ||
error.code = diagnostic.code; | ||
return 'preserve'; | ||
} | ||
return location; | ||
@@ -115,3 +127,6 @@ } | ||
for (const [, diagnostic] of expectedErrors) { | ||
diagnostics.push(Object.assign(Object.assign({}, diagnostic), { message: 'Expected an error, but found none.', severity: 'error' })); | ||
const message = diagnostic.code ? | ||
`Found an error that tsd does not currently support (\`ts${diagnostic.code}\`), consider creating an issue on GitHub.` : | ||
'Expected an error, but found none.'; | ||
diagnostics.push(Object.assign(Object.assign({}, diagnostic), { message, severity: 'error' })); | ||
} | ||
@@ -118,0 +133,0 @@ return diagnostics; |
@@ -36,2 +36,6 @@ import { CompilerOptions } from '@tsd/typescript'; | ||
ExpressionNotConstructable = 2351, | ||
TypeNotAssignableWithExactOptionalPropertyTypes = 2375, | ||
TypeNotAssignableToParameterWithExactOptionalPropertyTypes = 2379, | ||
TypeNotAssignableTypeOfTargetWithExactOptionalPropertyTypes = 2412, | ||
IndexSignatureOnlyPermitsReading = 2542, | ||
NoOverloadExpectsCountOfArguments = 2575, | ||
@@ -38,0 +42,0 @@ ThisContextOfTypeNotAssignableToMethodOfThisType = 2684, |
@@ -22,2 +22,6 @@ "use strict"; | ||
DiagnosticCode[DiagnosticCode["ExpressionNotConstructable"] = 2351] = "ExpressionNotConstructable"; | ||
DiagnosticCode[DiagnosticCode["TypeNotAssignableWithExactOptionalPropertyTypes"] = 2375] = "TypeNotAssignableWithExactOptionalPropertyTypes"; | ||
DiagnosticCode[DiagnosticCode["TypeNotAssignableToParameterWithExactOptionalPropertyTypes"] = 2379] = "TypeNotAssignableToParameterWithExactOptionalPropertyTypes"; | ||
DiagnosticCode[DiagnosticCode["TypeNotAssignableTypeOfTargetWithExactOptionalPropertyTypes"] = 2412] = "TypeNotAssignableTypeOfTargetWithExactOptionalPropertyTypes"; | ||
DiagnosticCode[DiagnosticCode["IndexSignatureOnlyPermitsReading"] = 2542] = "IndexSignatureOnlyPermitsReading"; | ||
DiagnosticCode[DiagnosticCode["NoOverloadExpectsCountOfArguments"] = 2575] = "NoOverloadExpectsCountOfArguments"; | ||
@@ -24,0 +28,0 @@ DiagnosticCode[DiagnosticCode["ThisContextOfTypeNotAssignableToMethodOfThisType"] = 2684] = "ThisContextOfTypeNotAssignableToMethodOfThisType"; |
@@ -10,3 +10,5 @@ import { Program, CallExpression } from '@tsd/typescript'; | ||
export declare const extractAssertions: (program: Program) => Map<Assertion, Set<CallExpression>>; | ||
export type ExpectedError = Pick<Diagnostic, 'fileName' | 'line' | 'column'>; | ||
export type ExpectedError = Pick<Diagnostic, 'fileName' | 'line' | 'column'> & { | ||
code?: number; | ||
}; | ||
/** | ||
@@ -13,0 +15,0 @@ * Loop over all the error assertion nodes and convert them to a location map. |
@@ -75,3 +75,3 @@ "use strict"; | ||
start: node.getStart(), | ||
end: node.getEnd() | ||
end: node.getEnd() + 1 | ||
}; | ||
@@ -78,0 +78,0 @@ const pos = node |
{ | ||
"name": "tsd", | ||
"version": "0.26.1", | ||
"version": "0.27.0", | ||
"description": "Check TypeScript type definitions", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -153,3 +153,3 @@ # tsd ![CI](https://github.com/SamVerschueren/tsd/workflows/CI/badge.svg) | ||
Asserts that `expression` throws an error. | ||
Asserts that `expression` throws an error. Will not ignore syntax errors. | ||
@@ -156,0 +156,0 @@ ### expectDeprecated(expression: any) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
84322
1600