-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnode.mock.ts
43 lines (41 loc) · 1.24 KB
/
node.mock.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
import { SyntaxKind } from 'ts-morph';
import type { CoverageType } from '../src/lib/runner/models.js';
export function nodeMock(options: {
coverageType: CoverageType;
line: number;
file: string;
isCommented: boolean;
}) {
return {
getKind: () => getKindFromCoverageType(options.coverageType),
getJsDocs: () => (options.isCommented ? ['Comment'] : []),
getName: () => 'test',
getStartLineNumber: () => options.line,
getDeclarations: () => [],
// Only for classes
getMethods: () => [],
getProperties: () => [],
};
}
function getKindFromCoverageType(coverageType: CoverageType): SyntaxKind {
switch (coverageType) {
case 'classes':
return SyntaxKind.ClassDeclaration;
case 'methods':
return SyntaxKind.MethodDeclaration;
case 'functions':
return SyntaxKind.FunctionDeclaration;
case 'interfaces':
return SyntaxKind.InterfaceDeclaration;
case 'enums':
return SyntaxKind.EnumDeclaration;
case 'variables':
return SyntaxKind.VariableDeclaration;
case 'properties':
return SyntaxKind.PropertyDeclaration;
case 'types':
return SyntaxKind.TypeAliasDeclaration;
default:
throw new Error(`Unsupported syntax kind: ${coverageType}`);
}
}