Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 419aae1

Browse files
authored
test: remove @ts-expect-errors for this being mocha (#4250)
If we specify the return type of the `getIt` util, tsc will know what type `this` is in the test context so we can remove the error overrides.
1 parent 6ae5eb7 commit 419aae1

File tree

27 files changed

+83
-115
lines changed

27 files changed

+83
-115
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,4 @@
7373
"workspaces": [
7474
"packages/*"
7575
]
76-
}
76+
}

packages/interface-ipfs-core/src/add-all.js

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ export function testAddAll (factory, options) {
7676

7777
it('should add a File as array of tuples', async function () {
7878
if (!supportsFileReader) {
79-
// @ts-expect-error this is mocha
80-
return this.skip('skip in node')
79+
return this.skip()
8180
}
8281

8382
const tuple = {
@@ -102,8 +101,7 @@ export function testAddAll (factory, options) {
102101

103102
it('should add array of objects with readable stream content', async function () {
104103
if (!isNode) {
105-
// @ts-expect-error this is mocha
106-
this.skip('Only node supports readable streams')
104+
this.skip()
107105
}
108106

109107
const expectedCid = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS'
@@ -336,7 +334,6 @@ export function testAddAll (factory, options) {
336334
})
337335

338336
it('should add a directory with only-hash=true', async function () {
339-
// @ts-expect-error this is mocha
340337
this.slow(10 * 1000)
341338
const content = String(Math.random() + Date.now())
342339

@@ -358,21 +355,18 @@ export function testAddAll (factory, options) {
358355
})
359356

360357
it('should add with mode as string', async function () {
361-
// @ts-expect-error this is mocha
362358
this.slow(10 * 1000)
363359
const mode = '0777'
364360
await testMode(mode, parseInt(mode, 8))
365361
})
366362

367363
it('should add with mode as number', async function () {
368-
// @ts-expect-error this is mocha
369364
this.slow(10 * 1000)
370365
const mode = parseInt('0777', 8)
371366
await testMode(mode, mode)
372367
})
373368

374369
it('should add with mtime as Date', async function () {
375-
// @ts-expect-error this is mocha
376370
this.slow(10 * 1000)
377371
const mtime = new Date(5000)
378372
await testMtime(mtime, {
@@ -382,7 +376,6 @@ export function testAddAll (factory, options) {
382376
})
383377

384378
it('should add with mtime as { nsecs, secs }', async function () {
385-
// @ts-expect-error this is mocha
386379
this.slow(10 * 1000)
387380
const mtime = {
388381
secs: 5,
@@ -392,7 +385,6 @@ export function testAddAll (factory, options) {
392385
})
393386

394387
it('should add with mtime as timespec', async function () {
395-
// @ts-expect-error this is mocha
396388
this.slow(10 * 1000)
397389
await testMtime({
398390
Seconds: 5,
@@ -404,7 +396,6 @@ export function testAddAll (factory, options) {
404396
})
405397

406398
it('should add with mtime as hrtime', async function () {
407-
// @ts-expect-error this is mocha
408399
this.slow(10 * 1000)
409400
const mtime = process.hrtime()
410401
await testMtime(mtime, {
@@ -414,7 +405,6 @@ export function testAddAll (factory, options) {
414405
})
415406

416407
it('should add a directory from the file system', async function () {
417-
// @ts-expect-error this is mocha
418408
if (!isNode) this.skip()
419409
const filesPath = resolve('test/fixtures/test-folder', 'interface-ipfs-core')
420410

@@ -423,7 +413,6 @@ export function testAddAll (factory, options) {
423413
})
424414

425415
it('should add a directory from the file system with an odd name', async function () {
426-
// @ts-expect-error this is mocha
427416
if (!isNode) this.skip()
428417

429418
const filesPath = resolve('test/fixtures/weird name folder [v0]', 'interface-ipfs-core')
@@ -433,7 +422,6 @@ export function testAddAll (factory, options) {
433422
})
434423

435424
it('should ignore a directory from the file system', async function () {
436-
// @ts-expect-error this is mocha
437425
if (!isNode) this.skip()
438426

439427
const filesPath = resolve('test/fixtures/test-folder', 'interface-ipfs-core')
@@ -443,7 +431,6 @@ export function testAddAll (factory, options) {
443431
})
444432

445433
it('should add a file from the file system', async function () {
446-
// @ts-expect-error this is mocha
447434
if (!isNode) this.skip()
448435

449436
const filePath = resolve('test/fixtures/test-folder', 'interface-ipfs-core')
@@ -454,7 +441,6 @@ export function testAddAll (factory, options) {
454441
})
455442

456443
it('should add a hidden file in a directory from the file system', async function () {
457-
// @ts-expect-error this is mocha
458444
if (!isNode) this.skip()
459445

460446
const filesPath = resolve('test/fixtures', 'interface-ipfs-core')
@@ -465,10 +451,8 @@ export function testAddAll (factory, options) {
465451
})
466452

467453
it('should add a file with only-hash=true', async function () {
468-
// @ts-expect-error this is mocha
469454
if (!isNode) this.skip()
470455

471-
// @ts-expect-error this is mocha
472456
this.slow(10 * 1000)
473457

474458
const out = await all(ipfs.addAll([{

packages/interface-ipfs-core/src/add.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ export function testAdd (factory, options) {
7373

7474
it('should add a File', async function () {
7575
if (!supportsFileReader) {
76-
// @ts-expect-error this is mocha
77-
return this.skip('skip in node')
76+
return this.skip()
7877
}
7978

8079
const fileAdded = await ipfs.add(new File(['should add a File'], 'filename.txt', { type: 'text/plain' }))
@@ -83,8 +82,7 @@ export function testAdd (factory, options) {
8382

8483
it('should add a File as tuple', async function () {
8584
if (!supportsFileReader) {
86-
// @ts-expect-error this is mocha
87-
return this.skip('skip in node')
85+
return this.skip()
8886
}
8987

9088
const tuple = {
@@ -212,7 +210,6 @@ export function testAdd (factory, options) {
212210

213211
it('should add readable stream', async function () {
214212
if (!isNode) {
215-
// @ts-expect-error this is mocha
216213
this.skip()
217214
}
218215
const expectedCid = 'QmVv4Wz46JaZJeH5PMV4LGbRiiMKEmszPYY3g6fjGnVXBS'
@@ -264,7 +261,6 @@ export function testAdd (factory, options) {
264261
})
265262

266263
it('should add with only-hash=true', async function () {
267-
// @ts-expect-error this is mocha
268264
this.slow(10 * 1000)
269265
const content = String(Math.random() + Date.now())
270266

@@ -292,21 +288,18 @@ export function testAdd (factory, options) {
292288
})
293289

294290
it('should add with mode as string', async function () {
295-
// @ts-expect-error this is mocha
296291
this.slow(10 * 1000)
297292
const mode = '0777'
298293
await testMode(mode, parseInt(mode, 8))
299294
})
300295

301296
it('should add with mode as number', async function () {
302-
// @ts-expect-error this is mocha
303297
this.slow(10 * 1000)
304298
const mode = parseInt('0777', 8)
305299
await testMode(mode, mode)
306300
})
307301

308302
it('should add with mtime as Date', async function () {
309-
// @ts-expect-error this is mocha
310303
this.slow(10 * 1000)
311304
const mtime = new Date(5000)
312305
await testMtime(mtime, {
@@ -316,7 +309,6 @@ export function testAdd (factory, options) {
316309
})
317310

318311
it('should add with mtime as { nsecs, secs }', async function () {
319-
// @ts-expect-error this is mocha
320312
this.slow(10 * 1000)
321313
const mtime = {
322314
secs: 5,
@@ -326,7 +318,6 @@ export function testAdd (factory, options) {
326318
})
327319

328320
it('should add with mtime as timespec', async function () {
329-
// @ts-expect-error this is mocha
330321
this.slow(10 * 1000)
331322
await testMtime({
332323
Seconds: 5,
@@ -338,7 +329,6 @@ export function testAdd (factory, options) {
338329
})
339330

340331
it('should add with mtime as hrtime', async function () {
341-
// @ts-expect-error this is mocha
342332
this.slow(10 * 1000)
343333
const mtime = process.hrtime()
344334
await testMtime(mtime, {

packages/interface-ipfs-core/src/dag/export.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ export function testExport (factory, options) {
7272
})
7373

7474
it('export of shuffled devnet export identical to canonical original', async function () {
75-
// @ts-expect-error this is mocha
7675
this.timeout(360000)
7776

7877
const input = loadFixture('test/fixtures/car/lotus_devnet_genesis.car', 'interface-ipfs-core')
@@ -83,7 +82,6 @@ export function testExport (factory, options) {
8382
})
8483

8584
it('export of shuffled testnet export identical to canonical original', async function () {
86-
// @ts-expect-error this is mocha
8785
this.timeout(360000)
8886

8987
const input = loadFixture('test/fixtures/car/lotus_testnet_export_128.car', 'interface-ipfs-core')

packages/interface-ipfs-core/src/files/touch.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export function testTouch (factory, options) {
5353
after(() => factory.clean())
5454

5555
it('should have default mtime', async function () {
56-
// @ts-expect-error this is mocha
5756
this.slow(5 * 1000)
5857
const testPath = `/test-${nanoid()}`
5958

@@ -74,7 +73,6 @@ export function testTouch (factory, options) {
7473
})
7574

7675
it('should update file mtime', async function () {
77-
// @ts-expect-error this is mocha
7876
this.slow(5 * 1000)
7977
const testPath = `/test-${nanoid()}`
8078
const mtime = new Date()
@@ -92,7 +90,6 @@ export function testTouch (factory, options) {
9290
})
9391

9492
it('should update directory mtime', async function () {
95-
// @ts-expect-error this is mocha
9693
this.slow(5 * 1000)
9794
const testPath = `/test-${nanoid()}`
9895
const mtime = new Date()

packages/interface-ipfs-core/src/files/write.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ export function testWrite (factory, options) {
188188

189189
it('writes a small file using a Node stream (Node only)', async function () {
190190
if (!isNode) {
191-
// @ts-expect-error this is mocha
192191
this.skip()
193192
}
194193
const filePath = `/small-file-${Math.random()}.txt`
@@ -205,7 +204,6 @@ export function testWrite (factory, options) {
205204

206205
it('writes a small file using an HTML5 Blob (Browser only)', async function () {
207206
if (!global.Blob || !global.FileReader) {
208-
// @ts-expect-error this is mocha
209207
return this.skip()
210208
}
211209

packages/interface-ipfs-core/src/key/gen.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export function testGen (factory, options) {
4444

4545
keyTypes.forEach((kt) => {
4646
it(`should generate a new ${kt.opts.type || 'default'} key`, async function () {
47-
// @ts-expect-error this is mocha
4847
this.timeout(20 * 1000)
4948
const name = nanoid()
5049
const key = await ipfs.key.gen(name, kt.opts)
@@ -61,8 +60,7 @@ export function testGen (factory, options) {
6160
} catch (/** @type {any} */ err) {
6261
if (err.code === 'ERR_NOT_IMPLEMENTED') {
6362
// key export is not exposed over the HTTP API
64-
// @ts-expect-error this is mocha
65-
this.skip('Cannot verify key type')
63+
this.skip()
6664
}
6765

6866
throw err

packages/interface-ipfs-core/src/key/list.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export function testList (factory, options) {
2727
after(() => factory.clean())
2828

2929
it('should list all the keys', async function () {
30-
// @ts-expect-error this is mocha
3130
this.timeout(60 * 1000)
3231

3332
const keys = await Promise.all([1, 2, 3].map(() => ipfs.key.gen(nanoid(), { type: 'rsa', size: 2048 })))

packages/interface-ipfs-core/src/key/rename.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export function testRename (factory, options) {
2727
after(() => factory.clean())
2828

2929
it('should rename a key', async function () {
30-
// @ts-expect-error this is mocha
3130
this.timeout(30 * 1000)
3231

3332
const oldName = nanoid()

packages/interface-ipfs-core/src/key/rm.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export function testRm (factory, options) {
2727
after(() => factory.clean())
2828

2929
it('should rm a key', async function () {
30-
// @ts-expect-error this is mocha
3130
this.timeout(30 * 1000)
3231

3332
const key = await ipfs.key.gen(nanoid(), { type: 'rsa', size: 2048 })

0 commit comments

Comments
 (0)