Closed tbeseda closed 7 months ago
I'm not sure how to turn this into a failing test case. Can you provide a .js
file, and the expected tape output from it?
@tbeseda ping, i'd love to address this
Apologies, I've been neglecting my GH notifications. I'll work on a repro you can run and update here.
Looking at this again, I realized it's related to executing tests in an ESM environment.
with CJS
const test = require('tape')
test('test', function (t) {
t.plan(1)
t.equal('foobaz', 'foobar')
})
I get the expected output with the at:
line
TAP version 13
# test
not ok 1 should be strictly equal
---
operator: equal
expected: 'foobar'
actual: 'foobaz'
at: Test.<anonymous> (/project-path/index.cjs:5:5)
stack: |-
Error: should be strictly equal
at Test.assert [as _assert] (/project-path/node_modules/tape/lib/test.js:479:48)
at Test.strictEqual (/project-path/node_modules/tape/lib/test.js:661:7)
at Test.<anonymous> (/project-path/index.cjs:5:5)
at Test.run (/project-path/node_modules/tape/lib/test.js:113:28)
at Immediate.next [as _onImmediate] (/project-path/node_modules/tape/lib/results.js:156:7)
at process.processImmediate (node:internal/timers:476:21)
...
1..1
# tests 1
# pass 0
# fail 1
with MJS
import test from 'tape'
test('test', function (t) {
t.plan(1)
t.equal('foobaz', 'foobar')
})
I don't get the at:
line, but there is a nice stack:
TAP version 13
# test
not ok 1 should be strictly equal
---
operator: equal
expected: 'foobar'
actual: 'foobaz'
stack: |-
Error: should be strictly equal
at Test.assert [as _assert] (/project-path/node_modules/tape/lib/test.js:479:48)
at Test.strictEqual (/project-path/node_modules/tape/lib/test.js:661:7)
at Test.<anonymous> (file:///project-path/index.mjs:5:5)
at Test.run (/project-path/node_modules/tape/lib/test.js:113:28)
at Immediate.next [as _onImmediate] (/project-path/node_modules/tape/lib/results.js:156:7)
at process.processImmediate (node:internal/timers:476:21)
...
1..1
# tests 1
# pass 0
# fail 1
this file:///
line has the location of my failing assertion
at Test.<anonymous> (file:///project-path/index.mjs:5:5)
aha, yes i'm sure that it's due to the regex expecting paths, while native ESM in node unfortunately uses URLs. I'll see what's possible - an actually correcct regex for a URL is probably impossible, but perhaps since this can only happen in a node that has a native URL
, I can use that when available.
Here's a sample of tape output without the
at:
entry in the diagnostics YAML The 4th line of the "stack" block should also be in the YAML as "at"I believe it's this loop that sets the
Test.at
https://github.com/ljharb/tape/blob/5a776572cb7dcf46e32c493db716579e3bc5dc5d/lib/test.js#L523-L525I'm hesitant to wade into that regex 😬 but I can make an attempt if it's not an apparent/easy fix
🍻