Skip to content

Commit

Permalink
[Fix] avoid failing in ES3 engines that lack Object.keys, and .every
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 14, 2022
1 parent 61446b9 commit dfc5f39
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bin/tape
Expand Up @@ -3,6 +3,7 @@
'use strict';

var parseOpts = require('minimist');
var objectKeys = require('object-keys');

var opts = parseOpts(process.argv.slice(2), {
alias: { r: 'require', i: 'ignore' },
Expand All @@ -18,7 +19,7 @@ if (typeof opts.require === 'string') {

var resolveModule;
opts.require.forEach(function (module) {
var options = { basedir: cwd, extensions: Object.keys(require.extensions) };
var options = { basedir: cwd, extensions: objectKeys(require.extensions) };
if (module) {
if (!resolveModule) { resolveModule = require('resolve').sync; }
// This check ensures we ignore `-r ""`, trailing `-r`, or other silly things the user might (inadvertently) be doing.
Expand Down
7 changes: 5 additions & 2 deletions lib/test.js
Expand Up @@ -12,6 +12,9 @@ var callBound = require('call-bind/callBound');
var forEach = require('for-each');
var inspect = require('object-inspect');
var is = require('object-is');
var objectKeys = require('object-keys');
var every = require('array.prototype.every');

var isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
var toLowerCase = callBound('String.prototype.toLowerCase');
var isProto = callBound('Object.prototype.isPrototypeOf');
Expand Down Expand Up @@ -654,14 +657,14 @@ Test.prototype['throws'] = function (fn, expected, msg, extra) {
passed = expected.test(caught.error);
expected = inspect(expected);
} else if (expected && typeof expected === 'object') { // Handle validation objects.
var keys = Object.keys(expected);
var keys = objectKeys(expected);
// Special handle errors to make sure the name and the message are compared as well.
if (expected instanceof Error) {
$push(keys, 'name', 'message');
} else if (keys.length === 0) {
throw new TypeError('`throws` validation object must not be empty');
}
passed = keys.every(function (key) {
passed = every(keys, function (key) {
if (typeof caught.error[key] === 'string' && isRegExp(expected[key]) && $test(expected[key], caught.error[key])) {
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -25,6 +25,7 @@
"test": "test"
},
"dependencies": {
"array.prototype.every": "^1.1.3",
"call-bind": "^1.0.2",
"deep-equal": "^2.0.5",
"defined": "^1.0.0",
Expand All @@ -39,6 +40,7 @@
"minimist": "^1.2.5",
"object-inspect": "^1.12.0",
"object-is": "^1.1.5",
"object-keys": "^1.1.1",
"object.assign": "^4.1.2",
"resolve": "^2.0.0-next.3",
"resumer": "^0.0.0",
Expand Down

0 comments on commit dfc5f39

Please sign in to comment.