-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
78 lines (66 loc) · 2.25 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
70
71
72
73
74
75
76
77
78
var assume = require('assume');
var pruddy = require('./');
describe('pruddy', function () {
const fixture = new Error('Splode');
it('is exposed as function', function () {
assume(pruddy).is.a('function');
});
it('returns undefined if noting is passed', function () {
assume(pruddy()).is.a('undefined');
});
it('returns a string when a valid error is given', function () {
assume(pruddy(fixture)).is.a('string');
});
it('provides context about the error', function () {
const rendered = pruddy(fixture);
assume(rendered).contains('v');
assume(rendered).contains(`4. describe('pruddy', function () {`);
assume(rendered).contains(`5. const fixture = new Error('Splode');`);
assume(rendered).contains(`6.`);
assume(rendered).contains('^');
});
describe('shift', function () {
it('can shift the stacktrace', function () {
const rendered = pruddy(fixture, {
shift: 1
});
assume(rendered).contains('v');
assume(rendered).does.not.contains(`4. describe('pruddy', function () {`);
assume(rendered).does.not.contains(`5. const fixture = new Error('Splode');`);
assume(rendered).does.not.contains(`6.`);
assume(rendered).contains('^');
});
});
describe('read', function () {
it('can provide a custom document fetcher', function (next) {
pruddy(fixture, {
read: function read(data) {
assume(data).is.a('object');
assume(data.filename).contains('pruddy-error/test.js');
assume(data.line).equals(5);
assume(data.col).equals(19);
next();
}
});
});
it('uses the returned file as source for highlight', function () {
const rendered = pruddy(fixture, {
read: function read() {
return [
'line 1',
'line 2',
'line 3',
'line 4',
'line 5 with some extra long content for me bois',
'line 6',
].join('\n');
}
});
assume(rendered).contains('v');
assume(rendered).contains(`4. line 4`);
assume(rendered).contains(`5. line 5 with some extra long content for me bois`);
assume(rendered).contains(`6. line 6`);
assume(rendered).contains('^');
});
});
});