"Some of your tests did a full page reload!" on MacOS when using Chrome 128.x
From https://github.com/angular/angular-cli/issues/28271
When using Karma with Chrome 128.x on OSX, the following error is displayed: Some of your tests did a full page reload!.
Reproduction steps
mkdir karma-test
cd karma-test
npm init -y
npm install karma karma-chrome-launcher karma-jasmine --save-dev
npx karma init
Update the karma config to include
client: {
clearContext: false,
},
npx karma start —-single-run
// This works for me. Not sure if it's a good option or if it makes more sense to address this in the config.
beforeEach(async () => {
window.onbeforeunload = () => "Oh no!"; // Prevent page reloads during tests
});
It’s recommended to use this as a temporary workaround while investigating the root cause of the reloads and fixing any underlying issues in your test logic.
I've hit this with Chrome 129 as well.
It only seems to be happening to me when running in headless mode so I have not been able to debug what is triggering window.onunload.
It seems to happen after all tests have run. I created a simple fdescribe test with an expect(true).toBeTrue() it block, and the issue still happens.
I suspect this has something to do with Chrome's "new" headless mode. Trying to see if that was the case, I tried setting headless=old but Karma-Chrome-Launch seems to not allow that.
browsers: ["ChromeHeadless"],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: "ChromeHeadless",
flags: [
"--no-sandbox", // required to run without privileges in docker
"--user-data-dir=/tmp/chrome-test-profile",
"--disable-web-security",
"--headless=old",
],
},
},
It seems to overwrite the headless option
08 10 2024 19:25:09.448:DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/xr/4wd3v1l5547059_2kptbhfr80000gq/T/karma-93895891 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-background-timer-throttling --disable-renderer-backgrounding --disable-device-discovery-notifications --no-sandbox --user-data-dir=/tmp/chrome-test-profile --disable-web-security http://localhost:9877/?id=93895891 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222
The issue does not happen when running with WebStorm
/Users/Richard.Collette/.nvm/versions/node/v20.15.1/bin/node /../myProjectDir/node_modules/@angular/cli/bin/ng test client --karma-config /Users/Richard.Collette/Applications/WebStorm.app/Contents/plugins/karma/js_reporter/karma-intellij/lib/intellij.conf.js --source-map
and it doesn't happen when I run in normal Chrome mode.
Same issue on mac Chrome 130
I faced the same issue in an Angular project. My karma config had autoWatch: false and singleRun: true. I solved the problem by adding the option watch: false in the "test" archeType defined in the angular.json :-)