Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ module.exports = function stackman (opts) {
properties.getFileName = {
writable: true,
value: function () {
var filename = getFileName.call(callsite)
var filename = getFileName.call(callsite).replace(/^file:\/\//, '')
var sourceFile = getPosition().source
if (!sourceFile) return filename
var sourceDir = path.dirname(filename)
Expand All @@ -303,6 +303,13 @@ module.exports = function stackman (opts) {
return getPosition().column || getColumnNumber.call(callsite)
}
}
} else {
properties.getFileName = {
writable: true,
value: function () {
return getFileName.call(callsite).replace(/^file:\/\//, '')
}
}
}

Object.defineProperties(callsite, properties)
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"tape": "^4.13.2"
},
"scripts": {
"test": "standard && node test/strict.js && node test/non-strict.js && node test/longjohn.js && node test/sourcemap.js"
"test": "node test/strict.js && node test/non-strict.js && node test/longjohn.js && node test/sourcemap.js && node test/esm.mjs",
"posttest": "npm run lint",
"lint": "standard"
},
"repository": {
"type": "git",
Expand Down
32 changes: 32 additions & 0 deletions test/esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import test from 'tape'
import createStackman from '../index.js'

const stackman = createStackman()

test('callsite.getRelativeFileName()', function (t) {
var err = new Error('foo')
stackman.callsites(err, function (err, callsites) {
t.error(err)
t.equal(callsites[0].getRelativeFileName(), 'test/esm.mjs')
t.end()
})
})

test('callsite.sourceContext()', function (t) {
var err = new Error()
stackman.callsites(err, function (err, callsites) {
t.error(err)

callsites[0].sourceContext(function (err, context) {
t.error(err)
t.equal(typeof context, 'object')
t.equal(typeof context.line, 'string')
t.ok(Array.isArray(context.pre), 'should be an array')
t.ok(Array.isArray(context.post), 'should be an array')
t.equal(context.pre.length, 2)
t.equal(context.post.length, 2)
t.equal(context.line.trim(), 'var err = new Error()')
t.end()
})
})
})