[Pkg-javascript-commits] [node-stack-utils] 03/67: 100% test coverage on clean method.

Bastien Roucariès rouca at moszumanska.debian.org
Thu Sep 7 09:53:01 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-stack-utils.

commit 474777da6fa0f5282fd1b3e3ee8b22af8eee9da3
Author: James Talmage <james at talmage.io>
Date:   Sun Jan 3 18:39:49 2016 -0500

    100% test coverage on clean method.
---
 package.json |  1 +
 test.js      | 85 +++++++++++++++++++++++++++++++++++++-----------------------
 2 files changed, 54 insertions(+), 32 deletions(-)

diff --git a/package.json b/package.json
index 1da558b..259566f 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
   "dependencies": {},
   "devDependencies": {
     "ava": "^0.8.0",
+    "flatten": "0.0.1",
     "nyc": "^5.2.0",
     "xo": "^0.12.1"
   }
diff --git a/test.js b/test.js
index cc033c9..55fdfc6 100644
--- a/test.js
+++ b/test.js
@@ -1,37 +1,15 @@
 import test from 'ava';
 import StackUtils from './';
+import flatten from 'flatten';
 
-function join(stack) {
-	return stack.join('\n') + '\n';
-}
-
-const LinuxStack1 = join([
-	'Error: foo',
-	'    at foo (/user/dev/project/foo.js:3:8)',
-	'    at bar (/user/dev/project/foo.js:7:2)',
-	'    at bar (/user/dev/project/bar.js:4:2)',
-	'    at Object.<anonymous> (/user/dev/project/bar.js:7:1)',
-	'    at Module._compile (module.js:398:26)',
-	'    at Object.Module._extensions..js (module.js:405:10)',
-	'    at Module.load (module.js:344:32)',
-	'    at Function.Module._load (module.js:301:12)',
-	'    at Function.Module.runMain (module.js:430:10)',
-	'    at startup (node.js:141:18)'
-]);
+const LinuxStack1 = join(linux1(), internals());
+const WindowsStack1 = join(windows1(), internals());
 
-const WindowsStack1 = join([
-	'Error: foo',
-	'    at foo (Z:\\user\\dev\\project\\foo.js:3:8)',
-	'    at bar (Z:\\user\\dev\\project\\foo.js:7:2)',
-	'    at bar (Z:\\user\\dev\\project\\bar.js:4:2)',
-	'    at Object.<anonymous> (Z:\\user\\dev\\project\\bar.js:7:1)',
-	'    at Module._compile (module.js:398:26)',
-	'    at Object.Module._extensions..js (module.js:405:10)',
-	'    at Module.load (module.js:344:32)',
-	'    at Function.Module._load (module.js:301:12)',
-	'    at Function.Module.runMain (module.js:430:10)',
-	'    at startup (node.js:141:18)'
-]);
+test('must be called with new', t => {
+	t.is(typeof StackUtils, 'function');
+	const stackUtils = StackUtils;
+	t.throws(() => stackUtils());
+});
 
 test('clean: truncates cwd', t => {
 	const expected = join([
@@ -48,10 +26,12 @@ test('clean: truncates cwd', t => {
 	]);
 
 	let stack = new StackUtils({cwd: '/user/dev/project'});
-	t.is(stack.clean(LinuxStack1), expected);
+	t.is(stack.clean(LinuxStack1), expected, 'accepts a linux string');
+	t.is(stack.clean(LinuxStack1.split('\n')), expected, 'accepts an array');
+	t.is(stack.clean(LinuxStack1.split('\n').slice(1)), expected, 'slices off the message line');
 
 	stack = new StackUtils({cwd: 'Z:\\user\\dev\\project'});
-	t.is(stack.clean(WindowsStack1), expected);
+	t.is(stack.clean(WindowsStack1), expected, 'accepts a windows string');
 });
 
 test('clean: eliminates internals', t => {
@@ -72,3 +52,44 @@ test('clean: eliminates internals', t => {
 	]));
 });
 
+test('clean: returns null if it is all internals', t => {
+	let stack = new StackUtils({internals: StackUtils.nodeInternals()});
+	t.is(stack.clean(join(internals())), null);
+});
+
+function join() {
+	var args = Array.prototype.slice.call(arguments);
+	return flatten(args).join('\n') + '\n';
+}
+
+function linux1() {
+	return [
+		'Error: foo',
+		'    at foo (/user/dev/project/foo.js:3:8)',
+		'    at bar (/user/dev/project/foo.js:7:2)',
+		'    at bar (/user/dev/project/bar.js:4:2)',
+		'    at Object.<anonymous> (/user/dev/project/bar.js:7:1)'
+	];
+}
+
+function windows1() {
+	return [
+		'Error: foo',
+		'    at foo (Z:\\user\\dev\\project\\foo.js:3:8)',
+		'    at bar (Z:\\user\\dev\\project\\foo.js:7:2)',
+		'    at bar (Z:\\user\\dev\\project\\bar.js:4:2)',
+		'    at Object.<anonymous> (Z:\\user\\dev\\project\\bar.js:7:1)'
+	];
+}
+
+function internals() {
+	return [
+		'    at Module._compile (module.js:398:26)',
+		'    at Object.Module._extensions..js (module.js:405:10)',
+		'    at Module.load (module.js:344:32)',
+		'    at Function.Module._load (module.js:301:12)',
+		'    at Function.Module.runMain (module.js:430:10)',
+		'    at startup (node.js:141:18)'
+	];
+}
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-stack-utils.git



More information about the Pkg-javascript-commits mailing list