test: fix implicit test dependencies on local dev environment #4053
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a few test failures I noticed when running
npm run test:unitandnpm run test:integrationlocally on my dev machine, which is running MacOS 13.4 with the system appearance preference set to dark mode. Before this PR, the integration tests wouldn't run and there were 11 bogus unit test failures on my local dev machine; after this PR, they are consistent with CI and pass.The main issues this PR fixes are:
npm run startusedhttp-serverwithout explicitly setting its-aargument, which means that it listens only on IPv4 localhost interfaces, not IPv6. This causednpm run test:integrationto get stuck instart-server-and-test's health check of the localhost server, which tried to connect on::1by default. Adding-a ""works around this. See support for IPv6 http-party/http-server#832 and https://github.com/http-party/http-server/pull/833/files for context.mocha.cssin our unit and integration tests uses aprefers-color-schememedia query to change the test page's background color according to system color scheme preference. However, many test cases in theget-foreground-colorandget-background-colorunit tests make assumptions about color blending that rely on the default light-scheme background color. This PR addsbefore/afterhooks to those test files to normalize to the#fffbackground the tests assume. These hooks intentionally set the normalized color inbeforeEach(to ensure each test case has an consistent starting state) and reset to the original color inafterrather thanafterEach(to limit the amount of unnecessary color flashing).dialogintegration test attempted to induce a color-contrast failure by overriding onlybackground-color, but in dark mode, the new background color didn't actually cause a failure on its own. Updated that test to also overridecolorto ensure the intended failure appears regardless of dark mode settings.This PR also included a few refactorings that didn't turn out to be necessary to the fixes, but seemed nice enough and separate enough from the other changes to include. They are isolated to their own commits; feel free to review commit-by-commit to see them in isolation from the functional changes.
@straker and I originally explored an alternative for this that involved adding our own
/test/global-styles.cssthat would overridemocha.cssand force a consistent background/text color across all tests all the time, ignoring prefers-color-scheme. I didn't end up going with this strategy because it conflicted too much with the test status messages that mocha includes on the page duringnpm run test:debugexecution; in dark mode, it resulted in a lot of unreadable white-on-white text.Closes: n/a