Skip to content

[lexical-headless-test] Enhance navigator environment check with object type and structure validation#7626

Merged
etrepum merged 7 commits intofacebook:mainfrom
0xobedient:enhance-navigator-check
Jun 22, 2025
Merged

[lexical-headless-test] Enhance navigator environment check with object type and structure validation#7626
etrepum merged 7 commits intofacebook:mainfrom
0xobedient:enhance-navigator-check

Conversation

@0xobedient
Copy link
Copy Markdown
Contributor

@0xobedient 0xobedient commented Jun 16, 2025

Lexical version: 0.32.1

[lexical-headless]
[env-utils] Feature: improve navigator detection logic for Node environments

Choose from the following PR Types:
Chore

Description

lexical-headless must guarantee testing in a Node environment, not in jsDom.
To ensure this, the following comment is placed at the top of the file to explicitly run tests in the Node environment:

 /**
    * @jest-environment node
 */

While testing 'should be headless environment', we verified that both window and document are undefined as expected.
However, navigator was found to be assigned an empty object and identified as an Object, which is unexpected.

To address this, we added logic to check whether navigator is a valid one created by the test environment (i.e., not a fake or placeholder object), ensuring a more accurate environment validation.

Before

Test Failing because typeof navigatoris returning "object".
image

After

All Test succeeded.
image

@vercel
Copy link
Copy Markdown

vercel bot commented Jun 16, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 22, 2025 1:24pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 22, 2025 1:24pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 16, 2025
@0xobedient 0xobedient requested a review from lilshady June 17, 2025 07:37
Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

How is this a net improvement, if the tests don't run in the configuration where this may have failed? It changes one test, which must have already passed, and seems to make no changes to any runtime code.

If this code is only relevant to tests, it should probably be colocated with the tests rather than placed in shared. We don't have other test utilities in the shared package.

@0xobedient
Copy link
Copy Markdown
Contributor Author

0xobedient commented Jun 17, 2025

How is this a net improvement, if the tests don't run in the configuration where this may have failed? It changes one test, which must have already passed, and seems to make no changes to any runtime code.

If this code is only relevant to tests, it should probably be colocated with the tests rather than placed in shared. We don't have other test utilities in the shared package.

You are right — this change does not introduce any modifications to the runtime code. As you suggested, I will move isEmptyNavigator into the test file. Thanks for review.

Copy link
Copy Markdown
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

I still don't really understand what purpose this serves, because the tests don't run in an environment where this change has any effect, but it is a small change isolated to the tests now.

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Jun 22, 2025
@etrepum etrepum added this pull request to the merge queue Jun 22, 2025
Merged via the queue into facebook:main with commit b7d43ab Jun 22, 2025
39 checks passed
@etrepum etrepum mentioned this pull request Jul 3, 2025
fantactuka pushed a commit that referenced this pull request Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants