-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
67 lines (56 loc) · 2.01 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
/*!
* clean-stacktrace-relative-paths <https://github.com/tunnckoCore/clean-stacktrace-relative-paths>
*
* Copyright (c) Charlike Mike Reagent <@tunnckoCore> (https://i.am.charlike.online)
* Released under the MIT license.
*/
/* jshint asi:true */
'use strict'
var path = require('path')
var isCI = require('is-ci')
var test = require('mukla')
var cleanStack = require('clean-stacktrace')
var relativePaths = require('./index')
test('should export a function that returns a mapper function', function (done) {
var mapper = relativePaths()
test.strictEqual(typeof mapper, 'function')
done()
})
test('should allow passing custom cwd', function (done) {
var er = new Error('abc error foo')
var mapper = relativePaths('../qux')
var stack = cleanStack(er.stack, mapper)
var fp = '..' + path.sep + 'clean-stacktrace-relative-paths' + path.sep + 'test.js'
test.strictEqual(stack.indexOf(fp) > 5, true)
done()
})
test('should be used as `mapper` function to `clean-stacktrace`', function (done) {
var error = new Error('fixture err')
var stack = cleanStack(error.stack, relativePaths())
test.ok(/\(test\.js:/.test(stack))
done()
})
test('should work for paths non in parens', function qxu (done) {
var line = 'at Function.qxu (/home/charlike/apps/clean-stacktrace-relative-paths/test.js:44:15)'
var relative = relativePaths()
var res = relative(line)
if (isCI) {
test.strictEqual(/at Function\.qxu/.test(res), true)
test.strictEqual(/\.\./.test(res), true)
test.strictEqual(/test\.js:44:15/.test(res), true)
} else {
test.strictEqual(res, 'at Function.qxu (test.js:44:15)')
}
done()
})
test('should work for lines like "at /full/absolute/path.js:3:1" with no "place"', function (done) {
var line = 'at /home/charlike/apps/clean-stacktrace-relative-paths/test.js:3:1'
var res = relativePaths()(line)
if (isCI) {
test.strictEqual(/at \.\./i.test(res), true)
test.strictEqual(/test\.js:3:1/i.test(res), true)
} else {
test.strictEqual(res, 'at test.js:3:1')
}
done()
})