Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

diagnostics.test.ts

31 lines951 Bytes

1import { expect, test } from 'vitest'
2import { analyzeModule } from '../src'
3​
4test.each(['\n', '\r\n', '\r', '\u2028', '\u2029'])(
5 'reports actionable syntax locations with %j line endings and Unicode source',
6 (newline) => {
7 const code = `// πŸ˜€Γ©${newline}/* πŸ˜€Γ© */ export const broken = ;`
8​
9 expect(() =>
10 analyzeModule({ code, filename: '/routes/index.tsx' }),
11 ).toThrow(
12 expect.objectContaining({
13 name: 'SyntaxError',
14 message: "/routes/index.tsx: Unexpected token ';' (2:32)",
15 loc: { line: 2, column: 32 },
16 pos: code.indexOf(';'),
17 }),
18 )
19 },
21​
22test('reports the first line and a zero-based column for syntax errors', () => {
23 expect(() => analyzeModule({ code: 'const broken = ;' })).toThrow(
24 expect.objectContaining({
25 name: 'SyntaxError',
26 message: "input.tsx: Unexpected token ';' (1:15)",
27 loc: { line: 1, column: 15 },
28 pos: 15,
29 }),
30 )
31})