Skip to content

Commit

Permalink
Increate test coverage for utils.js and logger.js
Browse files Browse the repository at this point in the history
  • Loading branch information
FWeinb committed Jan 28, 2015
1 parent f1bf3dd commit 913275c
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ export const is = {
object: arg => typeof arg === 'object' && arg !== null,
plainObject: arg => toString(arg) === '[object Object]',
array: arg => Array.isArray(arg),
error: arg => is.object(arg) &&
(toString(arg) === '[object Error]' || arg instanceof Error),
error: arg => is.object(arg) && toString(arg) === '[object Error]',
promise: arg => arg && is.function(arg.then),
stream: arg => arg && is.function(arg.pipe),
};
141 changes: 129 additions & 12 deletions test/data/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@
"end": 134
}
}
},
{
"description": "This is a test that autofill can be overwritten.\n",
"context": {
"type": "mixin",
"name": "autofill-test-handwritten",
"code": "\n $call: function-specific-test();\n $use: $variable-specific-test;\n @include mixin-specific-test;\n",
"line": {
"start": 143,
"end": 147
}
}
}
]
},
Expand Down Expand Up @@ -244,6 +256,30 @@
"end": 60
}
}
},
{
"description": "This is a test aiming at testing:\n- autofilled `@requires`\n- autofilled `@error`\n- autofilled `@content`\n",
"context": {
"type": "mixin",
"name": "autofill-test",
"code": "\n $call: function-specific-test();\n $use: $variable-specific-test;\n @include mixin-specific-test;\n @extend %placeholder-specific-test;\n\n @content;\n\n @include autofill-test();\n @error \"This is an autofilled error\";\n",
"line": {
"start": 124,
"end": 134
}
}
},
{
"description": "This is a test that autofill can be overwritten.\n",
"context": {
"type": "mixin",
"name": "autofill-test-handwritten",
"code": "\n $call: function-specific-test();\n $use: $variable-specific-test;\n @include mixin-specific-test;\n",
"line": {
"start": 143,
"end": 147
}
}
}
]
},
Expand Down Expand Up @@ -310,6 +346,18 @@
"end": 134
}
}
},
{
"description": "This is a test that autofill can be overwritten.\n",
"context": {
"type": "mixin",
"name": "autofill-test-handwritten",
"code": "\n $call: function-specific-test();\n $use: $variable-specific-test;\n @include mixin-specific-test;\n",
"line": {
"start": 143,
"end": 147
}
}
}
]
},
Expand Down Expand Up @@ -387,6 +435,10 @@
"access": "private",
"content": "",
"require": [
{
"type": "mixin",
"name": "mixin-specific-test"
},
{
"type": "function",
"name": "function-specific-test"
Expand All @@ -409,18 +461,83 @@
}
},
{
"description": "This is a test function aiming at testing:\n- `@alias`\n\n",
"description": "This is a test that autofill can be overwritten.\n",
"commentRange": {
"start": 138,
"start": 139,
"end": 141
},
"context": {
"type": "mixin",
"name": "autofill-test-handwritten",
"code": "\n $call: function-specific-test();\n $use: $variable-specific-test;\n @include mixin-specific-test;\n",
"line": {
"start": 143,
"end": 147
}
},
"require": [
{
"type": "variable",
"name": "variable-specific-test"
},
{
"type": "function",
"name": "function-specific-test",
"external": false
},
{
"type": "mixin",
"name": "mixin-specific-test",
"external": false
}
],
"group": [
"test"
],
"access": "private",
"file": {
"path": "test.scss",
"name": "test.scss"
}
},
{
"description": "This is a test that autofill should report not found\n",
"commentRange": {
"start": 149,
"end": 150
},
"context": {
"type": "mixin",
"name": "autofill-test-not-found",
"code": "\n",
"line": {
"start": 151,
"end": 152
}
},
"require": [],
"group": [
"test"
],
"access": "private",
"file": {
"path": "test.scss",
"name": "test.scss"
}
},
{
"description": "This is a test function aiming at testing:\n- `@alias`\n\n",
"commentRange": {
"start": 156,
"end": 159
},
"context": {
"type": "function",
"name": "alias-test",
"code": "",
"line": {
"start": 143,
"end": 143
"start": 161,
"end": 161
}
},
"alias": "alias-test-aliased",
Expand All @@ -436,16 +553,16 @@
{
"description": "This is a test function aiming at testing:\n- `@alias`\n",
"commentRange": {
"start": 145,
"end": 146
"start": 163,
"end": 164
},
"context": {
"type": "function",
"name": "alias-test-aliased",
"code": "",
"line": {
"start": 148,
"end": 148
"start": 166,
"end": 166
}
},
"group": [
Expand All @@ -463,16 +580,16 @@
{
"description": "This is a test function aiming at testing:\n- `@alias`\n\n",
"commentRange": {
"start": 150,
"end": 153
"start": 168,
"end": 171
},
"context": {
"type": "function",
"name": "alias-test-should-warn",
"code": "",
"line": {
"start": 155,
"end": 155
"start": 173,
"end": 173
}
},
"group": [
Expand Down
31 changes: 31 additions & 0 deletions test/env/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ describe('#logger', function () {
logger.debug('foo');
logger.debug('foo', 'bar');
logger.debug('%s %s', 'foo', 'bar', 'hop');
logger.debug(function(){return 'foo bar hop hop';});

// test logger.info()
logger.info('foo');
logger.info('foo', 'bar');
logger.info('%s %s', 'foo', 'bar', 'hop');

// test logger.timeEnd()
logger.time('label');
Expand Down Expand Up @@ -83,6 +89,13 @@ describe('#logger', function () {
assert.equal(debug('foo'), strings.shift());
assert.equal(debug('foo bar'), strings.shift());
assert.equal(debug('foo bar hop'), strings.shift());
assert.equal(debug('foo bar hop hop'), strings.shift());
});

it('should properly `info` with a grey chevron', function () {
assert.equal(log('foo'), strings.shift());
assert.equal(log('foo bar'), strings.shift());
assert.equal(log('foo bar hop'), strings.shift());
});

it('should properly `timeEnd` with default message', function () {
Expand Down Expand Up @@ -110,6 +123,24 @@ describe('#logger', function () {
});
});

it('should have a empty logger', function () {
assert.deepEqual(Logger.empty.log(), undefined);
assert.deepEqual(Logger.empty.warn(), undefined);
assert.deepEqual(Logger.empty.error(), undefined);
assert.deepEqual(Logger.empty.debug(), undefined);
});

it('should have a function to check if a object is a logger', function () {
assert.ok(Logger.checkLogger(Logger.empty));
assert.throws(function () {
Logger.checkLogger({ log : function() {} });
});
assert.throws(function () {
Logger.checkLogger({ log : function() {}, warn : function(){} });
});
assert.ok(Logger.checkLogger({ log : function() {}, warn : function(){}, error : function(){} }));
});

after(function () {
global.process.stderr.write = stderrWrite;
});
Expand Down
9 changes: 9 additions & 0 deletions test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@ describe('#utils:denodeify', function () {
});
});

it('should provide utils.is.*', function () {

assert.ok(utils.is.stream({ pipe : function(){}}));
assert.equal(utils.is.stream(), undefined);

assert.ok(utils.is.undef());

});

});

0 comments on commit 913275c

Please sign in to comment.