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

Tests failing on Windows > 10.0.17666 (nativeTheme undefined) #9699

Closed
dennisameling opened this issue May 4, 2020 · 3 comments · Fixed by #9709
Closed

Tests failing on Windows > 10.0.17666 (nativeTheme undefined) #9699

dennisameling opened this issue May 4, 2020 · 3 comments · Fixed by #9709

Comments

@dennisameling
Copy link
Contributor

Describe the bug

Updating to Windows > 10.0.17666 (Windows 10 1809 or Windows Server 2019), then running GitHub Desktop tests (yarn test), leads to failed tests related to Electron's NativeTheme API:

FAIL app/test/unit/git-store-test.ts
  ● Test suite failed to run
    TypeError: Cannot read property 'addListener' of undefined
      20 |     }
      21 | 
    > 22 |     remote.nativeTheme.addListener('updated', this.onThemeNotificationFromOS)
         |                        ^
      23 |   }
      24 | 
      25 |   private onThemeNotificationFromOS = (event: string, userInfo: any) => {
      at ThemeChangeMonitor.subscribe (src/ui/lib/theme-change-monitor.ts:22:24)
      at new ThemeChangeMonitor (src/ui/lib/theme-change-monitor.ts:10:10)
      at Object.<anonymous> (src/ui/lib/theme-change-monitor.ts:44:35)
      at Object.<anonymous> (src/lib/stores/app-store.ts:65:1)
      at Object.<anonymous> (src/lib/stores/index.ts:2:1)
      at Object.<anonymous> (test/unit/git-store-test.ts:10:1)

Commit: dennisameling@9771d64
AppVeyor pipeline: https://ci.appveyor.com/project/dennisameling/desktop/builds/32639417/job/fqktr9tpr2fnjqid#L477

The reason this problem only starts to appear now, is that the AppVeyor pipeline has been running on Visual Studio 2015 (Windows Server 2012 R2) until now, and when upgrading to Visual Studio 2019 (Windows Server 2019), the function isWindows10And1809Preview17666OrLater() returns true because build 17763 (Server 2019) > 17666.

A solution I can think of is to check whether remote.nativeTheme exists, as it's undefined in test environments apparently (it does work as expected when manually running the GitHub Desktop app on Windows 10 >1809, just not in yarn test). Not sure if it's the best solution, but it does make the tests pass. I'm attaching a PR for consideration by the GitHub Desktop team, feel free to decline if you think there's a better solution to resolve this issue.

Version & OS

Open 'About GitHub Desktop' menu to see the Desktop version. Also include what operating system you are using.

Steps to reproduce the behavior

  1. Run Windows 1809 (or later) or Windows Server 2019 (or later), since these builds have numbers 17763 (higher than 17666)
  2. Run yarn test, then the error above will show up

Expected behavior

Tests should pass without errors

Actual behavior

Multiple tests that are related to Electron's NativeTheme API fail both on client devices and the build pipeline (AppVeyor)

Screenshots

N/A

Logs

AppVeyor pipeline logs: https://ci.appveyor.com/project/dennisameling/desktop/builds/32639417/job/fqktr9tpr2fnjqid#L477

Additional context

Add any other context about the problem here.

@dennisameling
Copy link
Contributor Author

cc @say25 (related to this comment)

@outofambit
Copy link
Contributor

thanks for documenting this so well @dennisameling ! i made a fix in #9709 after doing a little research. would you take a look and see if that works for you?

@dennisameling
Copy link
Contributor Author

Great find in #9709, didn't know it's using mock functions in tests! Thanks @outofambit 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants