Skip to content

Tests fail on Windows: InputManager keyboard state and TextUtils lineHeight mismatch #3043

Description

@luo2430

Describe the bug

A clear and concise description of what the bug is.

ci可以跑通,但我windows本地如何都跑不通。

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 4 ⎯⎯⎯⎯⎯⎯⎯

 FAIL   @galacean/engine-tests (chromium)  src/core/input/InputManager.test.ts > InputManager > blur and focus
AssertionError: expected false to equal true

- Expected
+ Received

- true
+ false

 ❯ src/core/input/InputManager.test.ts:216:49
    214|     target.dispatchEvent(generateKeyboardEvent("keydown", "KeyA"));
    215|     engine.update();
    216|     expect(inputManager.isKeyDown(Keys.KeyA)).to.eq(true);
       |                                                 ^
    217|     target.dispatchEvent(new Event("blur"));
    218|     expect(inputManager.isKeyDown()).to.eq(false);

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/4]⎯

 FAIL   @galacean/engine-tests (chromium)  src/core/input/InputManager.test.ts > InputManager > change listener target
AssertionError: expected false to equal true

- Expected
+ Received

- true
+ false

 ❯ src/core/input/InputManager.test.ts:236:40
    234|     window.dispatchEvent(generateKeyboardEvent("keydown", "KeyA"));
    235|     engine.update();
    236|     expect(inputManager.isKeyDown()).to.eq(true);
       |                                        ^
    237| 
    238|     window.dispatchEvent(generateWheelEvent(1, 2, 3));

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/4]⎯

 FAIL   @galacean/engine-tests (chromium)  src/core/2d/text/TextUtils.test.ts > TextUtils > measureTextWithWrap
AssertionError: expected 26 to equal 27

- Expected
+ Received

- 27
+ 26

 ❯ src/core/2d/text/TextUtils.test.ts:170:36
    168|       "。"
    169|     ]);
    170|     expect(result.lineHeight).to.be.equal(27);
       |                                    ^
    171|     textRendererTruncate.text = text2;
    172|     result = TextUtils.measureTextWithWrap(

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/4]⎯

 FAIL   @galacean/engine-tests (chromium)  src/core/2d/text/TextUtils.test.ts > TextUtils > measureTextWithoutWrap
AssertionError: expected 26 to equal 27

- Expected
+ Received

- 27
+ 26

 ❯ src/core/2d/text/TextUtils.test.ts:412:36
    410|     expect(result.lines).to.be.deep.equal(["趚今天天气很好,阳光明媚。我 在公园里 漫步。"]);
    411|     expect(result.lineWidths).to.be.deep.equal([518]);
    412|     expect(result.lineHeight).to.be.equal(27);
       |                                    ^
    413|     textRendererTruncate.text = text2;
    414|     result = TextUtils.measureTextWithoutWrap(

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/4]⎯


 Test Files  2 failed | 109 passed (111)
      Tests  4 failed | 1444 passed (1448)
   Start at  13:40:16
   Duration  23.62s

Desktop (please complete the following information)

System:
OS: Windows 11 10.0.26200
CPU: (16) x64 AMD Ryzen 7 4800H with Radeon Graphics
Memory: 7.03 GB / 15.42 GB
Binaries:
Node: 22.22.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.22 - C:\Users\24306\AppData\Roaming\npm\yarn.CMD
npm: 11.17.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 9.3.0 - C:\Users\24306\AppData\Roaming\npm\pnpm.CMD
Managers:
pip3: 26.0.1 - ~\AppData\Local\Programs\Python\Python314\Scripts\pip3.EXE
Utilities:
Git: 2.53.0. - C:\Program Files\Git\cmd\git.EXE
Git LFS: 3.7.1 - C:\Program Files\Git\cmd\git-lfs.EXE
Curl: 8.19.0 - C:\WINDOWS\system32\curl.EXE
SDKs:
Windows SDK:
AllowDevelopmentWithoutDevLicense: Enabled
Versions: 10.0.26100.0
IDEs:
Android Studio: AI-253.29346.138.2531.14876573
VSCode: 1.124.2 - C:\Users\24306\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD
Languages:
Python: 3.14.3 - C:\Users\24306\AppData\Local\Programs\Python\Python314\python.EXE
Browsers:
Edge: Chromium (149.0.4022.69)

Additional context

Add any other context about the problem here.

这样修改后可以通过input测试,但由于缺少更详细的测试,我不确定这样修改之后是否符合你们的行为预期。

Image

关于textUtils问题,_measureFontOrChar 的核心逻辑似乎是在离屏 Canvas 上真实渲染字体,然后用 getImageData 逐像素扫描,找到第一个非透明像素和最后一个非透明像素。虽然统一使用了从系统获取的Arial字体,但是不同操作系统/浏览器上的渲染结果可能不同。这可能是导致这个问题的原因,可以尝试在测试中统一使用导入的ttf字体。

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions