1
- import * as assert from 'assert' ;
1
+ import * as assert from 'assert/strict ' ;
2
2
import { describe } from 'mocha' ;
3
3
import { join } from 'node:path' ;
4
4
import { dir as tempDir } from 'tmp-promise' ;
5
- import generate , { __test , parseGitHub , parseSemver } from '../generate' ;
5
+ import generate , { __test } from '../generate' ;
6
+ import { SemVer } from 'semver' ;
6
7
7
- const { execa } = __test ;
8
+ const { parseSemver , parseGitHub , protoLocation , execa } = __test ;
8
9
9
10
describe ( 'generate' , ( ) => {
10
11
it ( "should fail when 'src' is an accessible file" , async function ( ) {
@@ -141,9 +142,9 @@ describe('generate', () => {
141
142
'protobuf' ,
142
143
'empty'
143
144
) ) ;
144
- assert . notEqual ( Empty , undefined ) ;
145
- assert . equal ( typeof Empty . fromJSON , 'function' ) ;
146
- assert . deepEqual ( Empty . fromJSON ( ) , { } ) ;
145
+ assert . notStrictEqual ( Empty , undefined ) ;
146
+ assert . strictEqual ( typeof Empty . fromJSON , 'function' ) ;
147
+ assert . deepStrictEqual ( Empty . fromJSON ( ) , { } ) ;
147
148
} finally {
148
149
await execa ( 'npm' , [ 'unlink' , 'protobufjs' ] , {
149
150
cwd : path ,
@@ -154,13 +155,13 @@ describe('generate', () => {
154
155
155
156
describe ( 'parseGitHub' , ( ) => {
156
157
it ( 'should parse valid' , ( ) => {
157
- assert . deepEqual ( parseGitHub ( 'arduino/arduino-cli' ) , {
158
+ assert . deepStrictEqual ( parseGitHub ( 'arduino/arduino-cli' ) , {
158
159
owner : 'arduino' ,
159
160
repo : 'arduino-cli' ,
160
161
} ) ;
161
162
} ) ;
162
163
it ( 'should parse valid with commit' , ( ) => {
163
- assert . deepEqual ( parseGitHub ( 'arduino/arduino-cli#5a4ffe0' ) , {
164
+ assert . deepStrictEqual ( parseGitHub ( 'arduino/arduino-cli#5a4ffe0' ) , {
164
165
owner : 'arduino' ,
165
166
repo : 'arduino-cli' ,
166
167
commit : '5a4ffe0' ,
@@ -176,29 +177,125 @@ describe('generate', () => {
176
177
'owner/repo#one two' ,
177
178
] . forEach ( ( src ) =>
178
179
it ( `should not parse '${ src } '` , ( ) =>
179
- assert . equal ( parseGitHub ( src ) , undefined ) )
180
+ assert . strictEqual ( parseGitHub ( src ) , undefined ) )
180
181
) ;
181
182
} ) ;
182
183
describe ( 'parseSemver' , ( ) => {
183
184
it ( 'should parse valid' , ( ) =>
184
- assert . equal ( parseSemver ( '0.30.0' ) , '0.30.0' ) ) ;
185
+ assert . strictEqual (
186
+ ( < SemVer > parseSemver ( '0.30.0' ) ) . version ,
187
+ '0.30.0'
188
+ ) ) ;
185
189
it ( 'should parse valid with rc' , ( ) =>
186
- assert . equal ( parseSemver ( '0.30.0-rc1' ) , '0.30.0-rc1' ) ) ;
190
+ assert . strictEqual (
191
+ ( < SemVer > parseSemver ( '0.30.0-rc1' ) ) . version ,
192
+ '0.30.0-rc1'
193
+ ) ) ;
187
194
it ( "should parse valid with 'v' prefix" , ( ) =>
188
- assert . equal ( parseSemver ( 'v0.29.1' ) , '0.29.1' ) ) ;
195
+ assert . strictEqual (
196
+ ( < SemVer > parseSemver ( 'v0.29.1' ) ) . version ,
197
+ '0.29.1'
198
+ ) ) ;
189
199
it ( "should parse valid semver '>=0.29.0' as a semver [arduino/arduino-cli#1931]" , ( ) =>
190
- assert . equal ( parseSemver ( '0.29.0' ) , '0.29.0' ) ) ;
200
+ assert . strictEqual (
201
+ ( < SemVer > parseSemver ( '0.29.0' ) ) . version ,
202
+ '0.29.0'
203
+ ) ) ;
191
204
it ( "should parse to GitHub ref when version is not greater than '0.28.0'" , ( ) =>
192
- assert . deepEqual ( parseSemver ( '0.28.0' ) , {
205
+ assert . deepStrictEqual ( parseSemver ( '0.28.0' ) , {
193
206
owner : 'arduino' ,
194
207
repo : 'arduino-cli' ,
195
208
commit : '0.28.0' ,
196
209
} ) ) ;
197
210
[ 'a' , '0' , '0.30' , '0.30.' , '0.30.0.' ] . forEach ( ( src ) =>
198
211
it ( `should not parse '${ src } '` , ( ) =>
199
- assert . equal ( parseSemver ( src ) , undefined ) )
212
+ assert . strictEqual ( parseSemver ( src ) , undefined ) )
200
213
) ;
201
214
} ) ;
215
+ describe ( 'protoLocation' , ( ) => {
216
+ (
217
+ [
218
+ [ '0.28.0' , false ] ,
219
+ [ '0.29.0-rc.1' , false ] ,
220
+ [
221
+ '0.29.0' ,
222
+ {
223
+ endpoint :
224
+ 'https://github.com/arduino/arduino-cli/releases/download/0.29.0/arduino-cli_0.29.0_proto.zip' ,
225
+ filename : 'arduino-cli_0.29.0_proto.zip' ,
226
+ } ,
227
+ ] ,
228
+ [
229
+ 'v0.29.0' ,
230
+ {
231
+ endpoint :
232
+ 'https://github.com/arduino/arduino-cli/releases/download/0.29.0/arduino-cli_0.29.0_proto.zip' ,
233
+ filename : 'arduino-cli_0.29.0_proto.zip' ,
234
+ } ,
235
+ ] ,
236
+ [
237
+ 'v0.34.2' ,
238
+ {
239
+ endpoint :
240
+ 'https://github.com/arduino/arduino-cli/releases/download/0.34.2/arduino-cli_0.34.2_proto.zip' ,
241
+ filename : 'arduino-cli_0.34.2_proto.zip' ,
242
+ } ,
243
+ ] ,
244
+ [
245
+ 'v0.35.0-rc.0' ,
246
+ {
247
+ endpoint :
248
+ 'https://github.com/arduino/arduino-cli/releases/download/0.35.0-rc.0/arduino-cli_0.35.0-rc.0_proto.zip' ,
249
+ filename : 'arduino-cli_0.35.0-rc.0_proto.zip' ,
250
+ } ,
251
+ ] ,
252
+ [
253
+ 'v0.35.0-rc.1' ,
254
+ {
255
+ endpoint :
256
+ 'https://github.com/arduino/arduino-cli/releases/download/v0.35.0-rc.1/arduino-cli_0.35.0-rc.1_proto.zip' ,
257
+ filename : 'arduino-cli_0.35.0-rc.1_proto.zip' ,
258
+ } ,
259
+ ] ,
260
+ [
261
+ 'v0.35.0' ,
262
+ {
263
+ endpoint :
264
+ 'https://github.com/arduino/arduino-cli/releases/download/v0.35.0/arduino-cli_0.35.0_proto.zip' ,
265
+ filename : 'arduino-cli_0.35.0_proto.zip' ,
266
+ } ,
267
+ ] ,
268
+ [
269
+ 'v0.35.1' ,
270
+ {
271
+ endpoint :
272
+ 'https://github.com/arduino/arduino-cli/releases/download/v0.35.1/arduino-cli_0.35.1_proto.zip' ,
273
+ filename : 'arduino-cli_0.35.1_proto.zip' ,
274
+ } ,
275
+ ] ,
276
+ ] as const
277
+ )
278
+ . map (
279
+ ( [ raw , expected ] ) =>
280
+ [ new SemVer ( raw , { loose : true } ) , expected ] as [
281
+ SemVer ,
282
+ { endpoint : string ; filename : string } | false
283
+ ]
284
+ )
285
+ . forEach ( ( [ semver , expected ] ) =>
286
+ it ( `should${
287
+ ! expected ? ' not' : ''
288
+ } get the GitHub release asset location for the protos (${
289
+ semver . raw
290
+ } )`, ( ) => {
291
+ if ( ! expected ) {
292
+ assert . throws ( ( ) => protoLocation ( semver ) ) ;
293
+ } else {
294
+ assert . deepStrictEqual ( protoLocation ( semver ) , expected ) ;
295
+ }
296
+ } )
297
+ ) ;
298
+ } ) ;
202
299
} ) ;
203
300
204
301
async function dir < T > ( test : ( path : string ) => Promise < T > ) : Promise < T > {
0 commit comments