-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added waitFor method * fixed README.md code example for waitFor method * Closes #153 by using the current global scope instead of window * Added universal test loader for nodeunit and mocha test suites; Updated dependencies; Fixed coverage script; Reworked repo scripts set; Added coveralls integration; Added travis build integration; Updated README.md badges; * Extended integration with assert module; * Added prepublishOnly & postversion scripts * Reduced required branches coverage to 75% * added return value from test function just in case * allowed to skip null tests * updated package description * Added keywords
- Loading branch information
1 parent
191e0ff
commit 9f8a837
Showing
4 changed files
with
121 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- "8" | ||
- "10" | ||
env: | ||
- NODE_ENV=TEST | ||
script: | ||
- npm run test:coverage | ||
after_success: npm run coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('assert'); | ||
|
||
function importTests(root, filter) { | ||
const tests = {}; | ||
|
||
function scanDir(currentDir, testEntry) { | ||
fs.readdirSync(currentDir).forEach(function (entry) { | ||
entry = path.resolve(currentDir, entry); | ||
const stats = fs.statSync(entry); | ||
const {name, ext} = path.parse(entry); | ||
const relativePath = path.relative(root, entry); | ||
if (filter && !filter(relativePath)) return; | ||
if (stats.isDirectory()) { | ||
return scanDir(entry, testEntry[name] || (testEntry[name] = {})); | ||
} | ||
ext === '.js' && (testEntry[name] = require(entry)); | ||
}); | ||
} | ||
|
||
scanDir(root, tests); | ||
|
||
function _import(tests) { | ||
Object.keys(tests).forEach(function (testName) { | ||
const test = tests[testName]; | ||
const type = typeof test; | ||
if (type === 'object') { | ||
if (!type) { | ||
return; | ||
} | ||
describe(testName, function () { | ||
_import(test); | ||
}) | ||
} else if (type === 'function') { | ||
const executor = function (done) { | ||
if (!done) { | ||
return test.call(this); | ||
} | ||
let count, expectedCount; | ||
|
||
function wrap(fn) { | ||
return function () { | ||
count++; | ||
return fn.apply(null, arguments); | ||
} | ||
} | ||
|
||
const testObj = Object.assign(function () { | ||
return done.apply(this, arguments); | ||
}, { | ||
done: function (err) { | ||
if (expectedCount !== undefined && count < expectedCount) { | ||
throw Error(`${count}/${expectedCount} assertions was done`); | ||
} | ||
err ? done(err) : done(); | ||
}, | ||
expect: function (count) { | ||
expectedCount = count; | ||
} | ||
}); | ||
Object.keys(assert).forEach(function(prop){ | ||
const value= assert[prop]; | ||
typeof value==='function' && (testObj[prop]= wrap(value)); | ||
}); | ||
return test.call(this, testObj); | ||
}; | ||
it(testName, test.length ? executor : function () { | ||
return executor.call(this, null); | ||
}) | ||
} else { | ||
throw TypeError('expected an object or function'); | ||
} | ||
}) | ||
} | ||
_import(tests); | ||
} | ||
|
||
importTests('./test', function (path) { | ||
return !~['common.js', 'perf', 'test-loader.js'].indexOf(path); | ||
}); |