From 8ad15408e931f5263c1c2dbe221b20c712334572 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Tue, 14 Jan 2020 17:57:19 -0600 Subject: [PATCH] fix(test): lock in working version of fast-deep-equal Closes #2133 --- NOTICE.md | 32 ++++++++++++++++++++ scripts/license.ts | 1 + src/testing/matchers/events.ts | 53 +++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/NOTICE.md b/NOTICE.md index e27adec7156..71d0a4db2ba 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -746,6 +746,38 @@ Homepage: https://github.com/cowboy/node-exit ----------------------------------------- +## `fast-deep-equal` + +License: MIT + +Author: Evgeny Poberezkin + +Homepage: https://github.com/epoberezkin/fast-deep-equal#readme + +> MIT License +> +> Copyright (c) 2017 Evgeny Poberezkin +> +> Permission is hereby granted, free of charge, to any person obtaining a copy +> of this software and associated documentation files (the "Software"), to deal +> in the Software without restriction, including without limitation the rights +> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +> copies of the Software, and to permit persons to whom the Software is +> furnished to do so, subject to the following conditions: +> +> The above copyright notice and this permission notice shall be included in all +> copies or substantial portions of the Software. +> +> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +> SOFTWARE. + +----------------------------------------- + ## `fs.realpath` License: ISC diff --git a/scripts/license.ts b/scripts/license.ts index dbf351f17a1..3997eb28f6d 100644 --- a/scripts/license.ts +++ b/scripts/license.ts @@ -11,6 +11,7 @@ const entryDeps = [ 'exit', 'glob', 'graceful-fs', + 'fast-deep-equal', 'is-glob', 'is-extglob', 'minimatch', diff --git a/src/testing/matchers/events.ts b/src/testing/matchers/events.ts index a8d637ccf49..3103fe5ff9a 100644 --- a/src/testing/matchers/events.ts +++ b/src/testing/matchers/events.ts @@ -1,5 +1,4 @@ import * as d from '@stencil/core/internal'; -import deepEqual from 'fast-deep-equal'; export function toHaveReceivedEvent(eventSpy: d.EventSpy) { @@ -130,3 +129,55 @@ export function toHaveNthReceivedEventDetail(eventSpy: d.EventSpy, index: number pass: pass, }; } + +// from https://www.npmjs.com/package/fast-deep-equal +// License in NOTICE.md +const deepEqual = function equal(a: any, b: any) { + if (a === b) return true; + + if (a && b && typeof a == 'object' && typeof b == 'object') { + var arrA = Array.isArray(a) + , arrB = Array.isArray(b) + , i + , length + , key; + + if (arrA && arrB) { + length = a.length; + if (length != b.length) return false; + for (i = length; i-- !== 0;) + if (!equal(a[i], b[i])) return false; + return true; + } + + if (arrA != arrB) return false; + + var dateA = a instanceof Date + , dateB = b instanceof Date; + if (dateA != dateB) return false; + if (dateA && dateB) return a.getTime() == b.getTime(); + + var regexpA = a instanceof RegExp + , regexpB = b instanceof RegExp; + if (regexpA != regexpB) return false; + if (regexpA && regexpB) return a.toString() == b.toString(); + + var keys = Object.keys(a); + length = keys.length; + + if (length !== Object.keys(b).length) + return false; + + for (i = length; i-- !== 0;) + if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false; + + for (i = length; i-- !== 0;) { + key = keys[i]; + if (!equal(a[key], b[key])) return false; + } + + return true; + } + + return a!==a && b!==b; +};