Skip to content

Commit 6c62eec

Browse files
committedNov 17, 2020
chore: Merge branch 'master' of github.com:immerjs/immer
2 parents 0730231 + 31684f2 commit 6c62eec

12 files changed

+144
-128
lines changed
 

‎.travis.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
node_js:
3-
- "10.18.1"
4-
# - "node"
3+
# - "10.18.1"
4+
- "node"
55
env:
66
- NODE_ENV=TEST
77
cache:
@@ -12,12 +12,13 @@ before_script:
1212
- yarn global add if-node-version
1313
script:
1414
- yarn build || travis_terminate 1
15-
- if-node-version 10 || { yarn test && travis_terminate 0; }
16-
- yarn coveralls
15+
- yarn test || travis_terminate 1
16+
- yarn coveralls || travis_terminate 0
1717
jobs:
1818
include:
1919
- stage: deploy
2020
if: branch == master && !fork
2121
script:
22+
- yarn test || travis_terminate 1
2223
- NODE_ENV= yarn build || travis_terminate 1
2324
- yarn semantic-release

‎__tests__/__prod_snapshots__/base.js.snap

+32-48
Large diffs are not rendered by default.
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`applyPatches throws when \`op\` is not "add", "replace", nor "remove" 1`] = `"[Immer] minified error nr: 17 copy. Find the full error at: https://bit.ly/3cXEKWf"`;
3+
exports[`applyPatches throws when \`op\` is not "add", "replace", nor "remove" 1`] = `"[Immer] minified error nr: 17 'copy'. Find the full error at: https://bit.ly/3cXEKWf"`;
44

5-
exports[`applyPatches throws when \`path\` cannot be resolved 1`] = `"[Immer] minified error nr: 15 a/b. Find the full error at: https://bit.ly/3cXEKWf"`;
5+
exports[`applyPatches throws when \`path\` cannot be resolved 1`] = `"[Immer] minified error nr: 15 'a/b'. Find the full error at: https://bit.ly/3cXEKWf"`;
66

7-
exports[`applyPatches throws when \`path\` cannot be resolved 2`] = `"[Immer] minified error nr: 15 a/b/c. Find the full error at: https://bit.ly/3cXEKWf"`;
7+
exports[`applyPatches throws when \`path\` cannot be resolved 2`] = `"[Immer] minified error nr: 15 'a/b/c'. Find the full error at: https://bit.ly/3cXEKWf"`;
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`ES5 plugins should throw if no proxies are available error when using ES5 1`] = `"[Immer] minified error nr: 19 ES5. Find the full error at: https://bit.ly/3cXEKWf"`;
3+
exports[`ES5 plugins should throw if no proxies are available error when using ES5 1`] = `"[Immer] minified error nr: 18 'ES5'. Find the full error at: https://bit.ly/3cXEKWf"`;
44

5-
exports[`error when using Maps 1`] = `"[Immer] minified error nr: 19 MapSet. Find the full error at: https://bit.ly/3cXEKWf"`;
5+
exports[`error when using Maps 1`] = `"[Immer] minified error nr: 18 'MapSet'. Find the full error at: https://bit.ly/3cXEKWf"`;
66

7-
exports[`error when using patches - 1 1`] = `"[Immer] minified error nr: 19 Patches. Find the full error at: https://bit.ly/3cXEKWf"`;
7+
exports[`error when using patches - 1 1`] = `"[Immer] minified error nr: 18 'Patches'. Find the full error at: https://bit.ly/3cXEKWf"`;
88

9-
exports[`error when using patches - 2 1`] = `"[Immer] minified error nr: 19 Patches. Find the full error at: https://bit.ly/3cXEKWf"`;
9+
exports[`error when using patches - 2 1`] = `"[Immer] minified error nr: 18 'Patches'. Find the full error at: https://bit.ly/3cXEKWf"`;
1010

11-
exports[`error when using patches - 3 1`] = `"[Immer] minified error nr: 19 Patches. Find the full error at: https://bit.ly/3cXEKWf"`;
11+
exports[`error when using patches - 3 1`] = `"[Immer] minified error nr: 18 'Patches'. Find the full error at: https://bit.ly/3cXEKWf"`;

‎__tests__/base.js

+56-51
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ jest.setTimeout(1000)
1616

1717
enableAllPlugins()
1818

19+
const isProd = process.env.NODE_ENV === "production"
20+
1921
test("immer should have no dependencies", () => {
2022
expect(require("../package.json").dependencies).toBeUndefined()
2123
})
@@ -1145,65 +1147,66 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
11451147
})
11461148

11471149
// NOTE: ES5 drafts only protect existing properties when revoked.
1148-
it("revokes the draft once produce returns", () => {
1149-
const expectRevoked = (fn, shouldThrow = true) => {
1150-
if (shouldThrow) expect(fn).toThrowErrorMatchingSnapshot()
1151-
else expect(fn).not.toThrow()
1152-
}
1150+
if (!isProd)
1151+
it("revokes the draft once produce returns", () => {
1152+
const expectRevoked = (fn, shouldThrow = true) => {
1153+
if (shouldThrow) expect(fn).toThrowErrorMatchingSnapshot()
1154+
else expect(fn).not.toThrow()
1155+
}
11531156

1154-
// Test object drafts:
1155-
let draft
1156-
produce({a: 1, b: 1}, s => {
1157-
draft = s
1158-
delete s.b
1159-
})
1157+
// Test object drafts:
1158+
let draft
1159+
produce({a: 1, b: 1}, s => {
1160+
draft = s
1161+
delete s.b
1162+
})
11601163

1161-
// Access known property on object draft.
1162-
expectRevoked(() => {
1163-
draft.a
1164-
})
1164+
// Access known property on object draft.
1165+
expectRevoked(() => {
1166+
draft.a
1167+
})
11651168

1166-
// Assign known property on object draft.
1167-
expectRevoked(() => {
1168-
draft.a = true
1169-
})
1169+
// Assign known property on object draft.
1170+
expectRevoked(() => {
1171+
draft.a = true
1172+
})
11701173

1171-
// Access unknown property on object draft.
1172-
expectRevoked(() => {
1173-
draft.z
1174-
}, useProxies)
1174+
// Access unknown property on object draft.
1175+
expectRevoked(() => {
1176+
draft.z
1177+
}, useProxies)
11751178

1176-
// Assign unknown property on object draft.
1177-
expectRevoked(() => {
1178-
draft.z = true
1179-
}, useProxies)
1179+
// Assign unknown property on object draft.
1180+
expectRevoked(() => {
1181+
draft.z = true
1182+
}, useProxies)
11801183

1181-
// Test array drafts:
1182-
produce([1, 2], s => {
1183-
draft = s
1184-
s.pop()
1185-
})
1184+
// Test array drafts:
1185+
produce([1, 2], s => {
1186+
draft = s
1187+
s.pop()
1188+
})
11861189

1187-
// Access known index of an array draft.
1188-
expectRevoked(() => {
1189-
draft[0]
1190-
})
1190+
// Access known index of an array draft.
1191+
expectRevoked(() => {
1192+
draft[0]
1193+
})
11911194

1192-
// Assign known index of an array draft.
1193-
expectRevoked(() => {
1194-
draft[0] = true
1195-
})
1195+
// Assign known index of an array draft.
1196+
expectRevoked(() => {
1197+
draft[0] = true
1198+
})
11961199

1197-
// Access unknown index of an array draft.
1198-
expectRevoked(() => {
1199-
draft[1]
1200-
}, useProxies)
1200+
// Access unknown index of an array draft.
1201+
expectRevoked(() => {
1202+
draft[1]
1203+
}, useProxies)
12011204

1202-
// Assign unknown index of an array draft.
1203-
expectRevoked(() => {
1204-
draft[1] = true
1205-
}, useProxies)
1206-
})
1205+
// Assign unknown index of an array draft.
1206+
expectRevoked(() => {
1207+
draft[1] = true
1208+
}, useProxies)
1209+
})
12071210

12081211
it("can access a child draft that was created before the draft was modified", () => {
12091212
produce({a: {}}, s => {
@@ -1697,7 +1700,7 @@ function runBaseTest(name, useProxies, autoFreeze, useListener) {
16971700
},
16981701
e => {
16991702
expect(e).toBe(err)
1700-
expect(() => draft.a).toThrowErrorMatchingSnapshot()
1703+
if (!isProd) expect(() => draft.a).toThrowErrorMatchingSnapshot()
17011704
}
17021705
)
17031706
})
@@ -2418,7 +2421,9 @@ function testLiteralTypes(produce) {
24182421
draft.foo = true
24192422
})
24202423
).toThrowError(
2421-
"produce can only be called on things that are draftable"
2424+
isProd
2425+
? "[Immer] minified error nr: 21"
2426+
: "produce can only be called on things that are draftable"
24222427
)
24232428
})
24242429
} else {

‎__tests__/current.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ enableAllPlugins()
1414
runTests("proxy", true)
1515
runTests("es5", false)
1616

17+
const isProd = process.env.NODE_ENV === "production"
18+
1719
function runTests(name, useProxies) {
1820
describe("current - " + name, () => {
1921
beforeAll(() => {
@@ -24,7 +26,11 @@ function runTests(name, useProxies) {
2426
it("must be called on draft", () => {
2527
expect(() => {
2628
current({})
27-
}).toThrowError("[Immer] 'current' expects a draft, got: [object Object]")
29+
}).toThrowError(
30+
isProd
31+
? "[Immer] minified error nr: 22 '[object Object]'. Find the full error at: https://bit.ly/3cXEKWf"
32+
: "[Immer] 'current' expects a draft, got: [object Object]"
33+
)
2834
})
2935

3036
it("can handle simple arrays", () => {

‎__tests__/manual.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010

1111
enableAllPlugins()
1212

13+
const isProd = process.env.NODE_ENV === "production"
14+
1315
runTests("proxy", true)
1416
runTests("es5", false)
1517

@@ -41,16 +43,17 @@ function runTests(name, useProxies) {
4143
expect(state).toEqual([{}, {}, {}])
4244
})
4345

44-
it("cannot modify after finish", () => {
45-
const state = {a: 1}
46+
if (!isProd)
47+
it("cannot modify after finish", () => {
48+
const state = {a: 1}
4649

47-
const draft = createDraft(state)
48-
draft.a = 2
49-
expect(finishDraft(draft)).toEqual({a: 2})
50-
expect(() => {
51-
draft.a = 3
52-
}).toThrowErrorMatchingSnapshot()
53-
})
50+
const draft = createDraft(state)
51+
draft.a = 2
52+
expect(finishDraft(draft)).toEqual({a: 2})
53+
expect(() => {
54+
draft.a = 3
55+
}).toThrowErrorMatchingSnapshot()
56+
})
5457

5558
it("should support patches drafts", () => {
5659
const state = {a: 1}

‎__tests__/original.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import produce, {original, setUseProxies, enableAllPlugins} from "../src/immer"
33

44
enableAllPlugins()
55

6+
const isProd = process.env.NODE_ENV === "production"
7+
68
describe("original", () => {
79
const baseState = {
810
a: [],
@@ -40,20 +42,28 @@ describe("original", () => {
4042
draftState.c = {}
4143
draftState.d = 3
4244
expect(() => original(draftState.c)).toThrowErrorMatchingInlineSnapshot(
43-
`"[Immer] 'original' expects a draft, got: [object Object]"`
45+
isProd
46+
? `"[Immer] minified error nr: 23 '[object Object]'. Find the full error at: https://bit.ly/3cXEKWf"`
47+
: `"[Immer] 'original' expects a draft, got: [object Object]"`
4448
)
4549
expect(() => original(draftState.d)).toThrowErrorMatchingInlineSnapshot(
46-
`"[Immer] 'original' expects a draft, got: 3"`
50+
isProd
51+
? `"[Immer] minified error nr: 23 '3'. Find the full error at: https://bit.ly/3cXEKWf"`
52+
: `"[Immer] 'original' expects a draft, got: 3"`
4753
)
4854
})
4955
})
5056

5157
it("should return undefined for an object that is not proxied", () => {
5258
expect(() => original({})).toThrowErrorMatchingInlineSnapshot(
53-
`"[Immer] 'original' expects a draft, got: [object Object]"`
59+
isProd
60+
? `"[Immer] minified error nr: 23 '[object Object]'. Find the full error at: https://bit.ly/3cXEKWf"`
61+
: `"[Immer] 'original' expects a draft, got: [object Object]"`
5462
)
5563
expect(() => original(3)).toThrowErrorMatchingInlineSnapshot(
56-
`"[Immer] 'original' expects a draft, got: 3"`
64+
isProd
65+
? `"[Immer] minified error nr: 23 '3'. Find the full error at: https://bit.ly/3cXEKWf"`
66+
: `"[Immer] 'original' expects a draft, got: 3"`
5767
)
5868
})
5969
})

‎ignoreObseleteSnapshots.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(results) {
2+
// don't count obselete snapshot as a failure, but just check if there are no failing tests
3+
// console.dir(results)
4+
results.success = results.testResults.every(r => r.numFailingTests === 0)
5+
return results
6+
}

‎jest.config.build.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ module.exports = {
1414
preset: "ts-jest/presets/js-with-ts",
1515
testEnvironment: "node",
1616
testMatch: ["**/__tests__/**/*.[jt]s?(x)"],
17-
snapshotResolver: "<rootDir>/jest.config.build.snapshots.js"
17+
snapshotResolver: "<rootDir>/jest.config.build.snapshots.js",
18+
testResultsProcessor: "<rootDir>/ignoreObseleteSnapshots.js"
1819
}

‎readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Winner of the "Breakthrough of the year" [React open source award](https://osawa
1010

1111
## Contribute using one-click online setup
1212

13-
You can use Gitpod(a free online VS Code like IDE) for contributing online. With a single click it will launch a workspace and automatically:
13+
You can use Gitpod (a free online VS Code like IDE) for contributing online. With a single click it will launch a workspace and automatically:
1414

1515
- clone the immer repo.
1616
- install the dependencies.

‎src/utils/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export function die(error: keyof typeof errors, ...args: any[]): never {
5353
}
5454
throw new Error(
5555
`[Immer] minified error nr: ${error}${
56-
args.length ? " " + args.join(",") : ""
56+
args.length ? " " + args.map(s => `'${s}'`).join(",") : ""
5757
}. Find the full error at: https://bit.ly/3cXEKWf`
5858
)
5959
}

0 commit comments

Comments
 (0)
Please sign in to comment.