Skip to content
Myr

regressions.js

This file

Path

__tests__/regressions.js

316 lines · 7.6 KiB · JavaScript

Last changed by

chore(test): cover circular symbol references in produce (#1309)Bennett Payoyobefore adoption918b1e3

History of this file

Take it

The walk stopped after 200 commits: lines older than 07f5cc9 point at it.

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 1–7why, one step back
1"use strict"
2import {3 Immer,4 nothing,5 original,6 isDraft,7 immerable,

fix: undefined assigned to a prototype-inherited key gets dropped (#1262)Alexander Kireyevbefore adoption16e225b

lines 8–9why, one step back
8 enableMapSet,
9 enablePatches

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 10–11why, one step back
10} from "../src/immer"
11

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 12why, one step back
12enableMapSet()

fix: undefined assigned to a prototype-inherited key gets dropped (#1262)Alexander Kireyevbefore adoption16e225b

line 13why, one step back
13enablePatches()

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 14why, one step back
14

chore(test): cover circular symbol references in produce (#1309)Bennett Payoyobefore adoption918b1e3

lines 15–27why, one step back
15test("#1106 handles circular references in symbol properties", () => {
16 const symbol = Symbol("parent")17 const parent = {value: 0}18 const child = {[symbol]: parent}19 parent.child = child2021 const next = new Immer().produce(parent, draft => {22 draft.value = 123 })2425 expect(next.value).toBe(1)26})27

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 28–33why, one step back
28runBaseTest("proxy (no freeze)", true, false)
29runBaseTest("proxy (autofreeze)", true, true)30runBaseTest("es5 (no freeze)", false, false)31runBaseTest("es5 (autofreeze)", false, true)3233function runBaseTest(name, useProxies, autoFreeze, useListener) {

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

line 34why, one step back
34 const listener = useListener ? function () {} : undefined

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 35–45why, one step back
35 const {produce, produceWithPatches} = createPatchedImmer({
36 useProxies,37 autoFreeze38 })3940 // When `useListener` is true, append a function to the arguments of every41 // uncurried `produce` call in every test. This makes tests easier to read.42 function createPatchedImmer(options) {43 const immer = new Immer(options)4445 const {produce} = immer

chore: Merge branch 'unional-prettier'Michel Weststratebefore adoption37eaf8f

line 46why, one step back
46 immer.produce = function (...args) {

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 47–267why, one step back
47 return typeof args[1] === "function" && args.length < 3
48 ? produce(...args, listener)49 : produce(...args)50 }5152 return immer53 }5455 describe(`regressions ${name}`, () => {56 test("#604 freeze inside class", () => {57 class Thing {58 [immerable] = true5960 constructor({x}) {61 this._data = {x}62 }6364 get x() {65 return this._data.x66 }6768 set x(x) {69 this._data.x = x70 }71 }7273 let i = 174 let item = new Thing({x: i})75 let item0 = item7677 const bump = () => {78 item = produce(item, draft => {79 // uncomment this to make things work80 //draft._data81 draft.x = ++i82 })83 }8485 bump()86 bump()8788 expect(i).toBe(3)89 expect(item._data).toEqual({90 x: 391 })92 expect(item0._data).toEqual({93 x: 194 })95 })9697 test("#646 setting undefined field to undefined should not create new result", () => {98 const foo = {99 bar: undefined100 }101 const foo2 = produce(foo, draft => {102 draft.bar = undefined103 })104 expect(foo2).toBe(foo)105 })106107 test("#646 - 2 setting undefined field to undefined should not create new result", () => {108 const foo = {}109 const foo2 = produce(foo, draft => {110 draft.bar = undefined111 })112 expect(foo2).not.toBe(foo)113 expect(foo).toEqual({})114 expect(foo2).toEqual({bar: undefined})115 })116117 test("#638 - out of range assignments", () => {118 const state = []119120 const state1 = produce(state, draft => {121 draft[2] = "v2"122 })123124 expect(state1.length).toBe(3)125 expect(state1).toEqual([undefined, undefined, "v2"])126127 const state2 = produce(state1, draft => {128 draft[1] = "v1"129 })130131 expect(state2.length).toBe(3)132 expect(state2).toEqual([undefined, "v1", "v2"])133 })134135 test("#628 set removal hangs", () => {136 let arr = []137 let set = new Set([arr])138139 let result = produce(set, draft1 => {140 produce(draft1, draft2 => {141 draft2.delete(arr)142 })143 })144 expect(result).toEqual(new Set([[]])) // N.B. this outcome doesn't seem not correct, but then again,145 // double produce without return looks iffy as well, so not sure what the expected outcome in the146 // original report was147 })148149 test("#628 - 2 set removal hangs", () => {150 let arr = []151 let set = new Set([arr])152153 let result = produce(set, draft2 => {154 draft2.delete(arr)155 })156 expect(result).toEqual(new Set())157 })158159 test("#650 - changes with overridden arr.slice() fail", () => {160 const data = {161 foo: [162 {163 isActive: false164 }165 ]166 }167 // That's roughly what seamless-immutable does168 data.foo.slice = (...args) =>169 Object.freeze(Array.prototype.slice.call(data.foo, ...args))170171 const newData = produce(data, draft => {172 draft.foo[0].isActive = true173 })174 expect(newData.foo[0].isActive).toBe(true)175 })176177 test("#659 no reconciliation after read", () => {178 const bar = {}179 const foo = {bar}180181 const next = produce(foo, draft => {182 draft.bar183 draft.bar = bar184 })185 expect(next).toBe(foo)186 })187188 test("#659 no reconciliation after read - 2", () => {189 const bar = {}190 const foo = {bar}191192 const next = produce(foo, draft => {193 const subDraft = draft.bar194 draft.bar = bar195 subDraft.x = 3 // this subDraft is not part of the end result, so ignore196 })197198 expect(next).toEqual(foo)199 })200201 test("#659 no reconciliation after read - 3", () => {202 const bar = {}203 const foo = {bar}204205 const next = produce(foo, draft => {206 const subDraft = draft.bar207 subDraft.x = 3 // this subDraft is not part of the end result, so ignore208 draft.bar = bar209 })210 expect(next).toEqual(foo)211 })212213 // Disabled: these are optimizations that would be nice if they214 // could be detected, but don't change the correctness of the result215 test.skip("#659 no reconciliation after read - 4", () => {216 const bar = {}217 const foo = {bar}218219 const next = produce(foo, draft => {220 const subDraft = draft.bar221 draft.bar = bar222 subDraft.x = 3 // this subDraft is not part of the end result, so ignore223 })224225 expect(next).toBe(foo)226 })227228 // Disabled: these are optimizations that would be nice if they229 // could be detected, but don't change the correctness of the result230 test.skip("#659 no reconciliation after read - 5", () => {231 const bar = {}232 const foo = {bar}233234 const next = produce(foo, draft => {235 const subDraft = draft.bar236 subDraft.x = 3 // this subDraft is not part of the end result, so ignore237 draft.bar = bar238 })239 expect(next).toBe(foo)240 })241242 test("#659 no reconciliation after read - 6", () => {243 const bar = {}244 const foo = {bar}245246 const next = produce(foo, draft => {247 const subDraft = draft.bar248 subDraft.x = 3 // this subDraft is not part of the end result, so ignore249 draft.bar = bar250 draft.bar = subDraft251 })252 expect(next).not.toBe(foo)253 expect(next).toEqual({254 bar: {x: 3}255 })256 })257258 test("#807 new undefined member not stored", () => {259 const state = {}260 const newState = produce(state, draft => {261 draft.baz = undefined262 })263 expect(state).not.toBe(newState)264 expect(Object.hasOwnProperty.call(newState, "baz")).toBe(true)265 expect(newState).toEqual({266 baz: undefined267 })

fix: undefined assigned to a prototype-inherited key gets dropped (#1262)Alexander Kireyevbefore adoption16e225b

lines 268–287why, one step back
268 })
269270 test("#1160 assigning undefined to a key only present on the prototype is still stored as an own property", () => {271 const proto = {[immerable]: true, name: undefined}272 const state = Object.create(proto)273274 expect(Object.hasOwnProperty.call(state, "name")).toBe(false)275276 const [newState, patches] = produceWithPatches(state, draft => {277 draft.name = undefined278 })279280 expect(Object.hasOwnProperty.call(newState, "name")).toBe(true)281 expect(patches).toEqual([282 {283 op: "add",284 path: ["name"],285 value: undefined286 }287 ])

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

line 288why, one step back
288 })

chore: Add failing test for nested and chained produce calls (#935)James Allenbefore adoption04c5fb3

line 289why, one step back
289

Merge pull request #1028 from immerjs/immer-10Michel Weststratebefore adoption2ef9a42

line 290why, one step back
290 test("Nested and chained produce calls throw 'Cannot perform 'get' on a proxy that has been revoked' error", () => {

chore: Add failing test for nested and chained produce calls (#935)James Allenbefore adoption04c5fb3

lines 291–304why, one step back
291 const state = {
292 foo: {293 bar: {294 baz: "banana"295 }296 }297 }298 const newState = produce(state, draft => {299 draft.foo = produce(draft.foo, fooDraft => {300 fooDraft.baz = fooDraft.bar.baz.replace("banana", "apple")301 })302 draft.foo = produce(draft.foo, fooDraft => {303 /* another produce call makes this fail */304 /* no actual mutation necessary to make this happen */

fix: produce results should never be frozen when returned from nested produces, to prevent 'hiding' drafts. Fixes #935Michel Weststratebefore adoptiona810960

lines 305–308why, one step back
305 // This happened before becouse the outer object is not modified,
306 // so assumed to be safely freezable by Immer, while it actually still307 // contains a draft of bar, which wasn't retracted since we don't do that in nested308 // producers, as it can still be modified outside a produce

chore: Add failing test for nested and chained produce calls (#935)James Allenbefore adoption04c5fb3

lines 309–310why, one step back
309 })
310 })

fix: produce results should never be frozen when returned from nested produces, to prevent 'hiding' drafts. Fixes #935Michel Weststratebefore adoptiona810960

lines 311–313why, one step back
311 expect(newState).toEqual({
312 foo: {baz: "apple", bar: {baz: "banana"}}313 })

chore: Add failing test for nested and chained produce calls (#935)James Allenbefore adoption04c5fb3

line 314why, one step back
314 })

chore(test): fix production build unit testsMichel Weststratebefore adoption07f5cc9

lines 315–316why, one step back
315 })
316}