/
semantic-diagnostics-enabled.test.ts
41 lines (38 loc) · 1.32 KB
/
semantic-diagnostics-enabled.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { readFileSync } from 'fs';
import glob from 'glob';
import path from 'path';
import * as parser from '../../src';
import { formatSnapshotName, isJSXFileType } from '../../tools/test-utils';
/**
* Process all fixtures, we will only snapshot the ones that have semantic errors
* which are ignored by default parsing logic.
*/
const FIXTURES_DIR = path.join(__dirname, '../../../shared-fixtures/fixtures');
const testFiles = glob.sync(`**/*.src.*`, {
cwd: FIXTURES_DIR,
});
describe('Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled', () => {
testFiles.forEach(filename => {
const code = readFileSync(path.join(FIXTURES_DIR, filename), 'utf8');
const fileExtension = path.extname(filename);
const config: parser.TSESTreeOptions = {
loc: true,
range: true,
tokens: true,
errorOnUnknownASTType: true,
errorOnTypeScriptSyntacticAndSemanticIssues: true,
jsx: isJSXFileType(fileExtension),
};
it(formatSnapshotName(filename, FIXTURES_DIR, fileExtension), () => {
expect.assertions(1);
try {
parser.parseAndGenerateServices(code, config);
expect(
'TEST OUTPUT: No semantic or syntactic issues found',
).toMatchSnapshot();
} catch (err) {
expect(err).toMatchSnapshot();
}
});
});
});