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

clearContext:true and watch mode causes "Some of your tests did a full page reload!" #3482

Closed
kamilchlebek opened this issue Apr 21, 2020 · 5 comments · Fixed by #3591 or karronoli/redpen#10 · May be fixed by PDSSnyk/juice-shop#74
Closed
Labels

Comments

@kamilchlebek
Copy link

I'm not really sure if this is a bug or a feature.

I'm running karma in watch mode along with clearContext: true (which in fact was set to true by accident)

I was experiencing issues:
Disconnected (0 times) Client disconnected from CONNECTED state (ping timeout)
Some of your tests did a full page reload!

Only way to fix this was to restart karma.

I've debugged karma to see what's going on and here are results.

Setting clearContext: false solves the issue as

karma/client/karma.js

Lines 130 to 132 in 6235e68

if (!reloadingContext) {
// TODO(vojta): show what test (with explanation about jasmine.UPDATE_INTERVAL)
self.error('Some of your tests did a full page reload!')
error is never throw in this case

reloadingContext depends on clearContext here:

reloadingContext = !self.config.clearContext


I'm still getting DisconnectedClient disconnected from CONNECTED state (ping timeout) error in the console, but after karma receives command to execute tests it works fine.

What bothers me is - why execution of karma internals

navigateContextTo(constant.CONTEXT_URL)

causes Some of your tests did a full page reload! to be thrown. Shouldn't it be ignored same as navigateContextTo('about:blank') ?

@devoto13
Copy link
Collaborator

Without looking too much into details, this sounds pretty similar to #3424. What do you think?

@kamilchlebek
Copy link
Author

kamilchlebek commented Apr 21, 2020

I saw this issue and PR. I didn't want to pollute that discussion.

It seems related, especially that it happened to me randomly.

Assuming that leaving about:blank will not emit beforeunload event. Otherwise will it ever succeed? reloadingContext is always false (with clearContext: true) just before executing navigateContextTo(constant.CONTEXT_URL)

Important note: I was using an iframe mode

Outdated: btw. As I'm still getting DisconnectedClient disconnected from CONNECTED state (ping timeout). Should it ever happen in watch mode? It's not a big issue when running karma in console, but it's inconvenient when using karma inside Webstorm. I have to trigger test twice when this error occurs.

Update

I think I've found a workaround for DisconnectedClient disconnected from CONNECTED state (ping timeout). I've set pingTimeout to be quite big number. It used to be 60s ( #3354 ), now it's only 5s which somehow is randomly not enough. I quess it may be related to angular compilation that happens before tests are executed or something else is blocking heartbeat communication.

@johnjbarton
Copy link
Contributor

While running our unit tests locally I found one of the unit tests passed but then emitted Some of your tests did a full page reload!. This looks like a simple error in the test structure: the error message is emitted to the console via socket.emit('karma_error', message) in the function karma.error() and I guess this results in a message in a later event loop. If the test completes before the event is dequeued, no message; if the test is still running we see the bogus message. I found the results to vary from one run to the next.

Fixing the test is simple, just sinon.stub() rather than sinon.spy().

This doesn't does not explain the issue here, but the flaky nature of the message is maybe related to the socket.emit() logic.

johnjbarton added a commit to johnjbarton/karma that referenced this issue Dec 17, 2020
The error itself does not know abuot navigation.
May fix karma-runner#3482
@johnjbarton
Copy link
Contributor

TBH a lot I thought I knew was wrong: the tests run a browserify version of client/karma.js and static/karma.js to support the test. So depending upon exact commands (build or no), debug logging gives confusing results.

Eventually I sorted out that clearContext is called then the something else calls unload, probably the removal of the iframe when the test is torn down. The onbeforeunload from the clearContext was clearing karmaNavigating so the second call reports the error. That explains why this occurs with clearContext: true.

The onbeforeunload handler has not basis for knowing what navigation is happening. So remove the flag reset.

johnjbarton added a commit that referenced this issue Dec 17, 2020
The unload handler itself does not know about navigation.
May fix #3482
karmarunnerbot pushed a commit that referenced this issue Jan 13, 2021
# [6.0.0](v5.2.3...v6.0.0) (2021-01-13)

### Bug Fixes

* **ci:** abandon browserstack tests for Safari and IE ([#3615](#3615)) ([04a811d](04a811d))
* **client:** do not reset karmaNavigating in unload handler ([#3591](#3591)) ([4a8178f](4a8178f)), closes [#3482](#3482)
* **context:** do not error when karma is navigating ([#3565](#3565)) ([05dc288](05dc288)), closes [#3560](#3560)
* **cve:** update ua-parser-js to 0.7.23 to fix CVE-2020-7793 ([#3584](#3584)) ([f819fa8](f819fa8))
* **cve:** update yargs to 16.1.1 to fix cve-2020-7774 in y18n ([#3578](#3578)) ([3fed0bc](3fed0bc)), closes [#3577](#3577)
* **deps:** bump socket-io to v3 ([#3586](#3586)) ([1b9e1de](1b9e1de)), closes [#3569](#3569)
* **middleware:** catch errors when loading a module ([#3605](#3605)) ([fec972f](fec972f)), closes [#3572](#3572)
* **server:** clean up close-server logic ([#3607](#3607)) ([3fca456](3fca456))
* **test:** clear up clearContext ([#3597](#3597)) ([8997b74](8997b74))
* **test:** mark all second connections reconnects ([#3598](#3598)) ([1c9c2de](1c9c2de))

### Features

* **cli:** error out on unexpected options or parameters ([#3589](#3589)) ([603bbc0](603bbc0))
* **client:** update banner with connection, test status, ping times ([#3611](#3611)) ([4bf90f7](4bf90f7))
* **server:** print stack of unhandledrejections ([#3593](#3593)) ([35a5842](35a5842))
* **server:** remove deprecated static methods ([#3595](#3595)) ([1a65bf1](1a65bf1))
* remove support for running dart code in the browser ([#3592](#3592)) ([7a3bd55](7a3bd55))

### BREAKING CHANGES

* **server:** Deprecated `require('karma').server.start()` and `require('karma').Server.start()` variants were removed from the public API. Instead use canonical form:

```
const { Server } = require('karma');
const server = new Server();
server.start();
```
* **cli:** Karma is more strict and will error out if unknown option or argument is passed to CLI.
* Using Karma to run Dart code in the browser is no longer supported. Use your favorite Dart-to-JS compiler instead.

`dart` file type has been removed without a replacement.

`customFileHandlers` DI token has been removed. Use [`middleware`](http://karma-runner.github.io/5.2/config/configuration-file.html#middleware) to achieve similar functionality.

`customScriptTypes` DI token has been removed. It had no effect, so no replacement is provided.
* **deps:** Some projects have socket.io tests that are version sensitive.
@karmarunnerbot
Copy link
Member

🎉 This issue has been resolved in version 6.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

anthony-redFox pushed a commit to anthony-redFox/karma that referenced this issue May 16, 2023
…nner#3591)

The unload handler itself does not know about navigation.
May fix karma-runner#3482
anthony-redFox pushed a commit to anthony-redFox/karma that referenced this issue May 16, 2023
# [6.0.0](karma-runner/karma@v5.2.3...v6.0.0) (2021-01-13)

### Bug Fixes

* **ci:** abandon browserstack tests for Safari and IE ([karma-runner#3615](karma-runner#3615)) ([04a811d](karma-runner@04a811d))
* **client:** do not reset karmaNavigating in unload handler ([karma-runner#3591](karma-runner#3591)) ([4a8178f](karma-runner@4a8178f)), closes [karma-runner#3482](karma-runner#3482)
* **context:** do not error when karma is navigating ([karma-runner#3565](karma-runner#3565)) ([05dc288](karma-runner@05dc288)), closes [karma-runner#3560](karma-runner#3560)
* **cve:** update ua-parser-js to 0.7.23 to fix CVE-2020-7793 ([karma-runner#3584](karma-runner#3584)) ([f819fa8](karma-runner@f819fa8))
* **cve:** update yargs to 16.1.1 to fix cve-2020-7774 in y18n ([karma-runner#3578](karma-runner#3578)) ([3fed0bc](karma-runner@3fed0bc)), closes [karma-runner#3577](karma-runner#3577)
* **deps:** bump socket-io to v3 ([karma-runner#3586](karma-runner#3586)) ([1b9e1de](karma-runner@1b9e1de)), closes [karma-runner#3569](karma-runner#3569)
* **middleware:** catch errors when loading a module ([karma-runner#3605](karma-runner#3605)) ([fec972f](karma-runner@fec972f)), closes [karma-runner#3572](karma-runner#3572)
* **server:** clean up close-server logic ([karma-runner#3607](karma-runner#3607)) ([3fca456](karma-runner@3fca456))
* **test:** clear up clearContext ([karma-runner#3597](karma-runner#3597)) ([8997b74](karma-runner@8997b74))
* **test:** mark all second connections reconnects ([karma-runner#3598](karma-runner#3598)) ([1c9c2de](karma-runner@1c9c2de))

### Features

* **cli:** error out on unexpected options or parameters ([karma-runner#3589](karma-runner#3589)) ([603bbc0](karma-runner@603bbc0))
* **client:** update banner with connection, test status, ping times ([karma-runner#3611](karma-runner#3611)) ([4bf90f7](karma-runner@4bf90f7))
* **server:** print stack of unhandledrejections ([karma-runner#3593](karma-runner#3593)) ([35a5842](karma-runner@35a5842))
* **server:** remove deprecated static methods ([karma-runner#3595](karma-runner#3595)) ([1a65bf1](karma-runner@1a65bf1))
* remove support for running dart code in the browser ([karma-runner#3592](karma-runner#3592)) ([7a3bd55](karma-runner@7a3bd55))

### BREAKING CHANGES

* **server:** Deprecated `require('karma').server.start()` and `require('karma').Server.start()` variants were removed from the public API. Instead use canonical form:

```
const { Server } = require('karma');
const server = new Server();
server.start();
```
* **cli:** Karma is more strict and will error out if unknown option or argument is passed to CLI.
* Using Karma to run Dart code in the browser is no longer supported. Use your favorite Dart-to-JS compiler instead.

`dart` file type has been removed without a replacement.

`customFileHandlers` DI token has been removed. Use [`middleware`](http://karma-runner.github.io/5.2/config/configuration-file.html#middleware) to achieve similar functionality.

`customScriptTypes` DI token has been removed. It had no effect, so no replacement is provided.
* **deps:** Some projects have socket.io tests that are version sensitive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants