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

fix: add hint for missing document global in terminal error #26218

Merged
merged 9 commits into from
Oct 15, 2024

Conversation

bartlomieju
Copy link
Member

This came up on Discord as a question so I thought it's worth adding a hint for this
as it might be a common pitfall.

@bartlomieju
Copy link
Member Author

DO NOT LAND.

It's not great if document is used in testing code:

Deno.test("document query selector", () => {
  document.querySelector("div");
});
running 1 test from ./tests/specs/run/document/document_test.js
document query selector ... FAILED (1ms)

 ERRORS

document query selector => ./tests/specs/run/document/document_test.js:1:6
error: ReferenceError: document is not defined
  document.querySelector("div");
  ^
    at file:///Users/ib/dev/deno/tests/specs/run/document/document_test.js:2:3

 FAILURES

document query selector => ./tests/specs/run/document/document_test.js:1:6

FAILED | 0 passed | 1 failed (6ms)

error: Test failed

It should be enhancing terminal errors in deno test too.

@EGAMAGZ
Copy link

EGAMAGZ commented Oct 14, 2024

It will also grate to add this in the documentation related to testing, the need to add a library like happy-dom, deno_dom, linkedom or JSDom to polyfill the absence of dom to this type of test done with libraries like @testing-library/preact and frontend like preact (even include an example if it is possible)

bartlomieju added a commit that referenced this pull request Oct 15, 2024
Moves code for generating suggestions and hint to `cli/fmt_errors.rs`.

This effectively applies suggestion to any place that format JS errors
in terminal,
like `deno test`.

Addresses
#26218 (comment)
@bartlomieju bartlomieju enabled auto-merge (squash) October 15, 2024 18:43
@dsherret dsherret changed the title fix: Add hint for missing document global in terminal error fix: add hint for missing document global in terminal error Oct 15, 2024
Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

runtime/fmt_errors.rs Outdated Show resolved Hide resolved
bartlomieju and others added 3 commits October 15, 2024 23:13
Co-authored-by: David Sherret <[email protected]>
Signed-off-by: Bartek Iwańczuk <[email protected]>
@bartlomieju bartlomieju enabled auto-merge (squash) October 15, 2024 21:16
@bartlomieju bartlomieju merged commit ee904ec into denoland:main Oct 15, 2024
17 checks passed
@bartlomieju bartlomieju deleted the terminal_error_document branch October 15, 2024 21:55
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

Successfully merging this pull request may close these issues.

3 participants