diff --git a/lib/stackparser.js b/lib/stackparser.js index db166e7..7906e1c 100644 --- a/lib/stackparser.js +++ b/lib/stackparser.js @@ -1,14 +1,9 @@ -const regAssertParser = /(.*?)\n+(.*?)\n+(( at.*?file:\/\/(.*?):(\d+):(\d+).*?\n).*)/s +const regAssertParser = /(?.*?)\n+(?<diff>.*?)\n+(?<stacktrace> (?<where>at.*?file:\/\/(?<file>.*?):(?<line>\d+):(?<column>\d+)\)?)\n.*)/s const stackParser = (stack) => { const m = stack.match(regAssertParser) - const info = m - .slice(1) - .map(x => x.trim()) - const [title, diff, stacktrace, where, file, line, column] = info - - return { title, diff, where, file, line, column, stacktrace } + return m.groups } export { stackParser } \ No newline at end of file diff --git a/lib/stackparser.test.js b/lib/stackparser.test.js index 600f5d6..c7f98da 100644 --- a/lib/stackparser.test.js +++ b/lib/stackparser.test.js @@ -11,9 +11,14 @@ test('Diff', () => { } catch (e) { const stack = stackParser(e.stack) + assert.equal(stack.title, 'AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:') assert.ok(stack.diff.includes("name: 'Name'")) assert.ok(stack.diff.includes("name: 'Name2'")) - assert.ok(stack.where.includes('stackparser.test.js')) + assert.equal(stack.where, 'at Object.fn (file:///home/taz/code/metaltest/lib/stackparser.test.js:10:12)') + assert.equal(stack.file, '/home/taz/code/metaltest/lib/stackparser.test.js') + assert.equal(stack.line, '10') + assert.equal(stack.column, '12') + assert.ok(stack.stacktrace.startsWith(' at Object.fn (file:///home/taz/code/metaltest/lib/stackparser.test.js:10:12)')) } })