Skip to content

Commit 85f9af8

Browse files
authored
Add c8 for code coverage reporting fail on less than 95% coverage (#9)
- Increase coverage to meet these standards I’m so close to 100% but testing some of these possible error conditions is beyond what I can figure out tonight. I feel like the possible state machine of errors that SI can see is larger than the errors that can actually be produced. If I could prove that I could have less code, but since I can’t I’m going to have to rely on reason instead of tests to prove it. Also reporting of coverage sucks on node 10, it’s less than the other versions, so I disabled it.
1 parent 382b961 commit 85f9af8

17 files changed

+454
-25
lines changed

.github/workflows/test.yml

+4
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ jobs:
2020
npm test
2121
env:
2222
CI: true
23+
- name: Check Coverage Levels
24+
if: ${{ matrix.node-version != '10.x' }}
25+
run: |
26+
npm run check-coverage

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
node_modules
1+
coverage
22
dist
33
dist-ts
4+
node_modules

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
api-extractor.json
66
benchmark
77
budle-types.js
8+
coverage
89
dist-ts
910
lib
1011
package-lock.json

lib/batch-test.ts

+4-12
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,18 @@ function* numbers(max: number) {
2121
describe('batch', () => {
2222
it('batches async iterators', async () => {
2323
const batches: number[][] = []
24-
for await (const numberBatch of batch(5, asyncNumbers(10))) {
25-
assert.equal(numberBatch.length, 5)
24+
for await (const numberBatch of batch(5, asyncNumbers(11))) {
2625
batches.push(numberBatch)
2726
}
28-
assert.deepEqual(batches, [
29-
[1, 2, 3, 4, 5],
30-
[6, 7, 8, 9, 10],
31-
])
27+
assert.deepEqual(batches, [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11]])
3228
})
3329

3430
it('batches sync iterators', async () => {
3531
const batches: number[][] = []
36-
for await (const numberBatch of batch(5, numbers(10))) {
37-
assert.equal(numberBatch.length, 5)
32+
for await (const numberBatch of batch(5, numbers(11))) {
3833
batches.push(numberBatch)
3934
}
40-
assert.deepEqual(batches, [
41-
[1, 2, 3, 4, 5],
42-
[6, 7, 8, 9, 10],
43-
])
35+
assert.deepEqual(batches, [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11]])
4436
})
4537

4638
it('is curryable', async () => {

lib/flat-map-test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,12 @@ describe('flatmap', () => {
2727
}
2828
assert.deepEqual(numbers, [1, 2, 3, 4, 5, 6, 7, 8])
2929
})
30+
it('curries', async () => {
31+
const numbers: number[] = []
32+
const mapNothing = flatMap(i => i)
33+
for await (const num of mapNothing([1, 2, [3, 4, 5, 6], 7, [8]])) {
34+
numbers.push(num as any)
35+
}
36+
assert.deepEqual(numbers, [1, 2, 3, 4, 5, 6, 7, 8])
37+
})
3038
})

lib/flat-map.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function flatMap<T, B>(func: (data: T) => FlatMapValue<B>): (iterable: An
88
export function flatMap<T, B>(func: (data: T) => FlatMapValue<B>, iterable: AnyIterable<T>): AsyncGenerator<B>
99
export function flatMap<T, B>(func: (data: T) => FlatMapValue<B>, iterable?: AnyIterable<T>) {
1010
if (iterable === undefined) {
11-
return (curriedIterable: AnyIterable<T>) => flatMap(func, curriedIterable)
11+
return curriedIterable => flatMap(func, curriedIterable)
1212
}
1313
return filter<B>(i => i !== undefined && i !== null, flatten(map<any, any>(func, iterable)))
1414
}

lib/from-stream-test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import { assert } from 'chai'
22
import { fromStream } from '.'
33
import { PassThrough } from 'stream'
44

5+
const once = func => {
6+
let called = false
7+
return (...args) => {
8+
if (called) {
9+
return
10+
}
11+
called = true
12+
return func(...args)
13+
}
14+
}
15+
516
describe('fromStream', () => {
617
it('takes a stream and returns an async iterable', async () => {
718
const stream = new PassThrough({ objectMode: true })
@@ -11,6 +22,17 @@ describe('fromStream', () => {
1122
assert.equal(value, 1)
1223
}
1324
})
25+
it('takes an old stream and returns an async iterable', async () => {
26+
const stream = new PassThrough({ objectMode: true })
27+
stream[Symbol.asyncIterator] = undefined as any
28+
stream.write(1)
29+
const itr = fromStream(stream)[Symbol.asyncIterator]()
30+
assert.deepEqual(await itr.next(), { value: 1, done: false })
31+
const next = itr.next()
32+
stream.end()
33+
assert.deepEqual(await next, { value: undefined, done: true })
34+
})
35+
1436
it('iterates empty streams', async () => {
1537
const stream = new PassThrough({ objectMode: true })
1638
stream.end()

lib/from-stream.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async function* _fromStream(stream: ReadableStreamish) {
2020
continue
2121
}
2222
if ((stream as any)._readableState.ended) {
23-
return
23+
break
2424
}
2525
await onceReadable(stream)
2626
}

lib/get-iterator-test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,9 @@ describe('getIterator', () => {
4646
value: 1,
4747
})
4848
})
49+
it("throws if it's not an iterator", () => {
50+
assert.throw(() => {
51+
getIterator(4 as any)
52+
})
53+
})
4954
})

lib/parallel-flat-map-test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ describe('parallelFlatMap', () => {
4141
}
4242
assert.deepEqual(values, ['1', '2', '3'])
4343
})
44+
it('lets you curry a function and then fill the contract', async () => {
45+
const values: any[] = []
46+
const doubleTime = parallelFlatMap(2)
47+
const stringParallelFlatMap = doubleTime(asyncStringArr, [1, 2, 3])
48+
for await (const val of stringParallelFlatMap) {
49+
values.push(val)
50+
}
51+
assert.deepEqual(values, ['1', '2', '3'])
52+
})
4453
it('runs concurrent mapping operations', async () => {
4554
let mapCount = 0
4655
const counter = () => mapCount++

lib/reduce-test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ describe('reduce', () => {
3131
const addZero = addAble(0)
3232
assert.equal(await addZero([1, 2, 3]), 6)
3333
})
34+
it('supports an undefined start after currying', async () => {
35+
const reduceAdd = reduce((num1?: number, num2?: number) => (num1 || 0) + (num2 || 0))
36+
const addZero = reduceAdd(undefined, [1, 2, 3])
37+
assert.equal(await addZero, 6)
38+
})
3439
})

lib/reduce.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function reduce<T, B>(func: (acc: B, value: T) => B, start: B, iterable:
1919
export function reduce<T, B>(func: (acc: B, value: T) => B, start?: B, iterable?: AnyIterable<T>) {
2020
if (start === undefined) {
2121
return (curriedStart: B, curriedIterable?: AnyIterable<T>) =>
22-
curriedIterable ? reduce(func, curriedStart, curriedIterable) : reduce(func, curriedStart)
22+
curriedIterable ? _reduce(func, curriedStart, curriedIterable) : reduce(func, curriedStart)
2323
}
2424
if (iterable === undefined) {
2525
return (curriedIterable: AnyIterable<T>) => reduce(func, start, curriedIterable)

lib/take.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ async function* _take<T>(count: number, iterable: AsyncIterable<T>) {
77
yield await val
88
taken++
99
if (taken >= count) {
10-
return
10+
break
1111
}
1212
}
1313
}
@@ -18,7 +18,7 @@ function* _syncTake<T>(count: number, iterable: Iterable<T>) {
1818
yield val
1919
taken++
2020
if (taken >= count) {
21-
return
21+
break
2222
}
2323
}
2424
}

lib/write-to-stream-test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ describe('writeToStream', () => {
1212
assert.equal(stream.read(), 2)
1313
assert.equal(stream.read(), 3)
1414
})
15+
it('curries', async () => {
16+
const values = [1, 2, 3]
17+
const stream = new PassThrough({ highWaterMark: 4, objectMode: true })
18+
const streamWrite = writeToStream(stream)
19+
await streamWrite(values)
20+
assert.equal(stream.read(), 1)
21+
assert.equal(stream.read(), 2)
22+
assert.equal(stream.read(), 3)
23+
})
1524
it('respects backpressure', async () => {
1625
let lastYield = 0
1726
function* values() {

lib/write-to-stream.ts

-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ export interface WritableStreamish {
77
removeListener: any
88
}
99

10-
function once(event: string, stream: WritableStreamish): Promise<any> {
11-
return new Promise(resolve => {
12-
stream.once(event, resolve)
13-
})
14-
}
15-
1610
async function _writeToStream(stream: WritableStreamish, iterable: AnyIterable<any>): Promise<void> {
1711
let lastError = null
1812
let errCb: NullOrFunction = null

0 commit comments

Comments
 (0)