Skip to content

Commit a365116

Browse files
committed
Fix tests to work standalone, adopt QUnit
* Update JSHint and use directly from npm script, instead of via Grunt. * Switch from unmaintained nodeunit to latest QUnit. * Fix tests to work standalone. Follows-up a67ce89 which removed "color" in favor of "chalk" inside grunt-legacy-log-utils, but did not update the unit tests. This worked because the dev dependency on "grunt" brought "color" back in via "grunt-legacy-log", which in turn depends on "color". Without this in place, the tests failed due to accessing undefined `"c".blue.underline`.
1 parent a302ffd commit a365116

5 files changed

Lines changed: 35 additions & 75 deletions

File tree

.jshintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Gruntfile.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
[![Build Status](https://github.com/gruntjs/grunt-legacy-log-utils/workflows/Tests/badge.svg)](https://github.com/gruntjs/grunt-legacy-log-utils/actions?workflow=Tests)
55
[![Built with Grunt](https://gruntjs.com/builtwith.svg)](https://gruntjs.com/)
66
[![npm](https://img.shields.io/npm/v/grunt-legacy-log-utils.svg?style=flat)](https://www.npmjs.com/package/grunt-legacy-log-utils)
7+
[![Tested with QUnit](https://qunitjs.com/testedwith.svg)](https://qunitjs.com/)
8+
9+
## See also
10+
11+
* [grunt-legacy-log](https://github.com/gruntjs/grunt-legacy-log)

package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"index.js"
1818
],
1919
"scripts": {
20-
"test": "grunt test"
20+
"test": "jshint . && qunit"
2121
},
2222
"engines": {
2323
"node": ">=10"
@@ -30,9 +30,7 @@
3030
"chalk": "^4.1.0"
3131
},
3232
"devDependencies": {
33-
"grunt": "^1.2.1",
34-
"grunt-contrib-jshint": "^2.1.0",
35-
"grunt-contrib-nodeunit": "^2.1.0",
36-
"grunt-contrib-watch": "^1.1.0"
33+
"jshint": "~2.13.6",
34+
"qunit": "^2.25.0"
3735
}
3836
}

test/index.js

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
1+
/* globals QUnit */
12
'use strict';
23

4+
var chalk = require('chalk');
35
var logUtils = require('../');
46

5-
exports['Helpers'] = {
6-
setUp: function(done) {
7-
done();
8-
},
9-
'uncolor': function(test) {
10-
test.expect(1);
11-
12-
test.equal(logUtils.uncolor('a'.red + 'b'.bold.green + 'c'.blue.underline), 'abc');
13-
14-
test.done();
15-
},
16-
'wordlist': function(test) {
17-
test.expect(2);
18-
19-
test.equal(logUtils.uncolor(logUtils.wordlist(['a', 'b'])), 'a, b');
20-
test.equal(logUtils.uncolor(logUtils.wordlist(['a', 'b'], {separator: '-'})), 'a-b');
21-
22-
test.done();
23-
},
24-
'wraptext': function(test) {
25-
test.expect(8);
26-
7+
QUnit.module('Helpers', function () {
8+
QUnit.test('uncolor', function(assert) {
9+
var chalked = chalk.red('a') + chalk.bold.green('b') + chalk.blue.underline('c');
10+
assert.notEqual(chalked, 'abc', 'chalked');
11+
assert.equal(logUtils.uncolor(chalked), 'abc', 'uncolor');
12+
});
13+
QUnit.test('wordlist', function(assert) {
14+
assert.equal(logUtils.uncolor(logUtils.wordlist(['a', 'b'])), 'a, b');
15+
assert.equal(logUtils.uncolor(logUtils.wordlist(['a', 'b'], {separator: '-'})), 'a-b');
16+
});
17+
QUnit.test('wraptext', function(assert) {
2718
// // I'm not writing out comprehensive unit tests for this right now.
2819
// function doAll(text) {
2920
// console.log('==========');
@@ -43,21 +34,17 @@ exports['Helpers'] = {
4334
// text = 'foolish monkeys eating delicious bananas forever'.rainbow;
4435
// doAll(text);
4536

46-
test.equal(logUtils.wraptext(2, 'aabbc'), 'aa\nbb\nc');
47-
test.equal(logUtils.wraptext(2, 'aabbcc'), 'aa\nbb\ncc');
48-
test.equal(logUtils.wraptext(3, 'aaabbbc'), 'aaa\nbbb\nc');
49-
test.equal(logUtils.wraptext(3, 'aaabbbcc'), 'aaa\nbbb\ncc');
50-
test.equal(logUtils.wraptext(3, 'aaabbbccc'), 'aaa\nbbb\nccc');
51-
test.equal(logUtils.uncolor(logUtils.wraptext(3, 'aaa'.blue + 'bbb'.green + 'c'.underline)), 'aaa\nbbb\nc');
52-
test.equal(logUtils.uncolor(logUtils.wraptext(3, 'aaa'.blue + 'bbb'.green + 'cc'.underline)), 'aaa\nbbb\ncc');
53-
test.equal(logUtils.uncolor(logUtils.wraptext(3, 'aaa'.blue + 'bbb'.green + 'ccc'.underline)), 'aaa\nbbb\nccc');
54-
55-
test.done();
56-
},
57-
'table': function(test) {
58-
test.expect(1);
59-
60-
test.equal(logUtils.table([3, 1, 5, 1, 8, 1, 12, 1, 20], [
37+
assert.equal(logUtils.wraptext(2, 'aabbc'), 'aa\nbb\nc');
38+
assert.equal(logUtils.wraptext(2, 'aabbcc'), 'aa\nbb\ncc');
39+
assert.equal(logUtils.wraptext(3, 'aaabbbc'), 'aaa\nbbb\nc');
40+
assert.equal(logUtils.wraptext(3, 'aaabbbcc'), 'aaa\nbbb\ncc');
41+
assert.equal(logUtils.wraptext(3, 'aaabbbccc'), 'aaa\nbbb\nccc');
42+
assert.equal(logUtils.uncolor(logUtils.wraptext(3, chalk.blue('aaa') + chalk.green('bbb') + chalk.underline('c'))), 'aaa\nbbb\nc');
43+
assert.equal(logUtils.uncolor(logUtils.wraptext(3, chalk.blue('aaa') + chalk.green('bbb') + chalk.underline('cc'))), 'aaa\nbbb\ncc');
44+
assert.equal(logUtils.uncolor(logUtils.wraptext(3, chalk.blue('aaa') + chalk.green('bbb') + chalk.underline('ccc'))), 'aaa\nbbb\nccc');
45+
});
46+
QUnit.test('table', function(assert) {
47+
assert.equal(logUtils.table([3, 1, 5, 1, 8, 1, 12, 1, 20], [
6148
'a aa aaa aaaa aaaaa',
6249
'|||||||',
6350
'b bb bbb bbbb bbbbb',
@@ -74,6 +61,5 @@ exports['Helpers'] = {
7461
'a | | | |\n' +
7562
'aaa| | | |\n' +
7663
'aa | | | |');
77-
test.done();
78-
},
79-
};
64+
});
65+
});

0 commit comments

Comments
 (0)