-
-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add full diagnostics to tserror #1706
Merged
cspotcode
merged 18 commits into
TypeStrong:main
from
paulbrimicombe:add-error-locations-to-tserror
Apr 17, 2022
Merged
Changes from 3 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4938d99
Add error locations to TSErrors
paulbrimicombe 428e506
Simplify tests / code formatting
paulbrimicombe 7fb714a
Expose the full TypeScript diagnostics on TSErrors
paulbrimicombe f7afcab
Test re-org and deduplication
cspotcode e0560d8
lintfix
cspotcode b5d6ef6
fix
cspotcode a5f64f5
bang head against wall
cspotcode 47f769b
lintfix
cspotcode 992796b
fix
cspotcode 52fcbda
fix
cspotcode 5143a48
fix
cspotcode 9a0d071
fix
cspotcode 08a95c6
fix
cspotcode 30b78bd
tweaks
cspotcode 217e955
Revert "tweaks"
cspotcode 715d3ac
fix
cspotcode cd107ed
finally
cspotcode b6e01c8
fix
cspotcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ import { | |
CMD_ESM_LOADER_WITHOUT_PROJECT, | ||
EXPERIMENTAL_MODULES_FLAG, | ||
} from './helpers'; | ||
import type { TSError } from '..'; | ||
|
||
const exec = createExec({ | ||
cwd: TEST_DIR, | ||
|
@@ -974,6 +975,96 @@ test.suite('ts-node', (test) => { | |
expect(output).toMatch('var x = 10;'); | ||
}); | ||
|
||
test('should throw errors', ({ context: { service } }) => { | ||
let err: unknown = null; | ||
|
||
try { | ||
service.compile('new Error(123)', 'test.ts'); | ||
} catch (error) { | ||
err = error; | ||
} | ||
|
||
if (err === null) { | ||
throw new Error('Command was expected to fail, but it succeeded.'); | ||
} | ||
|
||
expect((err as Error).message).toMatch( | ||
new RegExp( | ||
"TS2345: Argument of type '123' " + | ||
"is not assignable to parameter of type 'string | undefined'\\." | ||
) | ||
); | ||
}); | ||
|
||
test('should throw errors with diagnostic text', ({ | ||
context: { service }, | ||
}) => { | ||
let err: unknown = null; | ||
|
||
try { | ||
service.compile('new Error(123)', 'test.ts'); | ||
} catch (error) { | ||
err = error; | ||
} | ||
|
||
if (err === null) { | ||
throw new Error('Command was expected to fail, but it succeeded.'); | ||
} | ||
|
||
expect((err as TSError).diagnosticText).toMatch( | ||
new RegExp( | ||
"TS2345: Argument of type '123' " + | ||
"is not assignable to parameter of type 'string | undefined'\\." | ||
) | ||
); | ||
}); | ||
|
||
test('should throw errors with diagnostic codes', ({ | ||
context: { service }, | ||
}) => { | ||
let err: unknown = null; | ||
|
||
try { | ||
service.compile('new Error(123)', 'test.ts'); | ||
} catch (error) { | ||
err = error; | ||
} | ||
|
||
if (err === null) { | ||
throw new Error('Command was expected to fail, but it succeeded.'); | ||
} | ||
|
||
expect((err as TSError).diagnosticCodes).toEqual([2345]); | ||
}); | ||
|
||
test('should throw errors with complete diagnostic information', ({ | ||
context: { service }, | ||
}) => { | ||
let err: unknown = null; | ||
|
||
try { | ||
service.compile('new Error(123)', 'test.ts'); | ||
} catch (error) { | ||
err = error; | ||
} | ||
|
||
if (err === null) { | ||
throw new Error('Command was expected to fail, but it succeeded.'); | ||
} | ||
|
||
const diagnostics = (err as TSError).diagnostics; | ||
|
||
expect(diagnostics).toHaveLength(1); | ||
expect(diagnostics[0]).toMatchObject({ | ||
code: 2345, | ||
start: 10, | ||
length: 3, | ||
messageText: | ||
"Argument of type '123' " + | ||
"is not assignable to parameter of type 'string | undefined'.", | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: consider moving these tests into a new spec file, perhaps |
||
|
||
test.suite('should get type information', (test) => { | ||
test('given position of identifier', ({ context: { service } }) => { | ||
expect( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this argument optional to avoid a breaking change to our API surface, since
TSError
is part of our API?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's exactly why it's optional — I didn't want to make this a breaking change.