Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"at:" missing from diagnostic when file path starts with "file://" #601

Closed
tbeseda opened this issue Oct 15, 2023 · 5 comments
Closed

"at:" missing from diagnostic when file path starts with "file://" #601

tbeseda opened this issue Oct 15, 2023 · 5 comments
Assignees

Comments

@tbeseda
Copy link

tbeseda commented Oct 15, 2023

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"

not ok 10 A failing string equal
  ---
    operator: equal
    expected: 'Good dog'
    actual:   'Bad dog'
    stack: |-
      Error: A failing string equal
          at Test.assert [as _assert] (/my-project/node_modules/tape/lib/test.js:479:48)
          at Test.strictEqual (/my-project/node_modules/tape/lib/test.js:643:7)
          at Test.<anonymous> (file:///my-project/test/tap/make-tap.js:51:5)
          at Test.run (/my-project/node_modules/tape/lib/test.js:113:28)
          at Immediate.next [as _onImmediate] (/my-project/node_modules/tape/lib/results.js:157:7)
          at process.processImmediate (node:internal/timers:476:21)
  ...

I believe it's this loop that sets the Test.at https://github.com/ljharb/tape/blob/5a776572cb7dcf46e32c493db716579e3bc5dc5d/lib/test.js#L523-L525

I'm hesitant to wade into that regex 😬 but I can make an attempt if it's not an apparent/easy fix

🍻

@ljharb
Copy link
Collaborator

ljharb commented Oct 23, 2023

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?

@ljharb
Copy link
Collaborator

ljharb commented Jan 10, 2024

@tbeseda ping, i'd love to address this

@tbeseda
Copy link
Author

tbeseda commented Jan 19, 2024

Apologies, I've been neglecting my GH notifications.
I'll work on a repro you can run and update here.

@tbeseda
Copy link
Author

tbeseda commented Jan 22, 2024

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)

@ljharb
Copy link
Collaborator

ljharb commented Jan 24, 2024

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.

@ljharb ljharb self-assigned this Jan 24, 2024
ljharb added a commit that referenced this issue Jan 24, 2024
@ljharb ljharb closed this as completed in 6a5df50 Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants