1 | var defaultReporter = require('./defaultReporter');
|
2 |
|
3 | module.exports.createAssertionWrapper = function (ok, notOk) {
|
4 | var assert = require('assert');
|
5 |
|
6 | var wrapper = {};
|
7 | Object.keys(assert).forEach(function (key) {
|
8 | if (key === 'AssertionError') return;
|
9 |
|
10 | wrapper[key] = function () {
|
11 | try {
|
12 | assert[key].apply(null, arguments);
|
13 | ok(getMessage(key, arguments));
|
14 | } catch (err) {
|
15 | notOk(err);
|
16 | }
|
17 | };
|
18 | });
|
19 |
|
20 | return wrapper;
|
21 | };
|
22 |
|
23 | function getMessage(name, args) {
|
24 | switch(name) {
|
25 | case 'ok':
|
26 | case 'ifError':
|
27 | return args[1];
|
28 |
|
29 | case 'throws':
|
30 | case 'doesNotThrow':
|
31 | return args[2] || (typeof args[1] === 'string' && args[1]);
|
32 |
|
33 | default:
|
34 | return args[2];
|
35 | }
|
36 | }
|
37 |
|
38 |
|
39 | module.exports.attachReporters = defaultReporter; |
\ | No newline at end of file |