-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Refactor/rm computer monitor #2088
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
base: gh-pages
Are you sure you want to change the base?
Refactor/rm computer monitor #2088
Conversation
I have to admit that the new look does not tickle my fancy... But then, I had no problem with the monitor, either. @To1ne do you prefer the new look? If so, I won't object against merging. |
Well, me neither. For me this makes it more obvious what the latest release is, so that is good. (or maybe my brain was trained to ignore the computer monitor already, that's also possible). Maybe it's just the empty space that's making it weird. Can you move the other links up? And maybe make the Pro Git section full width? |
} | ||
|
||
.monitor { | ||
@include background-image-2x($baseurl + "images/monitor-default", $monitor-width, $monitor-height); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also remove the assets if we don't need them no more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW originally I had meant not to compare screenshots, but to overlay with a really blurry <div>
and then measure the pixel brightness, then verify that it is relatively bright for light mode and dark for dark mode. But IIRC I got stuck somewhere along the lines. Maybe it was the "measure pixel brightness".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoa, I can't believe that I couldn't make it work back then. It's relatively easy:
const { chromium } = require('playwright');
const fs = require('fs');
(async () => {
const browser = await chromium.launch(/* uncomment for debugging: { headless: false } */);
const page = await browser.newPage();
await page.goto('https://git-scm.com');
const getBrightness = async () => {
// Take screenshot as base64
const screenshot = await page.screenshot({ type: 'png' });
return await page.evaluate(async (base64) => {
return new Promise((resolve) => {
const img = new Image();
img.src = 'data:image/png;base64,' + base64;
img.onload = () => {
const canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;
const ctx = canvas.getContext('2d');
// Draw scaled-down image to average colors
ctx.drawImage(img, 0, 0, 1, 1);
const [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
// Calculate brightness, for more details, see
// https://en.wikipedia.org/wiki/Relative_luminance#Relative_luminance_and_%22gamma_encoded%22_colorspaces
const brightness = 0.2126 * r + 0.7152 * g + 0.0722 * b;
resolve(brightness);
};
});
}, screenshot.toString('base64'));
};
console.log(`Estimated brightness: ${await getBrightness()}`);
const darkModeButton = page.locator('#dark-mode-button');
await darkModeButton.click();
console.log(`Estimated dark brightness: ${await getBrightness()}`);
// Inject image into page and analyze brightness
await browser.close();
})();
For me, this prints:
Estimated brightness: 216.4316
Estimated dark brightness: 63.005199999999995
Therefore, I think the best idea would be to change the Playwright tests that want to verify that dark mode is dark, light mode is bright, with a variation of this code, say, dividing the return value by 255 to limit it to the range between 0 and 1, and then assert something like expect(await getBrightness()).toBeCloseTo(0.25, 2)
for dark mode (and 0.85 for light mode).
@RafaelJohn9 do you want to run with this and replace the screenshot-based assertions (and likewise these assertions) with this kind of more robust approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing 👍,
Will update the tests 🤝
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RafaelJohn9 maybe that update should be split out into its own PR, which could then be fast-tracked?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooh okay,
lemme reset 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't mean the deletion of the resources that are no longer referenced. I meant the test update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
misunderstood that 😅 ,
Awesome, so should I open another PR referencing the same issue, or should I create a separate issue for it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In git-scm.com, we play a bit looser (albeit not as loose as the Git mailing list): We don't require an issue for every PR. Just open another PR with the updated test (and removing the stored screenshots), maybe referencing this finding about the Playwright tests being broken by benign updated as justification.
So uhm, should I update it to match the deisgn? |
Maybe it would make sense to let @jvns complete the "Install" page and then update the design in the same PR? |
5e73d77
to
52da97c
Compare
## Changes - Replaced pixel-based visual regression tests for dark/light mode with perceptually accurate brightness assertions. - Implemented a `getPageBrightness()` helper that computes **relative luminance** using the ITU-R BT.709/sRGB coefficients (`0.2126*R + 0.7152*G + 0.0722*B`), normalized to the `[0, 1]` range. - Added assertions that light mode brightness is approximately `0.85 ± 0.1` and dark mode is `0.25 ± 0.1`. - Removed all stored screenshot snapshots for dark/light mode across browsers and devices. ## Context Pixel-diff-based screenshot tests are fragile they fail on minor layout shifts, anti-aliasing changes, or browser rendering differences, even when the visual theme (light/dark) is correct. One example is the PR where the monitor around Git's version number is removed, which caused the dark mode tests to fail, even though the new look did not change anything about how dark the dark mode is. Instead, we now verify **perceived brightness** using the standard definition of *relative luminance* from color science (per [Wikipedia](https://en.wikipedia.org/wiki/Relative_luminance)), which aligns with human vision sensitivity (green contributes most, blue least). Reference: #2088 (comment)
Changes
Fix #2068
Context
After the remove of the Background image, the monitor tag looks like this:
I opted to have the tag still to have the name
monitor
since it contains different details such as latest Git version, Binary links for different operating systems and the release date for the latest Git version.One thing I wasn't sure of was whether to remove the images from the repository, would love to hear your thoughts on this.