Skip to content

Commit

Permalink
test: correct issue with TSError
Browse files Browse the repository at this point in the history
  • Loading branch information
armano2 committed Feb 15, 2021
1 parent 1cf7389 commit 2bae582
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { serializer } from '../../tools/tserror-serializer';
*/
const FIXTURES_DIR = path.join(__dirname, '../../../shared-fixtures/fixtures');

const testFiles = glob.sync(`${FIXTURES_DIR}/**/*.src.*`);
const testFiles = glob.sync('**/*.src.*', {
cwd: FIXTURES_DIR,
});

expect.addSnapshotSerializer(serializer);

describe('Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled', () => {
testFiles.forEach(filename => {
const code = readFileSync(filename, 'utf8');
const code = readFileSync(path.join(FIXTURES_DIR, filename), 'utf8');
const fileExtension = path.extname(filename);
const config: parser.TSESTreeOptions = {
loc: true,
Expand Down
12 changes: 7 additions & 5 deletions packages/typescript-estree/tools/tserror-serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import type { Plugin } from 'pretty-format';

export const serializer: Plugin = {
test: (val: unknown): val is TSError => val instanceof TSError,
serialize(val: TSError, config) {
serialize(val: TSError, config, indentation, depth, refs, printer) {
const format = (value: unknown): string =>
printer(value, config, indentation, depth + 1, refs);
return (
`${val.name} {\n` +
`${config.indent}"column": ${val.column},\n` +
`${config.indent}"index": ${val.index},\n` +
`${config.indent}"lineNumber": ${val.lineNumber},\n` +
`${config.indent}"message": "${val.message}",\n` +
`${config.indent}"column": ${format(val.column)},\n` +
`${config.indent}"index": ${format(val.index)},\n` +
`${config.indent}"lineNumber": ${format(val.lineNumber)},\n` +
`${config.indent}"message": ${format(val.message)},\n` +
`}`
);
},
Expand Down

0 comments on commit 2bae582

Please sign in to comment.