Skip to content

Commit

Permalink
use c8 instead of istanbul/nyc
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Feb 22, 2023
1 parent 8af099f commit b68b0f0
Show file tree
Hide file tree
Showing 41 changed files with 934 additions and 287 deletions.
32 changes: 20 additions & 12 deletions array.test.js
@@ -1,28 +1,36 @@

import * as array from './array.js'
import * as t from './testing.js'

/**
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testAppend = tc => {
export const testAppend = _tc => {
const arr = [1, 2, 3]
array.appendTo(arr, arr.slice())
array.appendTo(arr, array.copy(arr))
t.compareArrays(arr, [1, 2, 3, 1, 2, 3])
}

/**
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testBasic = _tc => {
const arr = array.create()
array.appendTo(arr, array.from([1]))
t.assert(array.last(arr) === 1)
}

/**
* @param {t.TestCase} _tc
*/
export const testflatten = tc => {
export const testflatten = _tc => {
const arr = [[1, 2, 3], [4]]
t.compareArrays(array.flatten(arr), [1, 2, 3, 4])
}

/**
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testEvery = tc => {
export const testEvery = _tc => {
const arr = [1, 2, 3]
t.assert(array.every(arr, x => x <= 3))
t.assert(!array.every(arr, x => x < 3))
Expand All @@ -31,9 +39,9 @@ export const testEvery = tc => {
}

/**
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testIsArray = tc => {
export const testIsArray = _tc => {
t.assert(array.isArray([]))
t.assert(array.isArray([1]))
t.assert(array.isArray(Array.from(new Set([3]))))
Expand All @@ -43,9 +51,9 @@ export const testIsArray = tc => {
}

/**
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testUnique = tc => {
export const testUnique = _tc => {
t.compare([1, 2], array.unique([1, 2, 1, 2, 2, 1]))
t.compare([], array.unique([]))
t.compare([{ el: 1 }], array.uniqueBy([{ el: 1 }, { el: 1 }], o => o.el))
Expand Down
8 changes: 4 additions & 4 deletions broadcastchannel.js
Expand Up @@ -33,7 +33,7 @@ import * as storage from './storage.js'
*/
const channels = new Map()

/* istanbul ignore next */
/* c8 ignore start */
class LocalStoragePolyfill {
/**
* @param {string} room
Expand All @@ -54,9 +54,10 @@ class LocalStoragePolyfill {
storage.varStorage.setItem(this.room, buffer.toBase64(buffer.createUint8ArrayFromArrayBuffer(buf)))
}
}
/* c8 ignore stop */

/* istanbul ignore next */
// Use BroadcastChannel or Polyfill
/* c8 ignore next */
const BC = typeof BroadcastChannel === 'undefined' ? LocalStoragePolyfill : BroadcastChannel

/**
Expand All @@ -67,7 +68,6 @@ const getChannel = room =>
map.setIfUndefined(channels, room, () => {
const subs = set.create()
const bc = new BC(room)
/* istanbul ignore next */
/**
* @param {{data:ArrayBuffer}} e
*/
Expand Down Expand Up @@ -99,7 +99,7 @@ export const subscribe = (room, f) => {
export const unsubscribe = (room, f) => {
const channel = getChannel(room)
const unsubscribed = channel.subs.delete(f)
/* istanbul ignore else */
/* c8 ignore else */
if (unsubscribed && channel.subs.size === 0) {
channel.bc.close()
channels.delete(room)
Expand Down
10 changes: 6 additions & 4 deletions buffer.js
Expand Up @@ -30,7 +30,7 @@ export const createUint8ArrayViewFromArrayBuffer = (buffer, byteOffset, length)
*/
export const createUint8ArrayFromArrayBuffer = buffer => new Uint8Array(buffer)

/* istanbul ignore next */
/* c8 ignore start */
/**
* @param {Uint8Array} bytes
* @return {string}
Expand All @@ -43,14 +43,15 @@ const toBase64Browser = bytes => {
// eslint-disable-next-line no-undef
return btoa(s)
}
/* c8 ignore stop */

/**
* @param {Uint8Array} bytes
* @return {string}
*/
const toBase64Node = bytes => Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64')

/* istanbul ignore next */
/* c8 ignore start */
/**
* @param {string} s
* @return {Uint8Array}
Expand All @@ -64,6 +65,7 @@ const fromBase64Browser = s => {
}
return bytes
}
/* c8 ignore stop */

/**
* @param {string} s
Expand All @@ -73,10 +75,10 @@ const fromBase64Node = s => {
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength)
}

/* istanbul ignore next */
/* c8 ignore next */
export const toBase64 = env.isBrowser ? toBase64Browser : toBase64Node

/* istanbul ignore next */
/* c8 ignore next */
export const fromBase64 = env.isBrowser ? fromBase64Browser : fromBase64Node

/**
Expand Down
2 changes: 1 addition & 1 deletion conditions.js
Expand Up @@ -9,5 +9,5 @@
* @param {T|null|undefined} v
* @return {T|null}
*/
/* istanbul ignore next */
/* c8 ignore next */
export const undefinedToNull = v => v === undefined ? null : v
11 changes: 6 additions & 5 deletions crypto.js
Expand Up @@ -5,11 +5,11 @@ import * as decoding from './decoding.js'
import * as string from './string.js'
import * as webcrypto from 'lib0/webcrypto'

/* istanbul ignore next */
/**
* @param {string | Uint8Array} data
* @return {Uint8Array}
*/
/* c8 ignore next */
const toBinary = data => typeof data === 'string' ? string.encodeUtf8(data) : data

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ export const deriveSymmetricKey = (secret, salt, { extractable = false, usages =
)
}

/* istanbul ignore next */
/* c8 ignore next */
/**
* @param {Object} opts
* @param {boolean} [opts.extractable]
Expand All @@ -68,13 +68,13 @@ export const generateAsymmetricKey = ({ extractable = false, usages = ['sign', '
usages
)

/* istanbul ignore next */
/* c8 ignore next */
/**
* @param {CryptoKey} key - Symmetric or Asymmetric key
*/
export const exportKey = key => webcrypto.subtle.exportKey('jwk', key)

/* istanbul ignore next */
/* c8 ignore start */
/**
* @param {any} jwk
* @param {Object} opts
Expand All @@ -83,8 +83,9 @@ export const exportKey = key => webcrypto.subtle.exportKey('jwk', key)
*/
export const importSymmetricKey = (jwk, { extractable = false, usages = ['encrypt', 'decrypt'] } = {}) =>
webcrypto.subtle.importKey('jwk', jwk, 'PBKDF2', extractable, usages)
/* c8 ignore stop */

/* istanbul ignore next */
/* c8 ignore next */
/**
* @param {any} jwk
* @param {Object} opts
Expand Down
11 changes: 7 additions & 4 deletions decoding.js
Expand Up @@ -250,10 +250,11 @@ export const readVarUint = decoder => {
if (r < binary.BIT8) {
return num
}
/* istanbul ignore if */
/* c8 ignore start */
if (num > number.MAX_SAFE_INTEGER) {
throw errorIntegerOutOfRange
}
/* c8 ignore stop */
}
throw errorUnexpectedEndOfArray
}
Expand Down Expand Up @@ -287,10 +288,11 @@ export const readVarInt = decoder => {
if (r < binary.BIT8) {
return sign * num
}
/* istanbul ignore if */
/* c8 ignore start */
if (num > number.MAX_SAFE_INTEGER) {
throw errorIntegerOutOfRange
}
/* c8 ignore stop */
}
throw errorUnexpectedEndOfArray
}
Expand Down Expand Up @@ -336,7 +338,7 @@ export const peekVarInt = decoder => {
* @param {Decoder} decoder
* @return {String} The read String.
*/
/* istanbul ignore next */
/* c8 ignore start */
export const _readVarStringPolyfill = decoder => {
let remainingLen = readVarUint(decoder)
if (remainingLen === 0) {
Expand All @@ -361,6 +363,7 @@ export const _readVarStringPolyfill = decoder => {
return decodeURIComponent(escape(encodedString))
}
}
/* c8 ignore stop */

/**
* @function
Expand All @@ -379,7 +382,7 @@ export const _readVarStringNative = decoder =>
* @return {String} The read String
*
*/
/* istanbul ignore next */
/* c8 ignore next */
export const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill

/**
Expand Down

0 comments on commit b68b0f0

Please sign in to comment.