forked from typescript-eslint/typescript-eslint
/
services.ts
47 lines (42 loc) · 1.52 KB
/
services.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
42
43
44
45
46
47
import path from 'path';
import fs from 'fs';
import glob from 'glob';
import { ParserOptions } from '../../src/parser';
import {
createSnapshotTestBlock,
formatSnapshotName,
testServices,
} from '../tools/test-utils';
import { createProgram } from '@typescript-eslint/typescript-estree';
//------------------------------------------------------------------------------
// Setup
//------------------------------------------------------------------------------
const FIXTURES_DIR = './tests/fixtures/services';
const testFiles = glob.sync(`**/*.src.ts`, {
cwd: FIXTURES_DIR,
});
function createConfig(filename: string): ParserOptions {
return {
filePath: filename,
project: './tsconfig.json',
tsconfigRootDir: path.resolve(FIXTURES_DIR),
};
}
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe('services', () => {
const program = createProgram(path.resolve(FIXTURES_DIR, 'tsconfig.json'));
testFiles.forEach(filename => {
const code = fs.readFileSync(path.join(FIXTURES_DIR, filename), 'utf8');
const config = createConfig(filename);
const snapshotName = formatSnapshotName(filename, FIXTURES_DIR, '.ts');
it(snapshotName, createSnapshotTestBlock(code, config));
it(`${snapshotName} services`, () => {
testServices(code, config);
});
it(`${snapshotName} services with provided program`, () => {
testServices(code, { ...config, program });
});
});
});