11import { describe , it , expect , beforeEach , vi } from 'vitest' ;
2- import { TextDocument } from 'vscode-languageserver-textdocument' ;
32import { getStackActionsCodeLenses } from '../../../src/codeLens/StackActionsCodeLens' ;
43import { getEntityMap } from '../../../src/context/SectionContextBuilder' ;
5- import { Document } from '../../../src/document/Document' ;
64import { createMockSyntaxTreeManager } from '../../utils/MockServerComponents' ;
5+ import { createTestDocument } from '../../utils/Utils' ;
76
87vi . mock ( '../../../src/context/SectionContextBuilder' , ( ) => ( {
98 getEntityMap : vi . fn ( ) ,
@@ -22,8 +21,11 @@ describe('StackActionsCodeLens', () => {
2221 it ( 'should return empty array when syntax tree is not found' , ( ) => {
2322 mockSyntaxTreeManager . getSyntaxTree . returns ( undefined ) ;
2423
25- const document = new Document (
26- TextDocument . create ( 'file:///test.yaml' , 'yaml' , 1 , 'Resources:\n Bucket:\n Type: AWS::S3::Bucket' ) ,
24+ const document = createTestDocument (
25+ 'file:///test.yaml' ,
26+ 'yaml' ,
27+ 1 ,
28+ 'Resources:\n Bucket:\n Type: AWS::S3::Bucket' ,
2729 ) ;
2830
2931 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
@@ -35,9 +37,7 @@ describe('StackActionsCodeLens', () => {
3537 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
3638 mockGetEntityMap . mockReturnValue ( undefined ) ;
3739
38- const document = new Document (
39- TextDocument . create ( 'file:///test.yaml' , 'yaml' , 1 , 'AWSTemplateFormatVersion: "2010-09-09"' ) ,
40- ) ;
40+ const document = createTestDocument ( 'file:///test.yaml' , 'yaml' , 1 , 'AWSTemplateFormatVersion: "2010-09-09"' ) ;
4141
4242 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
4343
@@ -48,7 +48,7 @@ describe('StackActionsCodeLens', () => {
4848 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
4949 mockGetEntityMap . mockReturnValue ( new Map ( ) ) ;
5050
51- const document = new Document ( TextDocument . create ( 'file:///test.yaml' , 'yaml' , 1 , 'Resources: {}' ) ) ;
51+ const document = createTestDocument ( 'file:///test.yaml' , 'yaml' , 1 , 'Resources: {}' ) ;
5252
5353 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
5454
@@ -59,9 +59,7 @@ describe('StackActionsCodeLens', () => {
5959 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
6060 mockGetEntityMap . mockReturnValue ( new Map ( [ [ 'Bucket' , { } ] ] ) ) ;
6161
62- const document = new Document (
63- TextDocument . create ( 'file:///test.yaml' , 'yaml' , 1 , 'some: random\nyaml: content' ) ,
64- ) ;
62+ const document = createTestDocument ( 'file:///test.yaml' , 'yaml' , 1 , 'some: random\nyaml: content' ) ;
6563
6664 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
6765
@@ -72,8 +70,11 @@ describe('StackActionsCodeLens', () => {
7270 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
7371 mockGetEntityMap . mockReturnValue ( new Map ( [ [ 'Bucket' , { } ] ] ) ) ;
7472
75- const document = new Document (
76- TextDocument . create ( 'file:///test.yaml' , 'yaml' , 1 , 'Resources:\n Bucket:\n Type: AWS::S3::Bucket' ) ,
73+ const document = createTestDocument (
74+ 'file:///test.yaml' ,
75+ 'yaml' ,
76+ 1 ,
77+ 'Resources:\n Bucket:\n Type: AWS::S3::Bucket' ,
7778 ) ;
7879
7980 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
@@ -88,8 +89,11 @@ describe('StackActionsCodeLens', () => {
8889 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
8990 mockGetEntityMap . mockReturnValue ( new Map ( [ [ 'Bucket' , { } ] ] ) ) ;
9091
91- const document = new Document (
92- TextDocument . create ( 'file:///test.yaml' , 'yaml' , 1 , 'Resources:\n Bucket:\n Type: AWS::S3::Bucket' ) ,
92+ const document = createTestDocument (
93+ 'file:///test.yaml' ,
94+ 'yaml' ,
95+ 1 ,
96+ 'Resources:\n Bucket:\n Type: AWS::S3::Bucket' ,
9397 ) ;
9498
9599 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
@@ -102,8 +106,11 @@ describe('StackActionsCodeLens', () => {
102106 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
103107 mockGetEntityMap . mockReturnValue ( new Map ( [ [ 'Bucket' , { } ] ] ) ) ;
104108
105- const document = new Document (
106- TextDocument . create ( 'file:///test.yaml' , 'yaml' , 1 , '\n\nResources:\n Bucket:\n Type: AWS::S3::Bucket' ) ,
109+ const document = createTestDocument (
110+ 'file:///test.yaml' ,
111+ 'yaml' ,
112+ 1 ,
113+ '\n\nResources:\n Bucket:\n Type: AWS::S3::Bucket' ,
107114 ) ;
108115
109116 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
@@ -115,13 +122,11 @@ describe('StackActionsCodeLens', () => {
115122 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
116123 mockGetEntityMap . mockReturnValue ( new Map ( [ [ 'Bucket' , { } ] ] ) ) ;
117124
118- const document = new Document (
119- TextDocument . create (
120- 'file:///test.yaml' ,
121- 'yaml' ,
122- 1 ,
123- '# This is a comment\n# Another comment\nResources:\n Bucket:\n Type: AWS::S3::Bucket' ,
124- ) ,
125+ const document = createTestDocument (
126+ 'file:///test.yaml' ,
127+ 'yaml' ,
128+ 1 ,
129+ '# This is a comment\n# Another comment\nResources:\n Bucket:\n Type: AWS::S3::Bucket' ,
125130 ) ;
126131
127132 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
@@ -133,13 +138,11 @@ describe('StackActionsCodeLens', () => {
133138 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
134139 mockGetEntityMap . mockReturnValue ( new Map ( [ [ 'Bucket' , { } ] ] ) ) ;
135140
136- const document = new Document (
137- TextDocument . create (
138- 'file:///test.yaml' ,
139- 'yaml' ,
140- 1 ,
141- '\n# Comment\n\n# Another comment\n\nResources:\n Bucket:\n Type: AWS::S3::Bucket' ,
142- ) ,
141+ const document = createTestDocument (
142+ 'file:///test.yaml' ,
143+ 'yaml' ,
144+ 1 ,
145+ '\n# Comment\n\n# Another comment\n\nResources:\n Bucket:\n Type: AWS::S3::Bucket' ,
143146 ) ;
144147
145148 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
@@ -151,13 +154,11 @@ describe('StackActionsCodeLens', () => {
151154 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
152155 mockGetEntityMap . mockReturnValue ( new Map ( [ [ 'Bucket' , { } ] ] ) ) ;
153156
154- const document = new Document (
155- TextDocument . create (
156- 'file:///test.yaml' ,
157- 'yaml' ,
158- 1 ,
159- 'AWSTemplateFormatVersion: "2010-09-09"\nResources:\n Bucket:\n Type: AWS::S3::Bucket' ,
160- ) ,
157+ const document = createTestDocument (
158+ 'file:///test.yaml' ,
159+ 'yaml' ,
160+ 1 ,
161+ 'AWSTemplateFormatVersion: "2010-09-09"\nResources:\n Bucket:\n Type: AWS::S3::Bucket' ,
161162 ) ;
162163
163164 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
@@ -170,13 +171,11 @@ describe('StackActionsCodeLens', () => {
170171 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
171172 mockGetEntityMap . mockReturnValue ( new Map ( [ [ 'Function' , { } ] ] ) ) ;
172173
173- const document = new Document (
174- TextDocument . create (
175- 'file:///test.yaml' ,
176- 'yaml' ,
177- 1 ,
178- 'Transform: AWS::Serverless-2016-10-31\nResources:\n Function:\n Type: AWS::Serverless::Function' ,
179- ) ,
174+ const document = createTestDocument (
175+ 'file:///test.yaml' ,
176+ 'yaml' ,
177+ 1 ,
178+ 'Transform: AWS::Serverless-2016-10-31\nResources:\n Function:\n Type: AWS::Serverless::Function' ,
180179 ) ;
181180
182181 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
@@ -188,8 +187,11 @@ describe('StackActionsCodeLens', () => {
188187 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
189188 mockGetEntityMap . mockReturnValue ( new Map ( [ [ 'Bucket' , { } ] ] ) ) ;
190189
191- const document = new Document (
192- TextDocument . create ( 'file:///test.json' , 'json' , 1 , '{"Resources":{"Bucket":{"Type":"AWS::S3::Bucket"}}}' ) ,
190+ const document = createTestDocument (
191+ 'file:///test.json' ,
192+ 'json' ,
193+ 1 ,
194+ '{"Resources":{"Bucket":{"Type":"AWS::S3::Bucket"}}}' ,
193195 ) ;
194196
195197 const result = getStackActionsCodeLenses ( 'file:///test.json' , document , mockSyntaxTreeManager ) ;
@@ -207,13 +209,11 @@ describe('StackActionsCodeLens', () => {
207209 ] ) ,
208210 ) ;
209211
210- const document = new Document (
211- TextDocument . create (
212- 'file:///test.yaml' ,
213- 'yaml' ,
214- 1 ,
215- 'Resources:\n Bucket:\n Type: AWS::S3::Bucket\n Table:\n Type: AWS::DynamoDB::Table' ,
216- ) ,
212+ const document = createTestDocument (
213+ 'file:///test.yaml' ,
214+ 'yaml' ,
215+ 1 ,
216+ 'Resources:\n Bucket:\n Type: AWS::S3::Bucket\n Table:\n Type: AWS::DynamoDB::Table' ,
217217 ) ;
218218
219219 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
@@ -225,13 +225,11 @@ describe('StackActionsCodeLens', () => {
225225 mockSyntaxTreeManager . getSyntaxTree . returns ( { rootNode : { } } as any ) ;
226226 mockGetEntityMap . mockReturnValue ( new Map ( [ [ 'Bucket' , { } ] ] ) ) ;
227227
228- const document = new Document (
229- TextDocument . create (
230- 'file:///test.yaml' ,
231- 'yaml' ,
232- 1 ,
233- ' \n\t\n \nResources:\n Bucket:\n Type: AWS::S3::Bucket' ,
234- ) ,
228+ const document = createTestDocument (
229+ 'file:///test.yaml' ,
230+ 'yaml' ,
231+ 1 ,
232+ ' \n\t\n \nResources:\n Bucket:\n Type: AWS::S3::Bucket' ,
235233 ) ;
236234
237235 const result = getStackActionsCodeLenses ( 'file:///test.yaml' , document , mockSyntaxTreeManager ) ;
0 commit comments