Skip to content

Commit

Permalink
fix(test): lock in working version of fast-deep-equal
Browse files Browse the repository at this point in the history
Closes #2133
  • Loading branch information
adamdbradley committed Jan 14, 2020
1 parent b3b6993 commit 8ad1540
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
32 changes: 32 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions scripts/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const entryDeps = [
'exit',
'glob',
'graceful-fs',
'fast-deep-equal',
'is-glob',
'is-extglob',
'minimatch',
Expand Down
53 changes: 52 additions & 1 deletion src/testing/matchers/events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as d from '@stencil/core/internal';
import deepEqual from 'fast-deep-equal';


export function toHaveReceivedEvent(eventSpy: d.EventSpy) {
Expand Down Expand Up @@ -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;
};

0 comments on commit 8ad1540

Please sign in to comment.