@@ -3,7 +3,7 @@ import * as http from 'http';
3
3
import * as nodeStatic from 'node-static' ;
4
4
import * as os from 'os' ;
5
5
import * as path from 'path' ;
6
- import * as tape from 'tape' ;
6
+ import tape from 'tape' ;
7
7
import * as tmp from 'tmp-promise' ;
8
8
9
9
import * as install from '../src/index' ;
@@ -12,7 +12,7 @@ const oldClangd = process.cwd() + '/test/assets/fake-clangd-5/clangd';
12
12
const newClangdV15 = process . cwd ( ) + '/test/assets/fake-clangd-15/clangd' ;
13
13
const newClangdV16 = process . cwd ( ) + '/test/assets/fake-clangd-16/clangd' ;
14
14
const unversionedClangd =
15
- process . cwd ( ) + '/test/assets/fake-clangd-unversioned/clangd' ;
15
+ process . cwd ( ) + '/test/assets/fake-clangd-unversioned/clangd' ;
16
16
const appleClangd = process . cwd ( ) + '/test/assets/apple-clangd-5/clangd' ;
17
17
const exactLdd = process . cwd ( ) + '/test/assets/ldd/exact' ;
18
18
const oldLdd = process . cwd ( ) + '/test/assets/ldd/old' ;
@@ -49,9 +49,15 @@ class FakeUI {
49
49
console . info ( msg , url ) ;
50
50
}
51
51
52
- promptReload ( ) { this . event ( 'promptReload' ) ; }
53
- promptUpdate ( ) { this . event ( 'promptUpdate' ) ; }
54
- promptInstall ( ) { this . event ( 'promptInstall' ) ; }
52
+ promptReload ( ) {
53
+ this . event ( 'promptReload' ) ;
54
+ }
55
+ promptUpdate ( ) {
56
+ this . event ( 'promptUpdate' ) ;
57
+ }
58
+ promptInstall ( ) {
59
+ this . event ( 'promptInstall' ) ;
60
+ }
55
61
public shouldReuseValue = true ;
56
62
async shouldReuse ( ) {
57
63
this . event ( 'shouldReuse' ) ;
@@ -62,86 +68,127 @@ class FakeUI {
62
68
this . event ( 'slow' ) ;
63
69
return work ;
64
70
}
65
- progress < T > ( _title : string , _cancel : any ,
66
- work : ( progress : ( fraction : number ) => void ) => Promise < T > ) {
71
+ progress < T > (
72
+ _title : string ,
73
+ _cancel : any ,
74
+ work : ( progress : ( fraction : number ) => void ) => Promise < T > ,
75
+ ) {
67
76
this . event ( 'progress' ) ;
68
77
return work ( ( fraction ) => console . log ( 'progress% ' , 100 * fraction ) ) ;
69
78
}
70
- localize ( message : string , ...args : Array < string | number | boolean > ) : string {
79
+ localize ( message : string , ...args : Array < string | number | boolean > ) : string {
71
80
let ret = message ;
72
81
for ( const i in args ) {
73
82
ret . replace ( `{${ i } }` , args [ i ] . toString ( ) ) ;
74
83
}
75
84
return ret ;
76
85
}
77
- } ;
78
-
79
- function test ( name : string ,
80
- body : ( assert : tape . Test , ui : FakeUI ) => Promise < any > ) {
81
- tape ( name , async ( assert ) => tmp . withDir ( async dir => {
82
- const ui = new FakeUI ( dir . path ) ;
83
- const files = new nodeStatic . Server ( 'test/assets/' ) ;
84
- return new Promise ( ( resolve , _reject ) => {
85
- const server = http . createServer ( ( req , res ) => {
86
- console . log ( 'Fake github:' , req . method , req . url ) ;
87
- req . on ( 'end' , ( ) => files . serve ( req , res ) ) . resume ( ) ;
88
- } )
89
- . listen ( 9999 , '::' , async ( ) => {
90
- console . log ( 'Fake github serving...' ) ;
91
- install . fakeGitHubReleaseURL ( releases ) ;
92
- install . fakeLddCommand ( exactLdd ) ;
93
- try {
94
- await body ( assert , ui ) ;
95
- } catch ( e ) {
96
- assert . fail ( e ) ;
97
- }
98
- console . log ( 'Fake github stopping...' ) ;
99
- server . close ( ) ;
100
- resolve ( ) ;
101
- } ) ;
102
- } ) ;
103
- } , { unsafeCleanup : true } ) ) ;
86
+ }
87
+
88
+ function test (
89
+ name : string ,
90
+ body : ( assert : tape . Test , ui : FakeUI ) => Promise < any > ,
91
+ ) {
92
+ tape ( name , async ( assert ) =>
93
+ tmp . withDir (
94
+ async ( dir ) => {
95
+ const ui = new FakeUI ( dir . path ) ;
96
+ const files = new nodeStatic . Server ( 'test/assets/' ) ;
97
+ return new Promise ( ( resolve , _reject ) => {
98
+ const server = http
99
+ . createServer ( ( req , res ) => {
100
+ console . log ( 'Fake github:' , req . method , req . url ) ;
101
+ req . on ( 'end' , ( ) => files . serve ( req , res ) ) . resume ( ) ;
102
+ } )
103
+ . listen ( 9999 , '::' , async ( ) => {
104
+ console . log ( 'Fake github serving...' ) ;
105
+ install . fakeGitHubReleaseURL ( releases ) ;
106
+ install . fakeLddCommand ( exactLdd ) ;
107
+ try {
108
+ await body ( assert , ui ) ;
109
+ } catch ( e ) {
110
+ assert . fail ( e as string ) ;
111
+ }
112
+ console . log ( 'Fake github stopping...' ) ;
113
+ server . close ( ) ;
114
+ resolve ( ) ;
115
+ } ) ;
116
+ } ) ;
117
+ } ,
118
+ { unsafeCleanup : true } ,
119
+ ) ,
120
+ ) ;
104
121
}
105
122
106
123
// Test the actual installation, typically the clangd.install command.
107
124
108
125
test ( 'install' , async ( assert , ui ) => {
109
126
await install . installLatest ( ui ) ;
110
127
111
- const installedClangd =
112
- path . join ( ui . storagePath , 'install' , '10.0' , 'fake-clangd-10' , 'clangd' ) ;
113
- assert . true ( fs . existsSync ( installedClangd ) ,
114
- `Extracted clangd exists: ${ installedClangd } ` ) ;
128
+ const installedClangd = path . join (
129
+ ui . storagePath ,
130
+ 'install' ,
131
+ '10.0' ,
132
+ 'fake-clangd-10' ,
133
+ 'clangd' ,
134
+ ) ;
135
+ assert . true (
136
+ fs . existsSync ( installedClangd ) ,
137
+ `Extracted clangd exists: ${ installedClangd } ` ,
138
+ ) ;
115
139
assert . equal ( ui . clangdPath , installedClangd ) ;
116
- assert . deepEqual (
117
- ui . events , [ /*download*/ 'progress' , /*extract*/ 'slow' , 'promptReload' ] ) ;
140
+ assert . deepEqual ( ui . events , [
141
+ /*download*/ 'progress' ,
142
+ /*extract*/ 'slow' ,
143
+ 'promptReload' ,
144
+ ] ) ;
118
145
} ) ;
119
146
120
147
test ( 'install: no binary for platform' , async ( assert , ui ) => {
121
148
install . fakeGitHubReleaseURL ( incompatibleReleases ) ;
122
149
await install . installLatest ( ui ) ;
123
150
124
- const installedClangd =
125
- path . join ( ui . storagePath , 'install' , '10.0' , 'fake-clangd-10' , 'clangd' ) ;
126
- assert . false ( fs . existsSync ( installedClangd ) ,
127
- `Extracted clangd exists: ${ installedClangd } ` ) ;
128
- assert . true ( ui . clangdPath . endsWith ( 'fake-clangd-5/clangd' ) ,
129
- 'clangdPath unmodified' ) ;
151
+ const installedClangd = path . join (
152
+ ui . storagePath ,
153
+ 'install' ,
154
+ '10.0' ,
155
+ 'fake-clangd-10' ,
156
+ 'clangd' ,
157
+ ) ;
158
+ assert . false (
159
+ fs . existsSync ( installedClangd ) ,
160
+ `Extracted clangd exists: ${ installedClangd } ` ,
161
+ ) ;
162
+ assert . true (
163
+ ui . clangdPath . endsWith ( 'fake-clangd-5/clangd' ) ,
164
+ 'clangdPath unmodified' ,
165
+ ) ;
130
166
assert . deepEqual ( ui . events , [ 'showHelp' ] ) ;
131
167
} ) ;
132
168
133
169
test ( 'install: wrong url' , async ( assert , ui ) => {
134
170
install . fakeGitHubReleaseURL ( wrongUrlReleases ) ;
135
171
await install . installLatest ( ui ) ;
136
172
137
- const installedClangd =
138
- path . join ( ui . storagePath , 'install' , '10.0' , 'fake-clangd-10' , 'clangd' ) ;
139
- assert . false ( fs . existsSync ( installedClangd ) ,
140
- `Extracted clangd exists: ${ installedClangd } ` ) ;
141
- assert . true ( ui . clangdPath . endsWith ( 'fake-clangd-5/clangd' ) ,
142
- 'clangdPath unmodified' ) ;
143
- assert . deepEqual ( ui . events ,
144
- [ /*download*/ 'progress' , /*download-fails*/ 'showHelp' ] ) ;
173
+ const installedClangd = path . join (
174
+ ui . storagePath ,
175
+ 'install' ,
176
+ '10.0' ,
177
+ 'fake-clangd-10' ,
178
+ 'clangd' ,
179
+ ) ;
180
+ assert . false (
181
+ fs . existsSync ( installedClangd ) ,
182
+ `Extracted clangd exists: ${ installedClangd } ` ,
183
+ ) ;
184
+ assert . true (
185
+ ui . clangdPath . endsWith ( 'fake-clangd-5/clangd' ) ,
186
+ 'clangdPath unmodified' ,
187
+ ) ;
188
+ assert . deepEqual ( ui . events , [
189
+ /*download*/ 'progress' ,
190
+ /*download-fails*/ 'showHelp' ,
191
+ ] ) ;
145
192
} ) ;
146
193
147
194
if ( os . platform ( ) == 'linux' ) {
@@ -177,8 +224,13 @@ test('install: reuse existing install', async (assert, ui) => {
177
224
ui . shouldReuseValue = true ;
178
225
await install . installLatest ( ui ) ;
179
226
180
- const installedClangd =
181
- path . join ( ui . storagePath , 'install' , '10.0' , 'fake-clangd-10' , 'clangd' ) ;
227
+ const installedClangd = path . join (
228
+ ui . storagePath ,
229
+ 'install' ,
230
+ '10.0' ,
231
+ 'fake-clangd-10' ,
232
+ 'clangd' ,
233
+ ) ;
182
234
assert . false ( fs . existsSync ( installedClangd ) , 'Not extracted' ) ;
183
235
assert . true ( fs . existsSync ( existingClangd ) , 'Not erased' ) ;
184
236
assert . equal ( existingClangd , ui . clangdPath , 'clangdPath is existing install' ) ;
@@ -194,13 +246,21 @@ test('install: overwrite existing install', async (assert, ui) => {
194
246
ui . shouldReuseValue = false ;
195
247
await install . installLatest ( ui ) ;
196
248
197
- const installedClangd =
198
- path . join ( ui . storagePath , 'install' , '10.0' , 'fake-clangd-10' , 'clangd' ) ;
249
+ const installedClangd = path . join (
250
+ ui . storagePath ,
251
+ 'install' ,
252
+ '10.0' ,
253
+ 'fake-clangd-10' ,
254
+ 'clangd' ,
255
+ ) ;
199
256
assert . true ( fs . existsSync ( installedClangd ) , 'Extracted' ) ;
200
257
assert . false ( fs . existsSync ( existingClangd ) , 'Erased' ) ;
201
258
assert . equal ( installedClangd , ui . clangdPath , 'clangdPath is new install' ) ;
202
259
assert . deepEqual ( ui . events , [
203
- 'shouldReuse' , /*download*/ 'progress' , /*extract*/ 'slow' , 'promptReload'
260
+ 'shouldReuse' ,
261
+ /*download*/ 'progress' ,
262
+ /*extract*/ 'slow' ,
263
+ 'promptReload' ,
204
264
] ) ;
205
265
} ) ;
206
266
0 commit comments