Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

allow trigger error, for better async test #205

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,26 @@
}
}

/**
* Trigger error for deferred benchmark.
*
* @memberOf Benchmark.Deferred
* @param {Error} [err]
*/
function reject(err) {
// make sure error not a void like value
var error = err || new Error(err);
error.originError = err;

var deferred = this,
clone = deferred.benchmark,
bench = clone._original;

var event = Event('error');
clone.error = event.message = error;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not weird to set the error object as both error and message? Why not just the event.error? Or you could set error.message to event.message.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I agree.

clone.emit(event);
}

/*------------------------------------------------------------------------*/

/**
Expand Down Expand Up @@ -2608,7 +2628,8 @@
});

_.assign(Deferred.prototype, {
'resolve': resolve
'resolve': resolve,
'reject': reject
});

/*------------------------------------------------------------------------*/
Expand Down
37 changes: 26 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
{
"name": "benchmark",
"name": "benchmark2",
"version": "2.1.4",
"description": "A benchmarking library that supports high-resolution timers & returns statistically significant results.",
"keywords": [
"benchmark",
"performance",
"speed"
],
"homepage": "https://benchmarkjs.com/",
"bugs": {
"url": "https://github.com/bluelovers/benchmark.js/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/bluelovers/benchmark.js.git"
},
"license": "MIT",
"main": "benchmark.js",
"keywords": "benchmark, performance, speed",
"author": "Mathias Bynens <[email protected]>",
"contributors": [
"Mathias Bynens <[email protected]>",
"John-David Dalton <[email protected]>",
"Kit Cambridge <[email protected]>"
],
"repository": "bestiejs/benchmark.js",
"files": [
"benchmark.js"
],
"main": "benchmark.js",
"directories": {
"doc": "doc",
"example": "example",
"test": "test"
},
"scripts": {
"doc": "docdown benchmark.js doc/README.md style=github title=\"<a href=\\\"https://benchmarkjs.com/\\\">Benchmark.js</a> <span>v${npm_package_version}</span>\" toc=categories url=https://github.com/bestiejs/benchmark.js/blob/${npm_package_version}/benchmark.js",
"test": "node test/test"
},
"dependencies": {
"lodash": "^4.17.10",
"lodash": "^4.17.11",
"platform": "^1.3.5"
},
"devDependencies": {
"coveralls": "^3.0.1",
"coveralls": "^3.0.2",
"docdown": "^0.7.3",
"istanbul": "0.4.5",
"qunit-extras": "^3.0.0",
"qunitjs": "^2.4.1",
"requirejs": "^2.3.5"
},
"files": [
"benchmark.js"
]
"requirejs": "^2.3.6"
}
}