From 6fcd7d62a752f8ecd5d64b6a718d431d8851b0a1 Mon Sep 17 00:00:00 2001 From: fent <933490+fent@users.noreply.github.com> Date: Wed, 4 Mar 2020 17:28:15 -0500 Subject: [PATCH 1/2] Fix async assert functions --- lib/index.js | 13 ++++++++++--- lib/index.js.map | 2 +- lib/index.mjs | 13 ++++++++++--- test/example-passing-tests.js | 24 ++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/lib/index.js b/lib/index.js index a6eb8cc..85ce22c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -119,9 +119,16 @@ function AssertDiff() { AssertDiff.options = {strict: false}; Object.keys(assert_plus__WEBPACK_IMPORTED_MODULE_0__).forEach(function(k) { - AssertDiff[k] = function() { - assert_plus__WEBPACK_IMPORTED_MODULE_0__[k].apply(assert_plus__WEBPACK_IMPORTED_MODULE_0__[k], arguments); - }; + let fun = assert_plus__WEBPACK_IMPORTED_MODULE_0__[k]; + if (fun.constructor.name === 'AsyncFunction') { + AssertDiff[k] = async function() { + return fun.apply(fun, arguments); + }; + } else { + AssertDiff[k] = function() { + fun.apply(fun, arguments); + }; + } }); const deepStrictEqual = AssertDiff.deepStrictEqual = function deepStrictEqual() { diff --git a/lib/index.js.map b/lib/index.js.map index 2a8a433..5e9872a 100644 --- a/lib/index.js.map +++ b/lib/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap","webpack:///./lib/index.mjs","webpack:///external \"assert-plus\"","webpack:///external \"json-diff\""],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(global, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./lib/index.mjs\");\n","import assert from 'assert-plus';\nimport jdiff from 'json-diff';\n\nfunction AssertDiff() {\n assert.ok.apply(assert.ok, arguments);\n}\n\nAssertDiff.options = {strict: false};\n\nObject.keys(assert).forEach(function(k) {\n AssertDiff[k] = function() {\n assert[k].apply(assert[k], arguments);\n };\n});\n\nexport const deepStrictEqual = AssertDiff.deepStrictEqual = function deepStrictEqual() {\n try {\n assert.deepStrictEqual.apply(assert.deepStrictEqual, arguments);\n } catch (e) {\n throw new assert.AssertionError({\n message: addDiffToMessage(e.message, jdiff.diffString(e.expected, e.actual)),\n stackStartFunction: assert.AssertionError\n })\n }\n};\n\nexport const deepEqual = AssertDiff.deepEqual = function deepEqual() {\n try {\n assert.deepEqual.apply(assert.deepEqual, arguments);\n } catch (e) {\n throw new assert.AssertionError({\n message: addDiffToMessage(e.message, jdiff.diffString(e.expected, e.actual)),\n stackStartFunction: assert.AssertionError\n })\n }\n if (AssertDiff.options.strict && jdiff.diff(arguments[0], arguments[1])) {\n throw new assert.AssertionError({\n message: addDiffToMessage(arguments[2], jdiff.diffString(arguments[0], arguments[1])),\n stackStartFunction: assert.AssertionError\n })\n }\n};\n\nfunction addDiffToMessage(message, diff) {\n var msg = message ? message : '';\n var resetCliColorAttributes = '\\u001b[m';\n\n return msg + resetCliColorAttributes + '\\n' + diff;\n}\n\nAssertDiff.deepEqualOrig = assert.deepEqual;\n\nexport default AssertDiff;\n","module.exports = require(\"assert-plus\");","module.exports = require(\"json-diff\");"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;AClFA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACpDA;;;;;;;;;;;ACAA;;;;;A","sourceRoot":""} \ No newline at end of file +{"version":3,"file":"index.js","sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap","webpack:///./lib/index.mjs","webpack:///external \"assert-plus\"","webpack:///external \"json-diff\""],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(global, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./lib/index.mjs\");\n","import assert from 'assert-plus';\nimport jdiff from 'json-diff';\n\nfunction AssertDiff() {\n assert.ok.apply(assert.ok, arguments);\n}\n\nAssertDiff.options = {strict: false};\n\nObject.keys(assert).forEach(function(k) {\n let fun = assert[k];\n if (fun.constructor.name === 'AsyncFunction') {\n AssertDiff[k] = async function() {\n return fun.apply(fun, arguments);\n };\n } else {\n AssertDiff[k] = function() {\n fun.apply(fun, arguments);\n };\n }\n});\n\nexport const deepStrictEqual = AssertDiff.deepStrictEqual = function deepStrictEqual() {\n try {\n assert.deepStrictEqual.apply(assert.deepStrictEqual, arguments);\n } catch (e) {\n throw new assert.AssertionError({\n message: addDiffToMessage(e.message, jdiff.diffString(e.expected, e.actual)),\n stackStartFunction: assert.AssertionError\n })\n }\n};\n\nexport const deepEqual = AssertDiff.deepEqual = function deepEqual() {\n try {\n assert.deepEqual.apply(assert.deepEqual, arguments);\n } catch (e) {\n throw new assert.AssertionError({\n message: addDiffToMessage(e.message, jdiff.diffString(e.expected, e.actual)),\n stackStartFunction: assert.AssertionError\n })\n }\n if (AssertDiff.options.strict && jdiff.diff(arguments[0], arguments[1])) {\n throw new assert.AssertionError({\n message: addDiffToMessage(arguments[2], jdiff.diffString(arguments[0], arguments[1])),\n stackStartFunction: assert.AssertionError\n })\n }\n};\n\nfunction addDiffToMessage(message, diff) {\n var msg = message ? message : '';\n var resetCliColorAttributes = '\\u001b[m';\n\n return msg + resetCliColorAttributes + '\\n' + diff;\n}\n\nAssertDiff.deepEqualOrig = assert.deepEqual;\n\nexport default AssertDiff;\n","module.exports = require(\"assert-plus\");","module.exports = require(\"json-diff\");"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;AClFA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC3DA;;;;;;;;;;;ACAA;;;;;A","sourceRoot":""} \ No newline at end of file diff --git a/lib/index.mjs b/lib/index.mjs index 14d128a..c5ee7e0 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -8,9 +8,16 @@ function AssertDiff() { AssertDiff.options = {strict: false}; Object.keys(assert).forEach(function(k) { - AssertDiff[k] = function() { - assert[k].apply(assert[k], arguments); - }; + let fun = assert[k]; + if (fun.constructor.name === 'AsyncFunction') { + AssertDiff[k] = async function() { + return fun.apply(fun, arguments); + }; + } else { + AssertDiff[k] = function() { + fun.apply(fun, arguments); + }; + } }); export const deepStrictEqual = AssertDiff.deepStrictEqual = function deepStrictEqual() { diff --git a/test/example-passing-tests.js b/test/example-passing-tests.js index f32db20..0fa9ee7 100644 --- a/test/example-passing-tests.js +++ b/test/example-passing-tests.js @@ -38,3 +38,27 @@ it('basic derived asserts works', function() { assert.equal(3, 3, 'this should not fail') assert.object({}, 'this should not fail'); }) + +it('async functions', async function() { + let a = false; + await assert.doesNotReject(function() { + return new Promise(function(resolve, reject) { + setTimeout(function() { + a = true; + resolve(); + }) + }) + }) + assert.ok(a); + + let b = false; + await assert.rejects(async function() { + return new Promise(function(resolve, reject) { + setTimeout(function() { + b = true; + reject(Error('bad error')) + }) + }) + }); + assert.ok(b); +}) From 64744e8527df9df76a4e3839fc661e1d99a8180d Mon Sep 17 00:00:00 2001 From: fent <933490+fent@users.noreply.github.com> Date: Wed, 4 Mar 2020 17:48:19 -0500 Subject: [PATCH 2/2] Fix for promises too --- lib/index.js | 12 +++--------- lib/index.js.map | 2 +- lib/index.mjs | 12 +++--------- test/example-passing-tests.js | 9 +++++++++ 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/index.js b/lib/index.js index 85ce22c..adec4fe 100644 --- a/lib/index.js +++ b/lib/index.js @@ -120,15 +120,9 @@ AssertDiff.options = {strict: false}; Object.keys(assert_plus__WEBPACK_IMPORTED_MODULE_0__).forEach(function(k) { let fun = assert_plus__WEBPACK_IMPORTED_MODULE_0__[k]; - if (fun.constructor.name === 'AsyncFunction') { - AssertDiff[k] = async function() { - return fun.apply(fun, arguments); - }; - } else { - AssertDiff[k] = function() { - fun.apply(fun, arguments); - }; - } + AssertDiff[k] = async function() { + return fun.apply(fun, arguments); + }; }); const deepStrictEqual = AssertDiff.deepStrictEqual = function deepStrictEqual() { diff --git a/lib/index.js.map b/lib/index.js.map index 5e9872a..35c0dea 100644 --- a/lib/index.js.map +++ b/lib/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap","webpack:///./lib/index.mjs","webpack:///external \"assert-plus\"","webpack:///external \"json-diff\""],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(global, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./lib/index.mjs\");\n","import assert from 'assert-plus';\nimport jdiff from 'json-diff';\n\nfunction AssertDiff() {\n assert.ok.apply(assert.ok, arguments);\n}\n\nAssertDiff.options = {strict: false};\n\nObject.keys(assert).forEach(function(k) {\n let fun = assert[k];\n if (fun.constructor.name === 'AsyncFunction') {\n AssertDiff[k] = async function() {\n return fun.apply(fun, arguments);\n };\n } else {\n AssertDiff[k] = function() {\n fun.apply(fun, arguments);\n };\n }\n});\n\nexport const deepStrictEqual = AssertDiff.deepStrictEqual = function deepStrictEqual() {\n try {\n assert.deepStrictEqual.apply(assert.deepStrictEqual, arguments);\n } catch (e) {\n throw new assert.AssertionError({\n message: addDiffToMessage(e.message, jdiff.diffString(e.expected, e.actual)),\n stackStartFunction: assert.AssertionError\n })\n }\n};\n\nexport const deepEqual = AssertDiff.deepEqual = function deepEqual() {\n try {\n assert.deepEqual.apply(assert.deepEqual, arguments);\n } catch (e) {\n throw new assert.AssertionError({\n message: addDiffToMessage(e.message, jdiff.diffString(e.expected, e.actual)),\n stackStartFunction: assert.AssertionError\n })\n }\n if (AssertDiff.options.strict && jdiff.diff(arguments[0], arguments[1])) {\n throw new assert.AssertionError({\n message: addDiffToMessage(arguments[2], jdiff.diffString(arguments[0], arguments[1])),\n stackStartFunction: assert.AssertionError\n })\n }\n};\n\nfunction addDiffToMessage(message, diff) {\n var msg = message ? message : '';\n var resetCliColorAttributes = '\\u001b[m';\n\n return msg + resetCliColorAttributes + '\\n' + diff;\n}\n\nAssertDiff.deepEqualOrig = assert.deepEqual;\n\nexport default AssertDiff;\n","module.exports = require(\"assert-plus\");","module.exports = require(\"json-diff\");"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;AClFA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC3DA;;;;;;;;;;;ACAA;;;;;A","sourceRoot":""} \ No newline at end of file +{"version":3,"file":"index.js","sources":["webpack:///webpack/universalModuleDefinition","webpack:///webpack/bootstrap","webpack:///./lib/index.mjs","webpack:///external \"assert-plus\"","webpack:///external \"json-diff\""],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse {\n\t\tvar a = factory();\n\t\tfor(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];\n\t}\n})(global, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./lib/index.mjs\");\n","import assert from 'assert-plus';\nimport jdiff from 'json-diff';\n\nfunction AssertDiff() {\n assert.ok.apply(assert.ok, arguments);\n}\n\nAssertDiff.options = {strict: false};\n\nObject.keys(assert).forEach(function(k) {\n let fun = assert[k];\n AssertDiff[k] = async function() {\n return fun.apply(fun, arguments);\n };\n});\n\nexport const deepStrictEqual = AssertDiff.deepStrictEqual = function deepStrictEqual() {\n try {\n assert.deepStrictEqual.apply(assert.deepStrictEqual, arguments);\n } catch (e) {\n throw new assert.AssertionError({\n message: addDiffToMessage(e.message, jdiff.diffString(e.expected, e.actual)),\n stackStartFunction: assert.AssertionError\n })\n }\n};\n\nexport const deepEqual = AssertDiff.deepEqual = function deepEqual() {\n try {\n assert.deepEqual.apply(assert.deepEqual, arguments);\n } catch (e) {\n throw new assert.AssertionError({\n message: addDiffToMessage(e.message, jdiff.diffString(e.expected, e.actual)),\n stackStartFunction: assert.AssertionError\n })\n }\n if (AssertDiff.options.strict && jdiff.diff(arguments[0], arguments[1])) {\n throw new assert.AssertionError({\n message: addDiffToMessage(arguments[2], jdiff.diffString(arguments[0], arguments[1])),\n stackStartFunction: assert.AssertionError\n })\n }\n};\n\nfunction addDiffToMessage(message, diff) {\n var msg = message ? message : '';\n var resetCliColorAttributes = '\\u001b[m';\n\n return msg + resetCliColorAttributes + '\\n' + diff;\n}\n\nAssertDiff.deepEqualOrig = assert.deepEqual;\n\nexport default AssertDiff;\n","module.exports = require(\"assert-plus\");","module.exports = require(\"json-diff\");"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;ACVA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;AClFA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACrDA;;;;;;;;;;;ACAA;;;;;A","sourceRoot":""} \ No newline at end of file diff --git a/lib/index.mjs b/lib/index.mjs index c5ee7e0..28c7465 100644 --- a/lib/index.mjs +++ b/lib/index.mjs @@ -9,15 +9,9 @@ AssertDiff.options = {strict: false}; Object.keys(assert).forEach(function(k) { let fun = assert[k]; - if (fun.constructor.name === 'AsyncFunction') { - AssertDiff[k] = async function() { - return fun.apply(fun, arguments); - }; - } else { - AssertDiff[k] = function() { - fun.apply(fun, arguments); - }; - } + AssertDiff[k] = async function() { + return fun.apply(fun, arguments); + }; }); export const deepStrictEqual = AssertDiff.deepStrictEqual = function deepStrictEqual() { diff --git a/test/example-passing-tests.js b/test/example-passing-tests.js index 0fa9ee7..d5552e9 100644 --- a/test/example-passing-tests.js +++ b/test/example-passing-tests.js @@ -61,4 +61,13 @@ it('async functions', async function() { }) }); assert.ok(b); + + let c = false; + await assert.rejects(new Promise(function(resolve, reject) { + setTimeout(function() { + c = true; + reject(Error('bad error')) + }) + })) + assert.ok(c); })