Skip to content

Commit

Permalink
refactor(test): Use co-mocha for async tests
Browse files Browse the repository at this point in the history
This improves error handling within tests so that they shouldn't time out when an assertion fails from within a callback. Server instances created within tests are also closed in finally blocks to avoid making Mocha hanging at the end.

This also greatly improves the performance of bulk generation of objects by allowing 100 concurrent uploads at a time. The indefinite timeout on these long-running tests has been removed.
  • Loading branch information
kherock committed Mar 13, 2018
1 parent 1c65504 commit fc7a12f
Show file tree
Hide file tree
Showing 4 changed files with 1,122 additions and 1,403 deletions.
9 changes: 9 additions & 0 deletions lib/utils.js
Expand Up @@ -90,3 +90,12 @@ exports.concatStreams = function(streams) {
pipeNext(streams.shift());
return passThrough;
};

exports.thunkToPromise = function(fn) {
return new Promise((resolve, reject) => {
fn((err, ...args) => {
if (err) return reject(err);
resolve(args.length > 1 ? args : args[0]);
});
});
};
8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -4,7 +4,7 @@
"description": "Fake S3 server for node",
"main": "lib/index.js",
"scripts": {
"test": "mocha --timeout 30000 --reporter spec --ui bdd",
"test": "mocha --require co-mocha --timeout 30000 --reporter spec --ui bdd",
"prettier-check": "prettier-check --ignore-path .gitignore \"**/*.js\"",
"prettier-fix": "prettier --ignore-path .gitignore --write \"**/*.js\"",
"eslint": "eslint --ignore-path .gitignore \"**/*.js\"",
Expand Down Expand Up @@ -36,6 +36,7 @@
"jstoxml": "^1.0.0",
"lodash": "^4.0.0",
"morgan": "^1.5.1",
"promise-limit": "^2.6.0",
"rxjs": "^5.4.0",
"winston": "^2.1.0",
"xml2js": "^0.4.4",
Expand All @@ -44,14 +45,17 @@
"devDependencies": {
"aws-sdk": "2.208.0",
"chai": "4.1.2",
"chai-as-promised": "7.1.1",
"co-mocha": "1.2.2",
"eslint": "4.18.2",
"eslint-config-prettier": "2.9.0",
"md5": "2.2.1",
"mocha": "5.0.4",
"moment": "2.21.0",
"prettier": "1.11.1",
"prettier-check": "2.0.0",
"request": "2.85.0"
"request": "2.85.0",
"request-promise-native": "1.0.5"
},
"engines": {
"node": ">=6.0.0"
Expand Down
File renamed without changes

0 comments on commit fc7a12f

Please sign in to comment.