-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
87 lines (76 loc) · 2.63 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
79
80
81
82
83
84
85
86
87
/*!
* clean-stacktrace-metadata <https://github.com/tunnckoCore/clean-stacktrace-metadata>
*
* Copyright (c) Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var test = require('mukla')
var cleanStacktraceMetadata = require('./index')
test('clean-stacktrace-metadata', function (done) {
var expected = 'at quxie (/home/charlike/apps/alwa.js:8:10)'
cleanStacktraceMetadata(function plugin (line, info) {
test.strictEqual(line, expected)
test.strictEqual(typeof info, 'object')
test.strictEqual(info.place, 'quxie')
test.strictEqual(info.filename, '/home/charlike/apps/alwa.js')
test.strictEqual(info.line, 8)
test.strictEqual(info.column, 10)
})(expected)
done()
})
test('should work for windows paths', function (done) {
cleanStacktraceMetadata(function plugin (line, info) {
test.strictEqual(info.place, 'Test.fn')
test.strictEqual(info.filename, 'C:/projects/stacktrace-metadata/test.js')
test.strictEqual(info.line, 53)
test.strictEqual(info.column, 15)
})('at Test.fn (C:\\projects\\stacktrace-metadata\\test.js:53:15)')
done()
})
test('should work when not defined line and column', function (done) {
function plugin (line, info) {
test.strictEqual(info.line, 0)
test.strictEqual(info.column, 0)
test.strictEqual(info.place, 'quxie')
test.strictEqual(info.filename, '/home/projects/stacktrace-metadata/test.js')
}
var line = 'at quxie /home/projects/stacktrace-metadata/test.js'
cleanStacktraceMetadata(plugin)(line)
done()
})
test('should get empty place when no place defined', function (done) {
cleanStacktraceMetadata(function plugin (line, info) {
test.strictEqual(info.filename, '/home/foo/test.js')
test.strictEqual(info.column, 2)
test.strictEqual(info.place, '')
test.strictEqual(info.line, 33)
})('at /home/foo/test.js:33:2')
done()
})
test('should work for relative paths with no place', function (done) {
var res = cleanStacktraceMetadata(function (line, info) {
test.strictEqual(info.place, '')
return 'hoho'
})('at test.js:33:2')
test.strictEqual(res, 'hoho')
done()
})
test('should throw TypeError if `plugin` is not a function', function (done) {
function fixture () {
cleanStacktraceMetadata()
}
test.throws(fixture, TypeError)
test.throws(fixture, /expect `plugin` to be a function/)
done()
})
test('should not call the `plugin` if line dont have `at`', function (done) {
var line = 'foo bar'
var called = 0
cleanStacktraceMetadata(function plugin (line, info) {
called++
})(line)
test.strictEqual(called, 0)
done()
})