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

Stub dark media css query #29

Closed
bahmutov opened this issue Oct 25, 2018 · 1 comment · Fixed by #30
Closed

Stub dark media css query #29

bahmutov opened this issue Oct 25, 2018 · 1 comment · Fixed by #30
Assignees
Labels

Comments

@bahmutov
Copy link
Owner

We cannot change the media query for now in Cypress, but we could stub media query from JavaScript, so that websites that load style based on query can switch to dark mode.

Example website that loads dark theme based on the CSS media

<link rel="stylesheet" media="(prefers-color-scheme: dark)" href="vendor/dark.css">

this works only in Safari technical preview 68 Fyrd/caniuse#4514 and is tied to the Mac OS Mojave https://paulmillr.com/posts/using-dark-mode-in-css/

But we can "emulate" this using JavaScript load in Electron / Chrome like this

<script>
    if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
      const link = document.createElement("link")
      link.type = "text/css";
      link.rel = "stylesheet";
      link.href = 'vendor/dark.css';
      document.head.appendChild(link)
    }
</script>

And this is only to allow the code below from this module to pass to the website that we want to use the dark color mode

Cypress.on('window:before:load', win => {
  cy.stub(win, 'matchMedia').withArgs('(prefers-color-scheme: dark)').returns({
    matches: true
  })
})

Looks like this in a simple todo app

screen shot 2018-10-25 at 11 55 11 am

@bahmutov
Copy link
Owner Author

🎉 This issue has been resolved in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

1 participant