From 913275c88a88ef35f4d43438e71e137778e61d30 Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg Date: Wed, 28 Jan 2015 17:52:11 +0100 Subject: [PATCH 1/3] Increate test coverage for utils.js and logger.js --- src/utils.js | 3 +- test/data/expected.json | 141 +++++++++++++++++++++++++++++++++++---- test/env/logger.test.js | 31 +++++++++ test/utils/utils.test.js | 9 +++ 4 files changed, 170 insertions(+), 14 deletions(-) diff --git a/src/utils.js b/src/utils.js index bdbc7676..5ec59702 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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), }; diff --git a/test/data/expected.json b/test/data/expected.json index a3dd81f1..21433319 100644 --- a/test/data/expected.json +++ b/test/data/expected.json @@ -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 + } + } } ] }, @@ -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 + } + } } ] }, @@ -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 + } + } } ] }, @@ -387,6 +435,10 @@ "access": "private", "content": "", "require": [ + { + "type": "mixin", + "name": "mixin-specific-test" + }, { "type": "function", "name": "function-specific-test" @@ -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", @@ -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": [ @@ -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": [ diff --git a/test/env/logger.test.js b/test/env/logger.test.js index 23e68f23..e486db15 100644 --- a/test/env/logger.test.js +++ b/test/env/logger.test.js @@ -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'); @@ -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 () { @@ -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; }); diff --git a/test/utils/utils.test.js b/test/utils/utils.test.js index 82345bb5..2fd6d0e1 100644 --- a/test/utils/utils.test.js +++ b/test/utils/utils.test.js @@ -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()); + + }); + }); From 5e5bc2ca537d8961d0ed3e4b07a42b691e0a5a94 Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg Date: Wed, 28 Jan 2015 18:50:53 +0100 Subject: [PATCH 2/3] Revert to old utils.is.error --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 5ec59702..3a3c22c9 100644 --- a/src/utils.js +++ b/src/utils.js @@ -64,7 +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]', + error: arg => is.object(arg) && (toString(arg) === '[object Error]' || arg instanceof Error), promise: arg => arg && is.function(arg.then), stream: arg => arg && is.function(arg.pipe), }; From 4a5b44d6baf578a51fec2b0ec74180386ef83745 Mon Sep 17 00:00:00 2001 From: Fabrice Weinberg Date: Wed, 28 Jan 2015 18:51:06 +0100 Subject: [PATCH 3/3] Add some more tests for utils.is --- test/utils/utils.test.js | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/test/utils/utils.test.js b/test/utils/utils.test.js index 2fd6d0e1..72a79c93 100644 --- a/test/utils/utils.test.js +++ b/test/utils/utils.test.js @@ -6,6 +6,7 @@ var assert = require('assert'); var fs = require('fs'); var utils = require('../../dist/utils'); var readFile = utils.denodeify(fs.readFile); +var errors = require('../../dist/errors'); describe('#utils:denodeify', function () { @@ -32,12 +33,36 @@ describe('#utils:denodeify', function () { }); it('should provide utils.is.*', function () { - - assert.ok(utils.is.stream({ pipe : function(){}})); + // .stream + assert.equal(utils.is.stream({ pipe : function(){}}), true); assert.equal(utils.is.stream(), undefined); - - assert.ok(utils.is.undef()); - + // .undef + assert.equal(utils.is.undef(1), false); + assert.equal(utils.is.undef(), true); + // .error + assert.equal(utils.is.error(null), false); + assert.equal(utils.is.error(new errors.SassDocError()), true); + // .string + assert.equal(utils.is.string(), false); + // .function + assert.equal(utils.is['function'](), false); + assert.equal(utils.is['function'](function(){}), true); + // .object + assert.equal(utils.is.object(), false); + assert.equal(utils.is.object(1), false); + assert.equal(utils.is.object(''), false); + assert.equal(utils.is.object({}), true); + assert.equal(utils.is.object(new Error()), true); + // .plainObject + assert.equal(utils.is.plainObject(), false); + assert.equal(utils.is.plainObject(1), false); + assert.equal(utils.is.plainObject(new Error()), false); + assert.equal(utils.is.plainObject({}), true); + // .array + assert.equal(utils.is.array(), false); + assert.equal(utils.is.array(1), false); + assert.equal(utils.is.array(''), false); + assert.equal(utils.is.array([]), true); }); });