GeezerVison is showing github.com — assert: make partialDeepStrictEqual work with urls and File prototypes · nodejs/node@eb2bf46
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/assert.js +7-2Lines changed: 7 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -95,6 +95,7 @@ const CallTracker = require('internal/assert/calltracker'); | 95 | 95 | const { | 96 | 96 | validateFunction, | 97 | 97 | } = require('internal/validators'); | | 98 | +const { isURL } = require('internal/url'); | 98 | 99 |
| 99 | 100 | let isDeepEqual; | 100 | 101 | let isDeepStrictEqual; | @@ -383,7 +384,7 @@ function isSpecial(obj) { | 383 | 384 | } | 384 | 385 |
| 385 | 386 | const typesToCallDeepStrictEqualWith = [ | 386 | | - isKeyObject, isWeakSet, isWeakMap, Buffer.isBuffer, isSharedArrayBuffer, | | 387 | + isKeyObject, isWeakSet, isWeakMap, Buffer.isBuffer, isSharedArrayBuffer, isURL, | 387 | 388 | ]; | 388 | 389 |
| 389 | 390 | function partiallyCompareMaps(actual, expected, comparedObjects) { | @@ -466,7 +467,7 @@ function partiallyCompareArrayBuffersOrViews(actual, expected) { | 466 | 467 | } | 467 | 468 |
| 468 | 469 | for (let i = 0; i < expectedViewLength; i++) { | 469 | | - if (actualView[i] !== expectedView[i]) { | | 470 | + if (!ObjectIs(actualView[i], expectedView[i])) { | 470 | 471 | return false; | 471 | 472 | } | 472 | 473 | } | @@ -586,6 +587,10 @@ function compareBranch( | 586 | 587 | expected, | 587 | 588 | comparedObjects, | 588 | 589 | ) { | | 590 | + // Checking for the simplest case possible. | | 591 | + if (actual === expected) { | | 592 | + return true; | | 593 | + } | 589 | 594 | // Check for Map object equality | 590 | 595 | if (isMap(actual) && isMap(expected)) { | 591 | 596 | return partiallyCompareMaps(actual, expected, comparedObjects); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-assert-objects.js +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -306,6 +306,16 @@ describe('Object Comparison Tests', () => { | 306 | 306 | actual: { dataView: new Uint8Array(3) }, | 307 | 307 | expected: { dataView: new DataView(new ArrayBuffer(3)) }, | 308 | 308 | }, | | 309 | + { | | 310 | + description: 'throws when comparing Float32Array([+0.0]) with Float32Array([-0.0])', | | 311 | + actual: new Float32Array([+0.0]), | | 312 | + expected: new Float32Array([-0.0]), | | 313 | + }, | | 314 | + { | | 315 | + description: 'throws when comparing two different urls', | | 316 | + actual: new URL('http://foo'), | | 317 | + expected: new URL('http://bar'), | | 318 | + }, | 309 | 319 | { | 310 | 320 | description: 'throws when comparing SharedArrayBuffers when expected has different elements actual', | 311 | 321 | actual: (() => { | @@ -778,6 +788,21 @@ describe('Object Comparison Tests', () => { | 778 | 788 | actual: [1, 2, 3], | 779 | 789 | expected: [2], | 780 | 790 | }, | | 791 | + { | | 792 | + description: 'ensures that File extends Blob', | | 793 | + actual: Object.getPrototypeOf(File.prototype), | | 794 | + expected: Blob.prototype | | 795 | + }, | | 796 | + { | | 797 | + description: 'compares NaN with NaN', | | 798 | + actual: NaN, | | 799 | + expected: NaN, | | 800 | + }, | | 801 | + { | | 802 | + description: 'compares two identical urls', | | 803 | + actual: new URL('http://foo'), | | 804 | + expected: new URL('http://foo'), | | 805 | + }, | 781 | 806 | ].forEach(({ description, actual, expected }) => { | 782 | 807 | it(description, () => { | 783 | 808 | assert.partialDeepStrictEqual(actual, expected); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-assert-typedarray-deepequal.js +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -101,10 +101,15 @@ suite('notEqualArrayPairs', () => { | 101 | 101 | makeBlock(assert.deepStrictEqual, arrayPair[0], arrayPair[1]), | 102 | 102 | assert.AssertionError | 103 | 103 | ); | | 104 | + // TODO(puskin94): remove emitWarning override once the partialDeepStrictEqual method is not experimental anymore | | 105 | + // Suppress warnings, necessary otherwise the tools/pseudo-tty.py runner will fail | | 106 | + const originalEmitWarning = process.emitWarning; | | 107 | + process.emitWarning = () => {}; | 104 | 108 | assert.throws( | 105 | 109 | makeBlock(assert.partialDeepStrictEqual, arrayPair[0], arrayPair[1]), | 106 | 110 | assert.AssertionError | 107 | 111 | ); | | 112 | + process.emitWarning = originalEmitWarning; // Restore original process.emitWarning | 108 | 113 | }); | 109 | 114 | } | 110 | 115 | }); |
|