-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
69 lines (56 loc) · 1.68 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
const {homedir} = require('os');
const {join} = require('path');
const {dim, red} = require('chalk');
const neatStack = require('.');
const test = require('tape');
const tildePath = require('tilde-path');
const home = homedir();
test('neatStack()', t => {
const path = tildePath(join(home, 'hello', 'world.js')).replace(/\\/ug, '/');
const error = new Error('foo');
error.stack = `Error: foo
at foo (${path}:1:1)\r\n at bar (${path}:3:4)
at createScript (vm.js:53:10)`;
t.equal(
neatStack(error),
red(`Error: foo${dim(`\n at foo (${path}:1:1)\r\n at bar (${path}:3:4)`)}`),
'should stringify the error with colors.'
);
const modifiedStackError = new TypeError('Hi');
modifiedStackError.stack = '0123456789';
t.equal(
neatStack(modifiedStackError),
red('0123456789'),
'should just return the red-colored stack when it\'s somehow modified.'
);
t.equal(
neatStack('this is string'),
red('this is string'),
'should return a red string if it takes a string.'
);
t.equal(
neatStack(`Error: error
at repl:1:1
at Script.runInThisContext (vm.js:65:33)`),
red(`Error: error
at repl:1:1`),
'should clean up stack trace even if it takes a string.'
);
t.equal(
neatStack(new Set([Buffer.alloc(0)])),
red('Set { <Buffer > }'),
'should return a red-colored util.inspect result if it takes a non-error object.'
);
t.throws(
() => neatStack(),
/^RangeError.*Expected 1 argument, but got no arguments\./u,
'should throw an error when it takes no arguments.'
);
t.throws(
() => neatStack(1, 2),
/^RangeError.*Expected 1 argument, but got 2 arguments\./u,
'should throw an error when it takes too many arguments.'
);
t.end();
});