@aws-solutions-constructs/core 2.78.0 → 2.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +303 -29
- package/lib/cloudfront-distribution-helper.d.ts +29 -0
- package/lib/cloudfront-distribution-helper.js +81 -1
- package/node_modules/deep-diff/.circleci/config.yml +76 -0
- package/node_modules/deep-diff/.eslintrc +72 -0
- package/node_modules/deep-diff/.vscode/launch.json +30 -0
- package/node_modules/deep-diff/.vscode/tasks.json +12 -0
- package/node_modules/deep-diff/ChangeLog.md +63 -0
- package/node_modules/deep-diff/LICENSE +7 -0
- package/node_modules/deep-diff/Readme.md +239 -0
- package/node_modules/deep-diff/dist/deep-diff.min.js +1 -0
- package/node_modules/deep-diff/dist/deep-diff.min.js.map +1 -0
- package/node_modules/deep-diff/examples/apply-diff-from-any.js +39 -0
- package/node_modules/deep-diff/examples/array-change.js +45 -0
- package/node_modules/deep-diff/examples/capture_change_apply_elsewhere.js +53 -0
- package/node_modules/deep-diff/examples/diff-ignoring-fun.js +88 -0
- package/node_modules/deep-diff/examples/diff-scenarios.js +49 -0
- package/node_modules/deep-diff/examples/example1.js +41 -0
- package/node_modules/deep-diff/examples/issue-111.js +6 -0
- package/node_modules/deep-diff/examples/issue-113-1.js +14 -0
- package/node_modules/deep-diff/examples/issue-113-2.js +11 -0
- package/node_modules/deep-diff/examples/issue-115.js +17 -0
- package/node_modules/deep-diff/examples/issue-124.js +8 -0
- package/node_modules/deep-diff/examples/issue-125.js +19 -0
- package/node_modules/deep-diff/examples/issue-126.js +33 -0
- package/node_modules/deep-diff/examples/issue-35.js +11 -0
- package/node_modules/deep-diff/examples/issue-47.js +17 -0
- package/node_modules/deep-diff/examples/issue-48.js +48 -0
- package/node_modules/deep-diff/examples/issue-62.js +14 -0
- package/node_modules/deep-diff/examples/issue-70.js +6 -0
- package/node_modules/deep-diff/examples/issue-71.js +15 -0
- package/node_modules/deep-diff/examples/issue-72.js +21 -0
- package/node_modules/deep-diff/examples/issue-74.js +9 -0
- package/node_modules/deep-diff/examples/issue-78.js +24 -0
- package/node_modules/deep-diff/examples/issue-83.js +11 -0
- package/node_modules/deep-diff/examples/issue-88.js +26 -0
- package/node_modules/deep-diff/examples/performance.js +64 -0
- package/node_modules/deep-diff/examples/practice-data.json +2501 -0
- package/node_modules/deep-diff/index.js +526 -0
- package/node_modules/deep-diff/package.json +74 -0
- package/node_modules/deep-diff/test/.eslintrc +10 -0
- package/node_modules/deep-diff/test/tests.html +34 -0
- package/node_modules/deep-diff/test/tests.js +759 -0
- package/node_modules/deepmerge/.editorconfig +7 -0
- package/node_modules/deepmerge/.eslintcache +1 -0
- package/node_modules/deepmerge/changelog.md +167 -0
- package/node_modules/deepmerge/dist/cjs.js +133 -0
- package/node_modules/deepmerge/dist/umd.js +139 -0
- package/node_modules/deepmerge/index.d.ts +20 -0
- package/node_modules/deepmerge/index.js +106 -0
- package/node_modules/deepmerge/license.txt +21 -0
- package/node_modules/deepmerge/package.json +42 -0
- package/node_modules/deepmerge/readme.md +264 -0
- package/node_modules/deepmerge/rollup.config.js +22 -0
- package/node_modules/npmlog/LICENSE.md +20 -0
- package/node_modules/npmlog/README.md +216 -0
- package/node_modules/npmlog/lib/log.js +400 -0
- package/node_modules/npmlog/package.json +52 -0
- package/nohoist.sh +11 -0
- package/package.json +3 -2
- package/test/cloudfront-distribution-s3-helper.test.js +455 -1
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
(function (root, factory) {
|
|
2
|
+
if (typeof define === 'function' && define.amd) { // eslint-disable-line no-undef
|
|
3
|
+
define(['deep-diff', 'expect.js'], factory);// eslint-disable-line no-undef
|
|
4
|
+
} else if (typeof module === 'object' && module.exports) {
|
|
5
|
+
module.exports = factory(require('../'), require('expect.js'));
|
|
6
|
+
} else {
|
|
7
|
+
root.returnExports = factory(root.DeepDiff, root.expect);
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line no-undef
|
|
10
|
+
}(typeof self !== 'undefined' ? self : this, function (deep, expect) {
|
|
11
|
+
|
|
12
|
+
describe('deep-diff', function () {
|
|
13
|
+
var empty = {};
|
|
14
|
+
|
|
15
|
+
describe('A target that has no properties', function () {
|
|
16
|
+
|
|
17
|
+
it('shows no differences when compared to another empty object', function () {
|
|
18
|
+
expect(deep.diff(empty, {})).to.be.an('undefined');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('when compared to a different type of keyless object', function () {
|
|
22
|
+
var comparandTuples = [
|
|
23
|
+
['an array', {
|
|
24
|
+
key: []
|
|
25
|
+
}],
|
|
26
|
+
['an object', {
|
|
27
|
+
key: {}
|
|
28
|
+
}],
|
|
29
|
+
['a date', {
|
|
30
|
+
key: new Date()
|
|
31
|
+
}],
|
|
32
|
+
['a null', {
|
|
33
|
+
key: null
|
|
34
|
+
}],
|
|
35
|
+
['a regexp literal', {
|
|
36
|
+
key: /a/
|
|
37
|
+
}],
|
|
38
|
+
['Math', {
|
|
39
|
+
key: Math
|
|
40
|
+
}]
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
comparandTuples.forEach(function (lhsTuple) {
|
|
44
|
+
comparandTuples.forEach(function (rhsTuple) {
|
|
45
|
+
if (lhsTuple[0] === rhsTuple[0]) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
it('shows differences when comparing ' + lhsTuple[0] + ' to ' + rhsTuple[0], function () {
|
|
49
|
+
var diff = deep.diff(lhsTuple[1], rhsTuple[1]);
|
|
50
|
+
expect(diff).to.be.ok();
|
|
51
|
+
expect(diff.length).to.be(1);
|
|
52
|
+
expect(diff[0]).to.have.property('kind');
|
|
53
|
+
expect(diff[0].kind).to.be('E');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('when compared with an object having other properties', function () {
|
|
60
|
+
var comparand = {
|
|
61
|
+
other: 'property',
|
|
62
|
+
another: 13.13
|
|
63
|
+
};
|
|
64
|
+
var diff = deep.diff(empty, comparand);
|
|
65
|
+
|
|
66
|
+
it('the differences are reported', function () {
|
|
67
|
+
expect(diff).to.be.ok();
|
|
68
|
+
expect(diff.length).to.be(2);
|
|
69
|
+
|
|
70
|
+
expect(diff[0]).to.have.property('kind');
|
|
71
|
+
expect(diff[0].kind).to.be('N');
|
|
72
|
+
expect(diff[0]).to.have.property('path');
|
|
73
|
+
expect(diff[0].path).to.be.an(Array);
|
|
74
|
+
expect(diff[0].path[0]).to.eql('other');
|
|
75
|
+
expect(diff[0]).to.have.property('rhs');
|
|
76
|
+
expect(diff[0].rhs).to.be('property');
|
|
77
|
+
|
|
78
|
+
expect(diff[1]).to.have.property('kind');
|
|
79
|
+
expect(diff[1].kind).to.be('N');
|
|
80
|
+
expect(diff[1]).to.have.property('path');
|
|
81
|
+
expect(diff[1].path).to.be.an(Array);
|
|
82
|
+
expect(diff[1].path[0]).to.eql('another');
|
|
83
|
+
expect(diff[1]).to.have.property('rhs');
|
|
84
|
+
expect(diff[1].rhs).to.be(13.13);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('A target that has one property', function () {
|
|
92
|
+
var lhs = {
|
|
93
|
+
one: 'property'
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
it('shows no differences when compared to itself', function () {
|
|
97
|
+
expect(deep.diff(lhs, lhs)).to.be.an('undefined');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('shows the property as removed when compared to an empty object', function () {
|
|
101
|
+
var diff = deep.diff(lhs, empty);
|
|
102
|
+
expect(diff).to.be.ok();
|
|
103
|
+
expect(diff.length).to.be(1);
|
|
104
|
+
expect(diff[0]).to.have.property('kind');
|
|
105
|
+
expect(diff[0].kind).to.be('D');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('shows the property as edited when compared to an object with null', function () {
|
|
109
|
+
var diff = deep.diff(lhs, {
|
|
110
|
+
one: null
|
|
111
|
+
});
|
|
112
|
+
expect(diff).to.be.ok();
|
|
113
|
+
expect(diff.length).to.be(1);
|
|
114
|
+
expect(diff[0]).to.have.property('kind');
|
|
115
|
+
expect(diff[0].kind).to.be('E');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('shows the property as edited when compared to an array', function () {
|
|
119
|
+
var diff = deep.diff(lhs, ['one']);
|
|
120
|
+
expect(diff).to.be.ok();
|
|
121
|
+
expect(diff.length).to.be(1);
|
|
122
|
+
expect(diff[0]).to.have.property('kind');
|
|
123
|
+
expect(diff[0].kind).to.be('E');
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
describe('A target that has null value', function () {
|
|
129
|
+
var lhs = {
|
|
130
|
+
key: null
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
it('shows no differences when compared to itself', function () {
|
|
134
|
+
expect(deep.diff(lhs, lhs)).to.be.an('undefined');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('shows the property as removed when compared to an empty object', function () {
|
|
138
|
+
var diff = deep.diff(lhs, empty);
|
|
139
|
+
expect(diff).to.be.ok();
|
|
140
|
+
expect(diff.length).to.be(1);
|
|
141
|
+
expect(diff[0]).to.have.property('kind');
|
|
142
|
+
expect(diff[0].kind).to.be('D');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('shows the property is changed when compared to an object that has value', function () {
|
|
146
|
+
var diff = deep.diff(lhs, {
|
|
147
|
+
key: 'value'
|
|
148
|
+
});
|
|
149
|
+
expect(diff).to.be.ok();
|
|
150
|
+
expect(diff.length).to.be(1);
|
|
151
|
+
expect(diff[0]).to.have.property('kind');
|
|
152
|
+
expect(diff[0].kind).to.be('E');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('shows that an object property is changed when it is set to null', function () {
|
|
156
|
+
lhs.key = {
|
|
157
|
+
nested: 'value'
|
|
158
|
+
};
|
|
159
|
+
var diff = deep.diff(lhs, {
|
|
160
|
+
key: null
|
|
161
|
+
});
|
|
162
|
+
expect(diff).to.be.ok();
|
|
163
|
+
expect(diff.length).to.be(1);
|
|
164
|
+
expect(diff[0]).to.have.property('kind');
|
|
165
|
+
expect(diff[0].kind).to.be('E');
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
describe('A target that has a date value', function () {
|
|
172
|
+
var lhs = {
|
|
173
|
+
key: new Date(555555555555)
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
it('shows the property is changed with a new date value', function () {
|
|
177
|
+
var diff = deep.diff(lhs, {
|
|
178
|
+
key: new Date(777777777777)
|
|
179
|
+
});
|
|
180
|
+
expect(diff).to.be.ok();
|
|
181
|
+
expect(diff.length).to.be(1);
|
|
182
|
+
expect(diff[0]).to.have.property('kind');
|
|
183
|
+
expect(diff[0].kind).to.be('E');
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
describe('A target that has a NaN', function () {
|
|
190
|
+
var lhs = {
|
|
191
|
+
key: NaN
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
it('shows the property is changed when compared to another number', function () {
|
|
195
|
+
var diff = deep.diff(lhs, {
|
|
196
|
+
key: 0
|
|
197
|
+
});
|
|
198
|
+
expect(diff).to.be.ok();
|
|
199
|
+
expect(diff.length).to.be(1);
|
|
200
|
+
expect(diff[0]).to.have.property('kind');
|
|
201
|
+
expect(diff[0].kind).to.be('E');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('shows no differences when compared to another NaN', function () {
|
|
205
|
+
var diff = deep.diff(lhs, {
|
|
206
|
+
key: NaN
|
|
207
|
+
});
|
|
208
|
+
expect(diff).to.be.an('undefined');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
describe('can revert namespace using noConflict', function () {
|
|
215
|
+
if (deep.noConflict) {
|
|
216
|
+
deep = deep.noConflict();
|
|
217
|
+
|
|
218
|
+
it('conflict is restored (when applicable)', function () {
|
|
219
|
+
// In node there is no global conflict.
|
|
220
|
+
if (typeof globalConflict !== 'undefined') {
|
|
221
|
+
expect(DeepDiff).to.be(deep); // eslint-disable-line no-undef
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('DeepDiff functionality available through result of noConflict()', function () {
|
|
226
|
+
expect(deep.applyDiff).to.be.a('function');
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
describe('When filtering keys', function () {
|
|
233
|
+
var lhs = {
|
|
234
|
+
enhancement: 'Filter/Ignore Keys?',
|
|
235
|
+
numero: 11,
|
|
236
|
+
submittedBy: 'ericclemmons',
|
|
237
|
+
supportedBy: ['ericclemmons'],
|
|
238
|
+
status: 'open'
|
|
239
|
+
};
|
|
240
|
+
var rhs = {
|
|
241
|
+
enhancement: 'Filter/Ignore Keys?',
|
|
242
|
+
numero: 11,
|
|
243
|
+
submittedBy: 'ericclemmons',
|
|
244
|
+
supportedBy: [
|
|
245
|
+
'ericclemmons',
|
|
246
|
+
'TylerGarlick',
|
|
247
|
+
'flitbit',
|
|
248
|
+
'ergdev'
|
|
249
|
+
],
|
|
250
|
+
status: 'closed',
|
|
251
|
+
fixedBy: 'flitbit'
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
describe('if the filtered property is an array', function () {
|
|
255
|
+
|
|
256
|
+
it('changes to the array do not appear as a difference', function () {
|
|
257
|
+
var prefilter = function (path, key) {
|
|
258
|
+
return key === 'supportedBy';
|
|
259
|
+
};
|
|
260
|
+
var diff = deep(lhs, rhs, prefilter);
|
|
261
|
+
expect(diff).to.be.ok();
|
|
262
|
+
expect(diff.length).to.be(2);
|
|
263
|
+
expect(diff[0]).to.have.property('kind');
|
|
264
|
+
expect(diff[0].kind).to.be('E');
|
|
265
|
+
expect(diff[1]).to.have.property('kind');
|
|
266
|
+
expect(diff[1].kind).to.be('N');
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
describe('if the filtered property is not an array', function () {
|
|
272
|
+
|
|
273
|
+
it('changes do not appear as a difference', function () {
|
|
274
|
+
var prefilter = function (path, key) {
|
|
275
|
+
return key === 'fixedBy';
|
|
276
|
+
};
|
|
277
|
+
var diff = deep(lhs, rhs, prefilter);
|
|
278
|
+
expect(diff).to.be.ok();
|
|
279
|
+
expect(diff.length).to.be(4);
|
|
280
|
+
expect(diff[0]).to.have.property('kind');
|
|
281
|
+
expect(diff[0].kind).to.be('A');
|
|
282
|
+
expect(diff[1]).to.have.property('kind');
|
|
283
|
+
expect(diff[1].kind).to.be('A');
|
|
284
|
+
expect(diff[2]).to.have.property('kind');
|
|
285
|
+
expect(diff[2].kind).to.be('A');
|
|
286
|
+
expect(diff[3]).to.have.property('kind');
|
|
287
|
+
expect(diff[3].kind).to.be('E');
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe('A target that has nested values', function () {
|
|
294
|
+
var nestedOne = {
|
|
295
|
+
noChange: 'same',
|
|
296
|
+
levelOne: {
|
|
297
|
+
levelTwo: 'value'
|
|
298
|
+
},
|
|
299
|
+
arrayOne: [{
|
|
300
|
+
objValue: 'value'
|
|
301
|
+
}]
|
|
302
|
+
};
|
|
303
|
+
var nestedTwo = {
|
|
304
|
+
noChange: 'same',
|
|
305
|
+
levelOne: {
|
|
306
|
+
levelTwo: 'another value'
|
|
307
|
+
},
|
|
308
|
+
arrayOne: [{
|
|
309
|
+
objValue: 'new value'
|
|
310
|
+
}, {
|
|
311
|
+
objValue: 'more value'
|
|
312
|
+
}]
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
it('shows no differences when compared to itself', function () {
|
|
316
|
+
expect(deep.diff(nestedOne, nestedOne)).to.be.an('undefined');
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('shows the property as removed when compared to an empty object', function () {
|
|
320
|
+
var diff = deep(nestedOne, empty);
|
|
321
|
+
expect(diff).to.be.ok();
|
|
322
|
+
expect(diff.length).to.be(3);
|
|
323
|
+
expect(diff[0]).to.have.property('kind');
|
|
324
|
+
expect(diff[0].kind).to.be('D');
|
|
325
|
+
expect(diff[1]).to.have.property('kind');
|
|
326
|
+
expect(diff[1].kind).to.be('D');
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('shows the property is changed when compared to an object that has value', function () {
|
|
330
|
+
var diff = deep.diff(nestedOne, nestedTwo);
|
|
331
|
+
expect(diff).to.be.ok();
|
|
332
|
+
expect(diff.length).to.be(3);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('shows the property as added when compared to an empty object on left', function () {
|
|
336
|
+
var diff = deep.diff(empty, nestedOne);
|
|
337
|
+
expect(diff).to.be.ok();
|
|
338
|
+
expect(diff.length).to.be(3);
|
|
339
|
+
expect(diff[0]).to.have.property('kind');
|
|
340
|
+
expect(diff[0].kind).to.be('N');
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
describe('when diff is applied to a different empty object', function () {
|
|
344
|
+
var diff = deep.diff(nestedOne, nestedTwo);
|
|
345
|
+
|
|
346
|
+
it('has result with nested values', function () {
|
|
347
|
+
var result = {};
|
|
348
|
+
|
|
349
|
+
deep.applyChange(result, nestedTwo, diff[0]);
|
|
350
|
+
expect(result.levelOne).to.be.ok();
|
|
351
|
+
expect(result.levelOne).to.be.an('object');
|
|
352
|
+
expect(result.levelOne.levelTwo).to.be.ok();
|
|
353
|
+
expect(result.levelOne.levelTwo).to.eql('another value');
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('has result with array object values', function () {
|
|
357
|
+
var result = {};
|
|
358
|
+
|
|
359
|
+
deep.applyChange(result, nestedTwo, diff[2]);
|
|
360
|
+
expect(result.arrayOne).to.be.ok();
|
|
361
|
+
expect(result.arrayOne).to.be.an('array');
|
|
362
|
+
expect(result.arrayOne[0]).to.be.ok();
|
|
363
|
+
expect(result.arrayOne[0].objValue).to.be.ok();
|
|
364
|
+
expect(result.arrayOne[0].objValue).to.equal('new value');
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it('has result with added array objects', function () {
|
|
368
|
+
var result = {};
|
|
369
|
+
|
|
370
|
+
deep.applyChange(result, nestedTwo, diff[1]);
|
|
371
|
+
expect(result.arrayOne).to.be.ok();
|
|
372
|
+
expect(result.arrayOne).to.be.an('array');
|
|
373
|
+
expect(result.arrayOne[1]).to.be.ok();
|
|
374
|
+
expect(result.arrayOne[1].objValue).to.be.ok();
|
|
375
|
+
expect(result.arrayOne[1].objValue).to.equal('more value');
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
describe('regression test for bug #10, ', function () {
|
|
381
|
+
var lhs = {
|
|
382
|
+
id: 'Release',
|
|
383
|
+
phases: [{
|
|
384
|
+
id: 'Phase1',
|
|
385
|
+
tasks: [{
|
|
386
|
+
id: 'Task1'
|
|
387
|
+
}, {
|
|
388
|
+
id: 'Task2'
|
|
389
|
+
}]
|
|
390
|
+
}, {
|
|
391
|
+
id: 'Phase2',
|
|
392
|
+
tasks: [{
|
|
393
|
+
id: 'Task3'
|
|
394
|
+
}]
|
|
395
|
+
}]
|
|
396
|
+
};
|
|
397
|
+
var rhs = {
|
|
398
|
+
id: 'Release',
|
|
399
|
+
phases: [{
|
|
400
|
+
// E: Phase1 -> Phase2
|
|
401
|
+
id: 'Phase2',
|
|
402
|
+
tasks: [{
|
|
403
|
+
id: 'Task3'
|
|
404
|
+
}]
|
|
405
|
+
}, {
|
|
406
|
+
id: 'Phase1',
|
|
407
|
+
tasks: [{
|
|
408
|
+
id: 'Task1'
|
|
409
|
+
}, {
|
|
410
|
+
id: 'Task2'
|
|
411
|
+
}]
|
|
412
|
+
}]
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
describe('differences in nested arrays are detected', function () {
|
|
416
|
+
var diff = deep.diff(lhs, rhs);
|
|
417
|
+
|
|
418
|
+
// there should be differences
|
|
419
|
+
expect(diff).to.be.ok();
|
|
420
|
+
expect(diff.length).to.be(6);
|
|
421
|
+
|
|
422
|
+
it('differences can be applied', function () {
|
|
423
|
+
var applied = deep.applyDiff(lhs, rhs);
|
|
424
|
+
|
|
425
|
+
it('and the result equals the rhs', function () {
|
|
426
|
+
expect(applied).to.eql(rhs);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
describe('regression test for bug #35', function () {
|
|
435
|
+
var lhs = ['a', 'a', 'a'];
|
|
436
|
+
var rhs = ['a'];
|
|
437
|
+
|
|
438
|
+
it('can apply diffs between two top level arrays', function () {
|
|
439
|
+
var differences = deep.diff(lhs, rhs);
|
|
440
|
+
|
|
441
|
+
differences.forEach(function (it) {
|
|
442
|
+
deep.applyChange(lhs, true, it);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
expect(lhs).to.eql(['a']);
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
describe('Objects from different frames', function () {
|
|
450
|
+
if (typeof globalConflict === 'undefined') { return; }
|
|
451
|
+
|
|
452
|
+
// eslint-disable-next-line no-undef
|
|
453
|
+
var frame = document.createElement('iframe');
|
|
454
|
+
// eslint-disable-next-line no-undef
|
|
455
|
+
document.body.appendChild(frame);
|
|
456
|
+
|
|
457
|
+
var lhs = new frame.contentWindow.Date(2010, 1, 1);
|
|
458
|
+
var rhs = new frame.contentWindow.Date(2010, 1, 1);
|
|
459
|
+
|
|
460
|
+
it('can compare date instances from a different frame', function () {
|
|
461
|
+
var differences = deep.diff(lhs, rhs);
|
|
462
|
+
|
|
463
|
+
expect(differences).to.be(undefined);
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
describe('Comparing regexes should work', function () {
|
|
468
|
+
var lhs = /foo/;
|
|
469
|
+
var rhs = /foo/i;
|
|
470
|
+
|
|
471
|
+
it('can compare regex instances', function () {
|
|
472
|
+
var diff = deep.diff(lhs, rhs);
|
|
473
|
+
|
|
474
|
+
expect(diff.length).to.be(1);
|
|
475
|
+
|
|
476
|
+
expect(diff[0].kind).to.be('E');
|
|
477
|
+
expect(diff[0].path).to.not.be.ok();
|
|
478
|
+
expect(diff[0].lhs).to.be('/foo/');
|
|
479
|
+
expect(diff[0].rhs).to.be('/foo/i');
|
|
480
|
+
});
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
describe('subject.toString is not a function', function () {
|
|
484
|
+
var lhs = {
|
|
485
|
+
left: 'yes',
|
|
486
|
+
right: 'no',
|
|
487
|
+
};
|
|
488
|
+
var rhs = {
|
|
489
|
+
left: {
|
|
490
|
+
toString: true,
|
|
491
|
+
},
|
|
492
|
+
right: 'no',
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
it('should not throw a TypeError', function () {
|
|
496
|
+
var diff = deep.diff(lhs, rhs);
|
|
497
|
+
|
|
498
|
+
expect(diff.length).to.be(1);
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
describe('regression test for issue #83', function () {
|
|
503
|
+
var lhs = {
|
|
504
|
+
date: null
|
|
505
|
+
};
|
|
506
|
+
var rhs = {
|
|
507
|
+
date: null
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
it('should not detect a difference', function () {
|
|
511
|
+
expect(deep.diff(lhs, rhs)).to.be(undefined);
|
|
512
|
+
});
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
describe('regression test for issue #70', function () {
|
|
516
|
+
|
|
517
|
+
it('should detect a difference with undefined property on lhs', function () {
|
|
518
|
+
var diff = deep.diff({ foo: undefined }, {});
|
|
519
|
+
|
|
520
|
+
expect(diff).to.be.an(Array);
|
|
521
|
+
expect(diff.length).to.be(1);
|
|
522
|
+
|
|
523
|
+
expect(diff[0].kind).to.be('D');
|
|
524
|
+
expect(diff[0].path).to.be.an('array');
|
|
525
|
+
expect(diff[0].path).to.have.length(1);
|
|
526
|
+
expect(diff[0].path[0]).to.be('foo');
|
|
527
|
+
expect(diff[0].lhs).to.be(undefined);
|
|
528
|
+
|
|
529
|
+
});
|
|
530
|
+
|
|
531
|
+
it('should detect a difference with undefined property on rhs', function () {
|
|
532
|
+
var diff = deep.diff({}, { foo: undefined });
|
|
533
|
+
|
|
534
|
+
expect(diff).to.be.an(Array);
|
|
535
|
+
expect(diff.length).to.be(1);
|
|
536
|
+
|
|
537
|
+
expect(diff[0].kind).to.be('N');
|
|
538
|
+
expect(diff[0].path).to.be.an('array');
|
|
539
|
+
expect(diff[0].path).to.have.length(1);
|
|
540
|
+
expect(diff[0].path[0]).to.be('foo');
|
|
541
|
+
expect(diff[0].rhs).to.be(undefined);
|
|
542
|
+
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
describe('regression test for issue #98', function () {
|
|
547
|
+
var lhs = { foo: undefined };
|
|
548
|
+
var rhs = { foo: undefined };
|
|
549
|
+
|
|
550
|
+
it('should not detect a difference with two undefined property values', function () {
|
|
551
|
+
var diff = deep.diff(lhs, rhs);
|
|
552
|
+
|
|
553
|
+
expect(diff).to.be(undefined);
|
|
554
|
+
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
describe('regression tests for issue #102', function () {
|
|
559
|
+
it('should not throw a TypeError', function () {
|
|
560
|
+
|
|
561
|
+
var diff = deep.diff(null, undefined);
|
|
562
|
+
|
|
563
|
+
expect(diff).to.be.an(Array);
|
|
564
|
+
expect(diff.length).to.be(1);
|
|
565
|
+
|
|
566
|
+
expect(diff[0].kind).to.be('D');
|
|
567
|
+
expect(diff[0].lhs).to.be(null);
|
|
568
|
+
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
it('should not throw a TypeError', function () {
|
|
572
|
+
|
|
573
|
+
var diff = deep.diff(Object.create(null), { foo: undefined });
|
|
574
|
+
|
|
575
|
+
expect(diff).to.be.an(Array);
|
|
576
|
+
expect(diff.length).to.be(1);
|
|
577
|
+
|
|
578
|
+
expect(diff[0].kind).to.be('N');
|
|
579
|
+
expect(diff[0].rhs).to.be(undefined);
|
|
580
|
+
});
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
describe('Order independent hash testing', function () {
|
|
584
|
+
function sameHash(a, b) {
|
|
585
|
+
expect(deep.orderIndepHash(a)).to.equal(deep.orderIndepHash(b));
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function differentHash(a, b) {
|
|
589
|
+
expect(deep.orderIndepHash(a)).to.not.equal(deep.orderIndepHash(b));
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
describe('Order indepdendent hash function should give different values for different objects', function () {
|
|
593
|
+
it('should give different values for different "simple" types', function () {
|
|
594
|
+
differentHash(1, -20);
|
|
595
|
+
differentHash('foo', 45);
|
|
596
|
+
differentHash('pie', 'something else');
|
|
597
|
+
differentHash(1.3332, 1);
|
|
598
|
+
differentHash(1, null);
|
|
599
|
+
differentHash('this is kind of a long string, don\'t you think?', 'the quick brown fox jumped over the lazy doge');
|
|
600
|
+
differentHash(true, 2);
|
|
601
|
+
differentHash(false, 'flooog');
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
it('should give different values for string and object with string', function () {
|
|
605
|
+
differentHash('some string', { key: 'some string' });
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
it('should give different values for number and array', function () {
|
|
609
|
+
differentHash(1, [1]);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
it('should give different values for string and array of string', function () {
|
|
613
|
+
differentHash('string', ['string']);
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
it('should give different values for boolean and object with boolean', function () {
|
|
617
|
+
differentHash(true, { key: true });
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
it('should give different values for different arrays', function () {
|
|
621
|
+
differentHash([1, 2, 3], [1, 2]);
|
|
622
|
+
differentHash([1, 4, 5, 6], ['foo', 1, true, undefined]);
|
|
623
|
+
differentHash([1, 4, 6], [1, 4, 7]);
|
|
624
|
+
differentHash([1, 3, 5], ['1', '3', '5']);
|
|
625
|
+
});
|
|
626
|
+
|
|
627
|
+
it('should give different values for different objects', function () {
|
|
628
|
+
differentHash({ key: 'value' }, { other: 'value' });
|
|
629
|
+
differentHash({ a: { b: 'c' } }, { a: 'b' });
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
it('should differentiate between arrays and objects', function () {
|
|
633
|
+
differentHash([1, true, '1'], { a: 1, b: true, c: '1' });
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
describe('Order independent hash function should work in pathological cases', function () {
|
|
638
|
+
it('should work in funky javascript cases', function () {
|
|
639
|
+
differentHash(undefined, null);
|
|
640
|
+
differentHash(0, undefined);
|
|
641
|
+
differentHash(0, null);
|
|
642
|
+
differentHash(0, false);
|
|
643
|
+
differentHash(0, []);
|
|
644
|
+
differentHash('', []);
|
|
645
|
+
differentHash(3.22, '3.22');
|
|
646
|
+
differentHash(true, 'true');
|
|
647
|
+
differentHash(false, 0);
|
|
648
|
+
});
|
|
649
|
+
|
|
650
|
+
it('should work on empty array and object', function () {
|
|
651
|
+
differentHash([], {});
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
it('should work on empty object and undefined', function () {
|
|
655
|
+
differentHash({}, undefined);
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
it('should work on empty array and array with 0', function () {
|
|
659
|
+
differentHash([], [0]);
|
|
660
|
+
});
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
describe('Order independent hash function should be order independent', function () {
|
|
664
|
+
it('should not care about array order', function () {
|
|
665
|
+
sameHash([1, 2, 3], [3, 2, 1]);
|
|
666
|
+
sameHash(['hi', true, 9.4], [true, 'hi', 9.4]);
|
|
667
|
+
});
|
|
668
|
+
|
|
669
|
+
it('should not care about key order in an object', function () {
|
|
670
|
+
sameHash({ foo: 'bar', foz: 'baz' }, { foz: 'baz', foo: 'bar' });
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
it('should work with complicated objects', function () {
|
|
674
|
+
var obj1 = {
|
|
675
|
+
foo: 'bar',
|
|
676
|
+
faz: [
|
|
677
|
+
1,
|
|
678
|
+
'pie',
|
|
679
|
+
{
|
|
680
|
+
food: 'yum'
|
|
681
|
+
}
|
|
682
|
+
]
|
|
683
|
+
};
|
|
684
|
+
|
|
685
|
+
var obj2 = {
|
|
686
|
+
faz: [
|
|
687
|
+
'pie',
|
|
688
|
+
{
|
|
689
|
+
food: 'yum'
|
|
690
|
+
},
|
|
691
|
+
1
|
|
692
|
+
],
|
|
693
|
+
foo: 'bar'
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
sameHash(obj1, obj2);
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
describe('Order indepedent array comparison should work', function () {
|
|
703
|
+
it('can compare simple arrays in an order independent fashion', function () {
|
|
704
|
+
var lhs = [1, 2, 3];
|
|
705
|
+
var rhs = [1, 3, 2];
|
|
706
|
+
|
|
707
|
+
var diff = deep.orderIndependentDiff(lhs, rhs);
|
|
708
|
+
expect(diff).to.be(undefined);
|
|
709
|
+
});
|
|
710
|
+
|
|
711
|
+
it('still works with repeated elements', function () {
|
|
712
|
+
var lhs = [1, 1, 2];
|
|
713
|
+
var rhs = [1, 2, 1];
|
|
714
|
+
|
|
715
|
+
var diff = deep.orderIndependentDiff(lhs, rhs);
|
|
716
|
+
expect(diff).to.be(undefined);
|
|
717
|
+
});
|
|
718
|
+
|
|
719
|
+
it('works on complex objects', function () {
|
|
720
|
+
var obj1 = {
|
|
721
|
+
foo: 'bar',
|
|
722
|
+
faz: [
|
|
723
|
+
1,
|
|
724
|
+
'pie',
|
|
725
|
+
{
|
|
726
|
+
food: 'yum'
|
|
727
|
+
}
|
|
728
|
+
]
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
var obj2 = {
|
|
732
|
+
faz: [
|
|
733
|
+
'pie',
|
|
734
|
+
{
|
|
735
|
+
food: 'yum'
|
|
736
|
+
},
|
|
737
|
+
1
|
|
738
|
+
],
|
|
739
|
+
foo: 'bar'
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
var diff = deep.orderIndependentDiff(obj1, obj2);
|
|
743
|
+
expect(diff).to.be(undefined);
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
it('should report some difference in non-equal arrays', function () {
|
|
747
|
+
var lhs = [1, 2, 3];
|
|
748
|
+
var rhs = [2, 2, 3];
|
|
749
|
+
|
|
750
|
+
var diff = deep.orderIndependentDiff(lhs, rhs);
|
|
751
|
+
expect(diff.length).to.be.ok();
|
|
752
|
+
});
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
});
|
|
756
|
+
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
}));
|