[Pkg-javascript-commits] [node-wrap-ansi] 04/04: add tests

Paolo Greppi paolog-guest at moszumanska.debian.org
Sat Nov 26 00:20:28 UTC 2016


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

paolog-guest pushed a commit to branch master
in repository node-wrap-ansi.

commit 7b2bd2d5b88605e035adb131edb0fec670699763
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date:   Sat Nov 26 00:11:36 2016 +0000

    add tests
    
    - Add a patch to use mocha as test runner rather than ava and to skip
      the xo style linter test step and the nyc (istanbul) coverage test.
    
    - add mocha, node-chalk, node-string-width and node-has-ansi build
      dependencies (required for testing)
    
    - override_dh_auto_test to run tests during packaging
    
    - enable autopkgtest
---
 debian/changelog             |   5 +-
 debian/control               |   4 ++
 debian/patches/00-mocha.diff | 144 +++++++++++++++++++++++++++++++++++++++++++
 debian/patches/series        |   1 +
 debian/rules                 |   6 +-
 debian/tests/control         |   3 +
 package.json                 |   3 +-
 test.js                      |  64 ++++++++-----------
 8 files changed, 184 insertions(+), 46 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index d1262d2..22da4e8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,8 @@
 node-wrap-ansi (2.0.0-1) UNRELEASED; urgency=low
 
   * Initial release (Closes: #845262)
+  * Add a patch to use mocha as test runner rather than ava and to
+    skip the xo style linter test step and the nyc (istanbul) coverage
+    test.
 
- -- Paolo Greppi <paolo.greppi at libpf.com>  Wed, 23 Nov 2016 13:14:41 +0000
+ -- Paolo Greppi <paolo.greppi at libpf.com>  Sat, 26 Nov 2016 00:06:08 +0000
diff --git a/debian/control b/debian/control
index 7af064c..5492408 100644
--- a/debian/control
+++ b/debian/control
@@ -7,6 +7,10 @@ Build-Depends:
  debhelper (>= 9)
  , dh-buildinfo
  , nodejs
+ , mocha
+ , node-chalk
+ , node-has-ansi,
+ , node-string-width
 Standards-Version: 3.9.8
 Homepage: https://github.com/chalk/wrap-ansi#readme
 Vcs-Git: https://anonscm.debian.org/git/pkg-javascript/node-wrap-ansi.git
diff --git a/debian/patches/00-mocha.diff b/debian/patches/00-mocha.diff
new file mode 100644
index 0000000..50433a5
--- /dev/null
+++ b/debian/patches/00-mocha.diff
@@ -0,0 +1,144 @@
+Description: Change from ava to mocha as test runner (ava is not yet
+ available as a Debian package). Skip the xo style linter test step
+ (xo is not available as a Debian package). Skip coverage test (nyc is
+ not available as a Debian package).
+Forwarded: not-needed
+Author: Paolo Greppi <paolo.greppi at libpf.com>
+
+Index: node-wrap-ansi/package.json
+===================================================================
+--- node-wrap-ansi.orig/package.json
++++ node-wrap-ansi/package.json
+@@ -19,8 +19,7 @@
+     "node": ">=0.10.0"
+   },
+   "scripts": {
+-    "test": "xo && nyc node test.js",
+-    "coverage": "nyc --reporter=text-lcov node test.js | coveralls"
++    "test": "mocha -u tdd"
+   },
+   "files": [
+     "index.js"
+Index: node-wrap-ansi/test.js
+===================================================================
+--- node-wrap-ansi.orig/test.js
++++ node-wrap-ansi/test.js
+@@ -1,5 +1,5 @@
+ 'use strict';
+-var test = require('ava');
++var assert = require('assert');
+ var chalk = require('chalk');
+ var hasAnsi = require('has-ansi');
+ var stripAnsi = require('strip-ansi');
+@@ -10,87 +10,73 @@ var fn = require('./');
+ var fixture = 'The quick brown ' + chalk.red('fox jumped over ') + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
+ var fixture2 = '12345678\n901234567890';
+ 
+-test('wraps string at 20 characters', function (t) {
++test('wraps string at 20 characters', function () {
+ 	var res20 = fn(fixture, 20);
+ 
+-	t.assert(res20 === 'The quick brown \u001b[31mfox\u001b[39m\n\u001b[31mjumped over \u001b[39mthe lazy\n\u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the\u001b[39m\n\u001b[32municorn.\u001b[39m');
+-	t.assert(stripAnsi(res20).split('\n').every(function (x) {
++	assert(res20 === 'The quick brown \u001b[31mfox\u001b[39m\n\u001b[31mjumped over \u001b[39mthe lazy\n\u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the\u001b[39m\n\u001b[32municorn.\u001b[39m');
++	assert(stripAnsi(res20).split('\n').every(function (x) {
+ 		return x.length <= 20;
+ 	}));
+-
+-	t.end();
+ });
+ 
+-test('wraps string at 30 characters', function (t) {
++test('wraps string at 30 characters', function () {
+ 	var res30 = fn(fixture, 30);
+ 
+-	t.assert(res30 === 'The quick brown \u001b[31mfox jumped\u001b[39m\n\u001b[31mover \u001b[39mthe lazy \u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the unicorn.\u001b[39m');
+-	t.assert(stripAnsi(res30).split('\n').every(function (x) {
++	assert(res30 === 'The quick brown \u001b[31mfox jumped\u001b[39m\n\u001b[31mover \u001b[39mthe lazy \u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the unicorn.\u001b[39m');
++	assert(stripAnsi(res30).split('\n').every(function (x) {
+ 		return x.length <= 30;
+ 	}));
+-
+-	t.end();
+ });
+ 
+-test('does not break strings longer than "cols" characters', function (t) {
++test('does not break strings longer than "cols" characters', function () {
+ 	var res5 = fn(fixture, 5, {hard: false});
+ 
+-	t.assert(res5 === 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumped\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32municorn.\u001b[39m');
+-	t.assert(
++	assert(res5 === 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumped\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32municorn.\u001b[39m');
++	assert(
+ 		stripAnsi(res5).split('\n').filter(function (x) {
+ 			return x.length > 5;
+ 		}).length > 0
+ 	);
+-
+-	t.end();
+ });
+ 
+-test('handles colored string that wraps on to multiple lines', function (t) {
++test('handles colored string that wraps on to multiple lines', function () {
+ 	var res = fn(chalk.green('hello world') + ' hey!', 5, {hard: false});
+ 	var lines = res.split('\n');
+-	t.assert(hasAnsi(lines[0]));
+-	t.assert(hasAnsi(lines[1]));
+-	t.assert(hasAnsi(lines[2]) === false);
+-	t.end();
++	assert(hasAnsi(lines[0]));
++	assert(hasAnsi(lines[1]));
++	assert(hasAnsi(lines[2]) === false);
+ });
+ 
+-test('does not prepend newline if first string is greater than "cols"', function (t) {
++test('does not prepend newline if first string is greater than "cols"', function () {
+ 	var res = fn(chalk.green('hello') + '-world', 5, {hard: false});
+-	t.assert(res.split('\n').length === 1);
+-	t.end();
++	assert(res.split('\n').length === 1);
+ });
+ 
+ // when "hard" is true
+ 
+-test('breaks strings longer than "cols" characters', function (t) {
++test('breaks strings longer than "cols" characters', function () {
+ 	var res5 = fn(fixture, 5, {hard: true});
+ 
+-	t.assert(res5 === 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumpe\u001b[39m\n\u001b[31md\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32munico\u001b[39m\n\u001b[32mrn.\u001b[39m');
+-	t.assert(stripAnsi(res5).split('\n').every(function (x) {
++	assert(res5 === 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumpe\u001b[39m\n\u001b[31md\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32munico\u001b[39m\n\u001b[32mrn.\u001b[39m');
++	assert(stripAnsi(res5).split('\n').every(function (x) {
+ 		return x.length <= 5;
+ 	}));
+-
+-	t.end();
+ });
+ 
+-test('removes last row if it contained only ansi escape codes', function (t) {
++test('removes last row if it contained only ansi escape codes', function () {
+ 	var res = fn(chalk.green('helloworld'), 2, {hard: true});
+ 
+-	t.assert(stripAnsi(res).split('\n').every(function (x) {
++	assert(stripAnsi(res).split('\n').every(function (x) {
+ 		return x.length === 2;
+ 	}));
+-
+-	t.end();
+ });
+ 
+-test('does not prepend newline if first word is split', function (t) {
++test('does not prepend newline if first word is split', function () {
+ 	var res = fn(chalk.green('hello') + 'world', 5, {hard: true});
+-	t.assert(res.split('\n').length === 2);
+-	t.end();
++	assert(res.split('\n').length === 2);
+ });
+ 
+-test('takes into account line returns inside input', function (t) {
++test('takes into account line returns inside input', function () {
+ 	var res20 = fn(fixture2, 10, {hard: true});
+-	t.assert(res20 === '12345678\n9012345678\n90');
+-	t.end();
++	assert(res20 === '12345678\n9012345678\n90');
+ });
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..c508ffd
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+00-mocha.diff
diff --git a/debian/rules b/debian/rules
index de57af0..f816b4a 100755
--- a/debian/rules
+++ b/debian/rules
@@ -9,7 +9,5 @@
 
 #override_dh_auto_build:
 
-#override_dh_auto_test:
-
-
-
+override_dh_auto_test:
+	mocha -u tdd --reporter spec
diff --git a/debian/tests/control b/debian/tests/control
index 372bdc9..9340b8c 100644
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -1,2 +1,5 @@
 Tests: require
 Depends: node-wrap-ansi
+
+Test-Command: mocha -u tdd
+Depends: @, @builddeps@
diff --git a/package.json b/package.json
index 960ea2d..97dba1e 100644
--- a/package.json
+++ b/package.json
@@ -19,8 +19,7 @@
     "node": ">=0.10.0"
   },
   "scripts": {
-    "test": "xo && nyc node test.js",
-    "coverage": "nyc --reporter=text-lcov node test.js | coveralls"
+    "test": "mocha -u tdd"
   },
   "files": [
     "index.js"
diff --git a/test.js b/test.js
index f976a75..677517e 100755
--- a/test.js
+++ b/test.js
@@ -1,5 +1,5 @@
 'use strict';
-var test = require('ava');
+var assert = require('assert');
 var chalk = require('chalk');
 var hasAnsi = require('has-ansi');
 var stripAnsi = require('strip-ansi');
@@ -10,87 +10,73 @@ var fn = require('./');
 var fixture = 'The quick brown ' + chalk.red('fox jumped over ') + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
 var fixture2 = '12345678\n901234567890';
 
-test('wraps string at 20 characters', function (t) {
+test('wraps string at 20 characters', function () {
 	var res20 = fn(fixture, 20);
 
-	t.assert(res20 === 'The quick brown \u001b[31mfox\u001b[39m\n\u001b[31mjumped over \u001b[39mthe lazy\n\u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the\u001b[39m\n\u001b[32municorn.\u001b[39m');
-	t.assert(stripAnsi(res20).split('\n').every(function (x) {
+	assert(res20 === 'The quick brown \u001b[31mfox\u001b[39m\n\u001b[31mjumped over \u001b[39mthe lazy\n\u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the\u001b[39m\n\u001b[32municorn.\u001b[39m');
+	assert(stripAnsi(res20).split('\n').every(function (x) {
 		return x.length <= 20;
 	}));
-
-	t.end();
 });
 
-test('wraps string at 30 characters', function (t) {
+test('wraps string at 30 characters', function () {
 	var res30 = fn(fixture, 30);
 
-	t.assert(res30 === 'The quick brown \u001b[31mfox jumped\u001b[39m\n\u001b[31mover \u001b[39mthe lazy \u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the unicorn.\u001b[39m');
-	t.assert(stripAnsi(res30).split('\n').every(function (x) {
+	assert(res30 === 'The quick brown \u001b[31mfox jumped\u001b[39m\n\u001b[31mover \u001b[39mthe lazy \u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the unicorn.\u001b[39m');
+	assert(stripAnsi(res30).split('\n').every(function (x) {
 		return x.length <= 30;
 	}));
-
-	t.end();
 });
 
-test('does not break strings longer than "cols" characters', function (t) {
+test('does not break strings longer than "cols" characters', function () {
 	var res5 = fn(fixture, 5, {hard: false});
 
-	t.assert(res5 === 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumped\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32municorn.\u001b[39m');
-	t.assert(
+	assert(res5 === 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumped\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32municorn.\u001b[39m');
+	assert(
 		stripAnsi(res5).split('\n').filter(function (x) {
 			return x.length > 5;
 		}).length > 0
 	);
-
-	t.end();
 });
 
-test('handles colored string that wraps on to multiple lines', function (t) {
+test('handles colored string that wraps on to multiple lines', function () {
 	var res = fn(chalk.green('hello world') + ' hey!', 5, {hard: false});
 	var lines = res.split('\n');
-	t.assert(hasAnsi(lines[0]));
-	t.assert(hasAnsi(lines[1]));
-	t.assert(hasAnsi(lines[2]) === false);
-	t.end();
+	assert(hasAnsi(lines[0]));
+	assert(hasAnsi(lines[1]));
+	assert(hasAnsi(lines[2]) === false);
 });
 
-test('does not prepend newline if first string is greater than "cols"', function (t) {
+test('does not prepend newline if first string is greater than "cols"', function () {
 	var res = fn(chalk.green('hello') + '-world', 5, {hard: false});
-	t.assert(res.split('\n').length === 1);
-	t.end();
+	assert(res.split('\n').length === 1);
 });
 
 // when "hard" is true
 
-test('breaks strings longer than "cols" characters', function (t) {
+test('breaks strings longer than "cols" characters', function () {
 	var res5 = fn(fixture, 5, {hard: true});
 
-	t.assert(res5 === 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumpe\u001b[39m\n\u001b[31md\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32munico\u001b[39m\n\u001b[32mrn.\u001b[39m');
-	t.assert(stripAnsi(res5).split('\n').every(function (x) {
+	assert(res5 === 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumpe\u001b[39m\n\u001b[31md\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32munico\u001b[39m\n\u001b[32mrn.\u001b[39m');
+	assert(stripAnsi(res5).split('\n').every(function (x) {
 		return x.length <= 5;
 	}));
-
-	t.end();
 });
 
-test('removes last row if it contained only ansi escape codes', function (t) {
+test('removes last row if it contained only ansi escape codes', function () {
 	var res = fn(chalk.green('helloworld'), 2, {hard: true});
 
-	t.assert(stripAnsi(res).split('\n').every(function (x) {
+	assert(stripAnsi(res).split('\n').every(function (x) {
 		return x.length === 2;
 	}));
-
-	t.end();
 });
 
-test('does not prepend newline if first word is split', function (t) {
+test('does not prepend newline if first word is split', function () {
 	var res = fn(chalk.green('hello') + 'world', 5, {hard: true});
-	t.assert(res.split('\n').length === 2);
-	t.end();
+	assert(res.split('\n').length === 2);
 });
 
-test('takes into account line returns inside input', function (t) {
+test('takes into account line returns inside input', function () {
 	var res20 = fn(fixture2, 10, {hard: true});
-	t.assert(res20 === '12345678\n9012345678\n90');
-	t.end();
+	assert(res20 === '12345678\n9012345678\n90');
 });

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



More information about the Pkg-javascript-commits mailing list