@@ -96,28 +96,61 @@ describe("unittests:: tsserver:: refactors", () => {
96
96
} ) ;
97
97
98
98
it ( "handles moving statement to an existing file" , ( ) => {
99
- const aTs : File = { path : "/Foo/a.ts" , content : "const x = 0;" } ;
100
- const bTs : File = {
101
- path : "/Foo/b.ts" , content : `import {} from "./bar";
102
- const a = 1;` } ;
103
- const tsconfig : File = { path : "/Foo/tsconfig.json" , content : `{ "files": ["./a.ts", "./b.ts"] }` } ;
104
- const host = createServerHost ( [ aTs , bTs , tsconfig ] ) ;
105
- const session = createSession ( host , { logger : createLoggerWithInMemoryLogs ( host ) } ) ;
106
- openFilesForSession ( [ aTs ] , session ) ;
99
+ const aTs : File = { path : "/Foo/a.ts" , content : "const x = 0;" } ;
100
+ const bTs : File = {
101
+ path : "/Foo/b.ts" , content : `import {} from "./bar";
102
+ const a = 1;`} ;
103
+ const tsconfig : File = { path : "/Foo/tsconfig.json" , content : `{ "files": ["./a.ts", "./b.ts"] }` } ;
104
+ const host = createServerHost ( [ aTs , bTs , tsconfig ] ) ;
105
+ const session = createSession ( host , { logger : createLoggerWithInMemoryLogs ( host ) } ) ;
106
+ openFilesForSession ( [ aTs ] , session ) ;
107
107
108
- session . executeCommandSeq < ts . server . protocol . GetEditsForRefactorRequest > ( {
109
- command : ts . server . protocol . CommandTypes . GetEditsForRefactor ,
110
- arguments : {
111
- file : aTs . path ,
112
- startLine : 1 ,
113
- startOffset : 1 ,
114
- endLine : 2 ,
115
- endOffset : aTs . content . length ,
116
- refactor : "Move to file" ,
117
- action : "Move to file" ,
118
- interactiveRefactorArguments : { targetFile : "/Foo/b.ts" } ,
119
- }
108
+ session . executeCommandSeq < ts . server . protocol . GetEditsForRefactorRequest > ( {
109
+ command : ts . server . protocol . CommandTypes . GetEditsForRefactor ,
110
+ arguments : {
111
+ file : aTs . path ,
112
+ startLine : 1 ,
113
+ startOffset : 1 ,
114
+ endLine : 2 ,
115
+ endOffset : aTs . content . length ,
116
+ refactor : "Move to file" ,
117
+ action : "Move to file" ,
118
+ interactiveRefactorArguments : { targetFile : "/Foo/b.ts" } ,
119
+ }
120
+ } ) ;
121
+ baselineTsserverLogs ( "refactors" , "handles moving statement to an existing file" , session ) ;
120
122
} ) ;
121
- baselineTsserverLogs ( "refactors" , "handles moving statement to an existing file" , session ) ;
123
+
124
+ it ( "handles moving statements to a non-TS file" , ( ) => {
125
+ const aTs : File = {
126
+ path : "/Foo/a.ts" ,
127
+ content : "const x = 0;"
128
+ } ;
129
+ const bTxt : File = {
130
+ path : "/Foo/b.txt" ,
131
+ content : ""
132
+ } ;
133
+ const tsconfig : File = {
134
+ path : "/Foo/tsconfig.json" ,
135
+ content : `{ "files": ["./a.ts"] }`
136
+ } ;
137
+ const host = createServerHost ( [ aTs , bTxt , tsconfig ] ) ;
138
+ const session = createSession ( host , { logger : createLoggerWithInMemoryLogs ( host ) } ) ;
139
+ openFilesForSession ( [ aTs ] , session ) ;
140
+
141
+ session . executeCommandSeq < ts . server . protocol . GetEditsForRefactorRequest > ( {
142
+ command : ts . server . protocol . CommandTypes . GetEditsForRefactor ,
143
+ arguments : {
144
+ file : aTs . path ,
145
+ startLine : 1 ,
146
+ startOffset : 1 ,
147
+ endLine : 2 ,
148
+ endOffset : aTs . content . length ,
149
+ refactor : "Move to file" ,
150
+ action : "Move to file" ,
151
+ interactiveRefactorArguments : { targetFile : "/Foo/b.txt" } ,
152
+ }
153
+ } ) ;
154
+ baselineTsserverLogs ( "refactors" , "handles moving statements to a non-TS file" , session ) ;
122
155
} ) ;
123
156
} ) ;
0 commit comments