Added istanbul rules to get 100% test coverage
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Michel Weststrate · committed by Michel Weststrate · parent 617772f · Browse files · 6 files·+23 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+23 added−12 removed
- other:+23 added−12 removed
Provenance
- Commit
f4a4701- Tree
9daf857- Author
Michel Weststrate <mweststrate@fb.com>- Committer
Michel Weststrate <mweststrate@fb.com>- Parent
617772f
6 files changed+23 added−12 removed
modified:src/common.ts+4 added-2 removed
86 unmodified lines87 ? obj =>88 Object.getOwnPropertyNames(obj).concat(89 Object.getOwnPropertySymbols(obj) as any90 )91- : Object.getOwnPropertyNames91+ : /* istanbul ignore next */ Object.getOwnPropertyNames92 93 export function each<T extends Objectish>(94 obj: T,95 iter: (key: string | number, value: any, source: T) => void11 unmodified lines107 return desc && desc.enumerable ? true : false108 }109 110 export function getArchtype(thing: any): Archtype {111+ /* istanbul ignore next */112 if (!thing) die()113 if (thing[DRAFT_STATE]) {114 switch ((thing as Drafted)[DRAFT_STATE].type) {115 case ProxyType.ES5Object:94 unmodified lines210 })211 return clone212 }213 213-export function freeze(obj: any, deep: boolean = false): void {214+export function freeze(obj: any, deep: boolean): void {215 if (!isDraftable(obj) || isDraft(obj) || Object.isFrozen(obj)) return216 const type = getArchtype(obj)217 if (type === Archtype.Set) {218 obj.add = obj.clear = obj.delete = dontMutateFrozenCollections as any19 unmodified lines238 writable: true239 })240 }241 242+/* istanbul ignore next */243 export function die(): never {244 throw new Error("Illegal state, please file a bug")245 }modified:src/finalize.ts+3 added-3 removed
76 unmodified lines77 state.finalized = true78 finalizeTree(immer, state.draft, scope, path)79 80 // We cannot really delete anything inside of a Set. We can only replace the whole Set.81- if (immer.onDelete && !isSet(state.base)) {81+ if (immer.onDelete && state.type !== ProxyType.Set) {82 // The `assigned` object is unreliable with ES5 drafts.83 if (immer.useProxies) {84 const {assigned} = state85 each(assigned, (prop, exists) => {86- if (!exists) immer.onDelete?.(state, prop as any)86+ if (!exists) immer.onDelete!(state, prop as any)87 })88 } else {89 const {base, copy} = state90 each(base, prop => {91- if (!has(copy, prop)) immer.onDelete?.(state, prop as any)91+ if (!has(copy, prop)) immer.onDelete!(state, prop as any)92 })93 }94 }95 if (immer.onCopy) {108 unmodified linesmodified:src/immer.ts+7 added-4 removed
7 unmodified lines8 isSet,9 isMap,10 isDraftable,11 DRAFT_STATE,12- NOTHING12+ NOTHING,13+ die14 } from "./common"15 import {ImmerScope} from "./scope"16 import {17 ImmerState,8 unmodified lines26 import {proxyMap} from "./map"27 import {proxySet} from "./set"28 import {processResult, maybeFreeze} from "./finalize"29 30+/* istanbul ignore next */31 function verifyMinified() {}32 33 const configDefaults = {34 useProxies:2 unmodified lines37 typeof Reflect !== "undefined",38 autoFreeze:39 typeof process !== "undefined"40 ? process.env.NODE_ENV !== "production"41+ : /* istanbul ignore next */39- : verifyMinified.name === "verifyMinified",42+ verifyMinified.name === "verifyMinified",43 onAssign: null,44 onDelete: null,45 onCopy: null46 } as const118 unmodified lines165 return (state: any, ...args: any[]) =>166 this.produceWithPatches(state, (draft: any) => arg1(draft, ...args))167 }168 // non-curried form166- if (arg3)167- throw new Error("A patch listener cannot be passed to produceWithPatches")169+ /* istanbul ignore next */170+ if (arg3) die()171 let patches: Patch[], inversePatches: Patch[]172 const nextState = this.produce(arg1, arg2, (p: Patch[], ip: Patch[]) => {173 patches = p174 inversePatches = ip102 unmodified linesmodified:src/map.ts+3 added
12 unmodified lines13141516171819202195 unmodified lines1171181191201211221231241258 unmodified lines13413513613713813914014114221 unmodified lines12 unmodified lines draft: Drafted<AnyMap, MapState>}
// Make sure DraftMap declarion doesn't die if Map is not avialable.../* istanbul ignore next */const MapBase: MapConstructor = typeof Map !== "undefined" ? Map : (function FakeMap() {} as any)
export class DraftMap<K, V> extends MapBase implements Map<K, V> {95 unmodified lines return { [iteratorSymbol]: () => this.values(), next: () => { const r = iterator.next() /* istanbul ignore next */ if (r.done) return r const value = this.get(r.value) return { done: false,8 unmodified lines return { [iteratorSymbol]: () => this.entries(), next: () => { const r = iterator.next() /* istanbul ignore next */ if (r.done) return r const value = this.get(r.value) return { done: false,21 unmodified linesmodified:src/patches.ts+4 added-2 removed
41 unmodified lines42 patches: Patch[],43 inversePatches: Patch[]44 ) {45 let {base, assigned, copy} = state46+ /* istanbul ignore next */47 if (!copy) die()48 49 // Reduce complexity by ensuring `base` is never longer.49- if (copy!.length < base.length) {50+ if (copy.length < base.length) {51 // @ts-ignore52 ;[base, copy] = [copy, base]53 ;[patches, inversePatches] = [inversePatches, patches]54 }118 unmodified lines173 export function applyPatches<T>(draft: T, patches: Patch[]): T {174 patches.forEach(patch => {175 const {path, op} = patch176 177+ /* istanbul ignore next */178 if (!path.length) die()179 180 let base: any = draft181 for (let i = 0; i < path.length - 1; i++) {9 unmodified lines191 case "replace":192 switch (type) {193 case Archtype.Map:194 return base.set(key, value)195+ /* istanbul ignore next */196 case Archtype.Set:197 throw new Error('Sets cannot have "replace" patches.')198 default:199 // if value is an object, then it's assigned by reference1 unmodified line201 // so we use value from the cloned patch202 // @ts-ignore203 return (base[key] = value)204 }202- break205 case "add":206 switch (type) {207 case Archtype.Array:208 return base.splice(key as any, 0, value)42 unmodified linesmodified:src/set.ts+2 added-1 removed
12 unmodified lines13 draft: Drafted<AnySet, SetState>14 }15 16 // Make sure DraftSet declarion doesn't die if Map is not avialable...17+/* istanbul ignore next */18 const SetBase: SetConstructor =19 typeof Set !== "undefined" ? Set : (function FakeSet() {} as any)20 21 export class DraftSet<K, V> extends SetBase implements Set<V> {57 unmodified lines79 return (80 state.copy!.delete(value) ||81 (state.drafts.has(value)82 ? state.copy!.delete(state.drafts.get(value))82- : false)83+ : /* istanbul ignore next */ false)84 )85 }86 87 clear() {58 unmodified lines