Skip to content

Commit 76c420f

Browse files
committed
Improve testing
1 parent 12df5bd commit 76c420f

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

tst/unit/context/TransformContext.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ describe('TransformContext', () => {
77
// Mock syntax tree with SAM transform
88
const mockNode = {
99
childCount: 2,
10+
descendantsOfType: () => [mockNode],
11+
namedChildren: [
12+
{
13+
type: 'block_mapping_pair',
14+
childForFieldName: (field: string) => {
15+
if (field === 'key') return { text: 'Transform' };
16+
if (field === 'value') return { text: 'AWS::Serverless-2016-10-31' };
17+
return null;
18+
},
19+
},
20+
{
21+
type: 'block_mapping_pair',
22+
childForFieldName: (field: string) => {
23+
if (field === 'key') return { text: 'Resources' };
24+
if (field === 'value') return { text: '{}' };
25+
return null;
26+
},
27+
},
28+
],
1029
child: (index: number) => {
1130
if (index === 0) {
1231
return {
@@ -38,7 +57,12 @@ describe('TransformContext', () => {
3857
});
3958

4059
it('should return false when no SAM transform present', () => {
41-
const mockNode = { childCount: 0, child: () => null } as any;
60+
const mockNode = {
61+
childCount: 0,
62+
child: () => null,
63+
descendantsOfType: () => [],
64+
namedChildren: [],
65+
} as any;
4266
const context = new TransformContext(mockNode, DocumentType.YAML);
4367
expect(context.hasSamTransform()).toBe(false);
4468
});

tst/utils/MockContext.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,20 @@ const defaultContextParams: Partial<ContextParams> = {
3434
};
3535

3636
function node(text: string, startPosition?: Point, endPosition?: Point, type?: string): SyntaxNode {
37-
return {
37+
const mockNode: Partial<SyntaxNode> = {
3838
text,
3939
startPosition,
4040
endPosition,
4141
type,
42-
} as SyntaxNode;
42+
parent: null,
43+
childCount: 0,
44+
child: () => null,
45+
childForFieldName: () => null,
46+
descendantsOfType: () => [],
47+
namedChildren: [],
48+
children: [],
49+
};
50+
return mockNode as SyntaxNode;
4351
}
4452

4553
export function createMockContext(

0 commit comments

Comments
 (0)