Skip to content

Commit a683cff

Browse files
authoredAug 15, 2022
fix: linting (#121)
1 parent e8d1e85 commit a683cff

18 files changed

+1050
-1403
lines changed
 

‎lib/content/read.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function readStream (cache, integrity, opts = {}) {
8181
return stream.emit('error', sizeError(size, stat.size))
8282
}
8383

84-
readPipeline(cpath, stat.size, sri, stream)
84+
return readPipeline(cpath, stat.size, sri, stream)
8585
}).catch(err => stream.emit('error', err))
8686

8787
return stream

‎lib/content/write.js

+2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ class CacacheWriteStream extends Flush {
8080
// defer this one tick by rejecting a promise on it.
8181
return Promise.reject(e).catch(cb)
8282
}
83+
// eslint-disable-next-line promise/catch-or-return
8384
this.handleContentP.then(
8485
(res) => {
8586
res.integrity && this.emit('integrity', res.integrity)
87+
// eslint-disable-next-line promise/always-return
8688
res.size !== null && this.emit('size', res.size)
8789
cb()
8890
},

‎lib/entry-index.js

+1
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ function lsStream (cache) {
285285
}))
286286
}))
287287
stream.end()
288+
return stream
288289
}).catch(err => stream.emit('error', err))
289290

290291
return stream

‎lib/get.js

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ function getStream (cache, key, opts = {}) {
155155
stream.unshift(memoStream)
156156
}
157157
stream.unshift(src)
158+
return stream
158159
}).catch((err) => stream.emit('error', err))
159160

160161
return stream

‎test/content/read.js

+65-103
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ const getReadStatFailure = (t, err) => getRead(t, {
2828
}),
2929
})
3030

31-
t.test('read: returns a Promise with cache content data', function (t) {
31+
t.test('read: returns a Promise with cache content data', async t => {
3232
const CONTENT = Buffer.from('foobarbaz')
3333
const INTEGRITY = ssri.fromData(CONTENT)
3434
const CACHE = t.testdir(
3535
CacheContent({
3636
[INTEGRITY]: CONTENT,
3737
})
3838
)
39-
return read(CACHE, INTEGRITY).then((data) => {
40-
t.same(data, CONTENT, 'cache contents read correctly')
41-
})
39+
const data = await read(CACHE, INTEGRITY)
40+
t.same(data, CONTENT, 'cache contents read correctly')
4241
})
4342

4443
t.test('read.sync: reads synchronously', (t) => {
@@ -54,7 +53,7 @@ t.test('read.sync: reads synchronously', (t) => {
5453
t.end()
5554
})
5655

57-
t.test('read.stream: returns a stream with cache content data', function (t) {
56+
t.test('read.stream: returns a stream with cache content data', async t => {
5857
const CONTENT = Buffer.from('foobarbaz')
5958
const INTEGRITY = ssri.fromData(CONTENT)
6059
const CACHE = t.testdir(
@@ -63,16 +62,15 @@ t.test('read.stream: returns a stream with cache content data', function (t) {
6362
})
6463
)
6564
const stream = read.stream(CACHE, INTEGRITY)
66-
return Promise.all([
65+
const [fromStream, fromBulk] = await Promise.all([
6766
stream.concat(),
6867
read(CACHE, INTEGRITY, { size: CONTENT.length }),
69-
]).then(([fromStream, fromBulk]) => {
70-
t.same(fromStream, CONTENT, 'stream data checks out')
71-
t.same(fromBulk, CONTENT, 'promise data checks out')
72-
})
68+
])
69+
t.same(fromStream, CONTENT, 'stream data checks out')
70+
t.same(fromBulk, CONTENT, 'promise data checks out')
7371
})
7472

75-
t.test('read: allows hashAlgorithm configuration', function (t) {
73+
t.test('read: allows hashAlgorithm configuration', async t => {
7674
const CONTENT = Buffer.from('foobarbaz')
7775
const HASH = 'sha384'
7876
const INTEGRITY = ssri.fromData(CONTENT, { algorithms: [HASH] })
@@ -82,16 +80,15 @@ t.test('read: allows hashAlgorithm configuration', function (t) {
8280
})
8381
)
8482
const stream = read.stream(CACHE, INTEGRITY)
85-
return Promise.all([
83+
const [fromStream, fromBulk] = await Promise.all([
8684
stream.concat(),
8785
read(CACHE, INTEGRITY),
88-
]).then(([fromStream, fromBulk]) => {
89-
t.same(fromStream, CONTENT, 'stream used algorithm')
90-
t.same(fromBulk, CONTENT, 'promise used algorithm')
91-
})
86+
])
87+
t.same(fromStream, CONTENT, 'stream used algorithm')
88+
t.same(fromBulk, CONTENT, 'promise used algorithm')
9289
})
9390

94-
t.test('read: errors if content missing', function (t) {
91+
t.test('read: errors if content missing', async t => {
9592
const CACHE = t.testdir({})
9693
const stream = read.stream(CACHE, 'sha512-whatnot')
9794
stream.on('data', function (data) {
@@ -100,28 +97,19 @@ t.test('read: errors if content missing', function (t) {
10097
stream.on('end', function () {
10198
throw new Error('end was emitted even though stream errored')
10299
})
103-
return Promise.all([
104-
stream.promise().catch((err) => {
105-
if (err.code === 'ENOENT') {
106-
return err
107-
}
108-
109-
throw err
110-
}),
111-
read(CACHE, 'sha512-whatnot').catch((err) => {
112-
if (err.code === 'ENOENT') {
113-
return err
114-
}
115-
116-
throw err
117-
}),
118-
]).then(([streamErr, bulkErr]) => {
119-
t.match(streamErr, { code: 'ENOENT' }, 'stream got the right error')
120-
t.match(bulkErr, { code: 'ENOENT' }, 'bulk got the right error')
121-
})
100+
await t.rejects(
101+
stream.promise(),
102+
{ code: 'ENOENT' },
103+
'stream got the right error'
104+
)
105+
await t.rejects(
106+
read(CACHE, 'sha512-whatnot'),
107+
{ code: 'ENOENT' },
108+
'bulk got the right error'
109+
)
122110
})
123111

124-
t.test('read: errors if content fails checksum', function (t) {
112+
t.test('read: errors if content fails checksum', async t => {
125113
const CONTENT = Buffer.from('foobarbaz')
126114
const INTEGRITY = ssri.fromData(CONTENT)
127115
const CACHE = t.testdir(
@@ -133,28 +121,19 @@ t.test('read: errors if content fails checksum', function (t) {
133121
stream.on('end', function () {
134122
throw new Error('end was emitted even though stream errored')
135123
})
136-
return Promise.all([
137-
stream.promise().catch((err) => {
138-
if (err.code === 'EINTEGRITY') {
139-
return err
140-
}
141-
142-
throw err
143-
}),
144-
read(CACHE, INTEGRITY).catch((err) => {
145-
if (err.code === 'EINTEGRITY') {
146-
return err
147-
}
148-
149-
throw err
150-
}),
151-
]).then(([streamErr, bulkErr]) => {
152-
t.match(streamErr, { code: 'EINTEGRITY' }, 'stream got the right error')
153-
t.match(bulkErr, { code: 'EINTEGRITY' }, 'bulk got the right error')
154-
})
124+
await t.rejects(
125+
stream.promise(),
126+
{ code: 'EINTEGRITY' },
127+
'stream got the right error'
128+
)
129+
await t.rejects(
130+
read(CACHE, INTEGRITY),
131+
{ code: 'EINTEGRITY' },
132+
'bulk got the right error'
133+
)
155134
})
156135

157-
t.test('read: errors if content size does not match size option', function (t) {
136+
t.test('read: errors if content size does not match size option', async t => {
158137
const CONTENT = Buffer.from('foobarbaz')
159138
const INTEGRITY = ssri.fromData(CONTENT)
160139
const CACHE = t.testdir(
@@ -166,27 +145,16 @@ t.test('read: errors if content size does not match size option', function (t) {
166145
stream.on('end', function () {
167146
throw new Error('end was called even though stream errored')
168147
})
169-
return Promise.all([
170-
stream.promise().catch((err) => {
171-
if (err.code === 'EBADSIZE') {
172-
return err
173-
}
174-
175-
throw err
176-
}),
177-
read(CACHE, INTEGRITY, {
178-
size: CONTENT.length,
179-
}).catch((err) => {
180-
if (err.code === 'EBADSIZE') {
181-
return err
182-
}
183-
184-
throw err
185-
}),
186-
]).then(([streamErr, bulkErr]) => {
187-
t.match(streamErr, { code: 'EBADSIZE' }, 'stream got the right error')
188-
t.match(bulkErr, { code: 'EBADSIZE' }, 'bulk got the right error')
189-
})
148+
await t.rejects(
149+
stream.promise(),
150+
{ code: 'EBADSIZE' },
151+
'stream got the right error'
152+
)
153+
await t.rejects(
154+
read(CACHE, INTEGRITY, { size: CONTENT.length }),
155+
{ code: 'EBADSIZE' },
156+
'bulk got the right error'
157+
)
190158
})
191159

192160
t.test('read: error while parsing provided integrity data', function (t) {
@@ -344,27 +312,26 @@ t.test('read.sync: content size value does not match option', (t) => {
344312
t.end()
345313
})
346314

347-
t.test('hasContent: tests content existence', (t) => {
315+
t.test('hasContent: tests content existence', async t => {
348316
const CACHE = t.testdir(
349317
CacheContent({
350318
'sha1-deadbeef': '',
351319
})
352320
)
353-
return Promise.all([
354-
read.hasContent(CACHE, 'sha1-deadbeef').then((content) => {
355-
t.ok(content.sri, 'returned sri for this content')
356-
t.equal(content.size, 0, 'returned the right size for this content')
357-
t.ok(content.stat.isFile(), 'returned actual stat object')
358-
}),
359-
read.hasContent(CACHE, 'sha1-not-there').then((content) => {
360-
t.equal(content, false, 'returned false for missing content')
361-
}),
362-
read
363-
.hasContent(CACHE, 'sha1-not-here sha1-also-not-here')
364-
.then((content) => {
365-
t.equal(content, false, 'multi-content hash failures work ok')
366-
}),
367-
])
321+
const content = await read.hasContent(CACHE, 'sha1-deadbeef')
322+
t.ok(content.sri, 'returned sri for this content')
323+
t.equal(content.size, 0, 'returned the right size for this content')
324+
t.ok(content.stat.isFile(), 'returned actual stat object')
325+
await t.resolveMatch(
326+
read.hasContent(CACHE, 'sha1-not-there'),
327+
false,
328+
'returned false for missing content'
329+
)
330+
await t.resolveMatch(
331+
read.hasContent(CACHE, 'sha1-not-here sha1-also-not-here'),
332+
false,
333+
'multi-content hash failures work ok'
334+
)
368335
})
369336

370337
t.test('hasContent: permission error', (t) => {
@@ -457,7 +424,7 @@ t.test('hasContent.sync: no integrity provided', (t) => {
457424
t.end()
458425
})
459426

460-
t.test('copy: copies content to a destination path', (t) => {
427+
t.test('copy: copies content to a destination path', async t => {
461428
const CONTENT = Buffer.from('foobarbaz')
462429
const INTEGRITY = ssri.fromData(CONTENT)
463430
const CACHE = t.testdir(
@@ -466,14 +433,9 @@ t.test('copy: copies content to a destination path', (t) => {
466433
})
467434
)
468435
const DEST = path.join(CACHE, 'foobar-file')
469-
return read
470-
.copy(CACHE, INTEGRITY, DEST)
471-
.then(() => {
472-
return fs.readFile(DEST)
473-
})
474-
.then((data) => {
475-
t.same(data, CONTENT, 'file successfully copied')
476-
})
436+
await read.copy(CACHE, INTEGRITY, DEST)
437+
const data = await fs.readFile(DEST)
438+
t.same(data, CONTENT, 'file successfully copied')
477439
})
478440

479441
t.test('copy.sync: copies content to a destination path synchronously', (t) => {

‎test/content/write.chownr.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const t = require('tap')
1212

1313
const contentPath = require('../../lib/content/path')
1414

15-
t.test('infers ownership from cache folder owner', (t) => {
15+
t.test('infers ownership from cache folder owner', async t => {
1616
const CACHE = t.testdir({ cache: {} })
1717
const CONTENT = 'foobarbaz'
1818
const INTEGRITY = ssri.fromData(CONTENT)
@@ -32,21 +32,16 @@ t.test('infers ownership from cache folder owner', (t) => {
3232
},
3333
})
3434
t.plan(7)
35-
return write.stream(CACHE, { hashAlgorithm: 'sha1' })
36-
.end(CONTENT)
37-
.promise()
38-
.then(() => {
39-
const cpath = contentPath(CACHE, INTEGRITY)
40-
const expectedPaths = [
41-
path.join(CACHE, path.relative(CACHE, cpath).split(path.sep)[0]),
42-
cpath,
43-
path.join(CACHE, 'tmp'),
44-
]
45-
t.same(
46-
updatedPaths.sort(),
47-
expectedPaths,
48-
'all paths that needed user stuff set got set'
49-
)
50-
})
51-
}
52-
)
35+
await write.stream(CACHE, { hashAlgorithm: 'sha1' }).end(CONTENT).promise()
36+
const cpath = contentPath(CACHE, INTEGRITY)
37+
const expectedPaths = [
38+
path.join(CACHE, path.relative(CACHE, cpath).split(path.sep)[0]),
39+
cpath,
40+
path.join(CACHE, 'tmp'),
41+
]
42+
t.same(
43+
updatedPaths.sort(),
44+
expectedPaths,
45+
'all paths that needed user stuff set got set'
46+
)
47+
})

0 commit comments

Comments
 (0)
Please sign in to comment.