Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 547
Add full diagnostics to tserror#1706
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4938d99428e5067fb714af7afcabe0560d8b5d6ef6a5f64f547f769b992796b52fcbda5143a489a0d07108a95c630b78bd217e955715d3accd107edb6e01c8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import type { TSError } from '..'; | ||
| import { contextTsNodeUnderTest, ts } from './helpers'; | ||
| import { context, expect } from './testlib'; | ||
| import * as semver from 'semver'; | ||
| import { once } from 'lodash'; | ||
| const test = context(contextTsNodeUnderTest); | ||
| test.suite('TSError diagnostics', ({ context }) => { | ||
| const test = context( | ||
| once(async (t) => { | ||
| const service = t.context.tsNodeUnderTest.create({ | ||
| compilerOptions: { target: 'es5' }, | ||
| skipProject: true, | ||
| }); | ||
| try { | ||
| service.compile('new Error(123)', 'test.ts'); | ||
| } catch (err) { | ||
| return { service, err }; | ||
| } | ||
| return { service, err: undefined }; | ||
| }) | ||
| ); | ||
| const diagnosticCode = 2345; | ||
| const diagnosticMessage = semver.satisfies(ts.version, '2.7') | ||
| ? "Argument of type '123' " + | ||
| "is not assignable to parameter of type 'string | undefined'." | ||
| : "Argument of type 'number' " + | ||
| "is not assignable to parameter of type 'string'."; | ||
| const diagnosticErrorMessage = `TS${diagnosticCode}: ${diagnosticMessage}`; | ||
| const cwdBefore = process.cwd(); | ||
| test('should throw errors', ({ log, context: { err, service } }) => { | ||
| log({ | ||
| version: ts.version, | ||
| serviceVersion: service.ts.version, | ||
| cwdBefore, | ||
| cwd: process.cwd(), | ||
| configFilePath: service.configFilePath, | ||
| config: service.config.options, | ||
| }); | ||
| expect(err).toBeDefined(); | ||
| expect((err as Error).message).toMatch(diagnosticErrorMessage); | ||
| }); | ||
| test('should throw errors with diagnostic text', ({ context: { err } }) => { | ||
| expect((err as TSError).diagnosticText).toMatch(diagnosticErrorMessage); | ||
| }); | ||
| test('should throw errors with diagnostic codes', ({ context: { err } }) => { | ||
| expect((err as TSError).diagnosticCodes).toEqual([2345]); | ||
| }); | ||
| test('should throw errors with complete diagnostic information', ({ | ||
| context: { err }, | ||
| }) => { | ||
| const diagnostics = (err as TSError).diagnostics; | ||
| expect(diagnostics).toHaveLength(1); | ||
| expect(diagnostics[0]).toMatchObject({ | ||
| code: 2345, | ||
| start: 10, | ||
| length: 3, | ||
| messageText: expect.stringMatching(diagnosticMessage), | ||
| }); | ||
| }); | ||
| }); |
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
TSErroris 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.