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

'Some of your tests did a full page reload!' error between two executions since karma 5.2.0 #3560

Closed
jnizet opened this issue Sep 6, 2020 · 12 comments · Fixed by #3565 or karronoli/redpen#10 · May be fixed by PDSSnyk/juice-shop#74
Closed
Labels

Comments

@jnizet
Copy link

jnizet commented Sep 6, 2020

Since version 5.2.0, in watch mode, every time an Angular test suite re-executes after some change is saved in a file, I get the following log in the console:

ERROR
Some of your tests did a full page reload!

The tests run fine and pass, but this error is logged between executions.

Here's a reproduction project: https://github.com/jnizet/karmarepro

To reproduce:

  • clone the project
  • yarn
  • ng test
  • change some test description in src/app/app.component.spec.ts and save file
  • look at the error appearing in the console.

Note that this project has just been created by

  • using ng new to create a new Angular project
  • changing the version numbers of all test-related dependencies in package.json

So I doubt the tests actually do a full page reload as the error message claims.

@johnjbarton
Copy link
Contributor

The error message is emitted by an beforeunload event handler:

this.onbeforeunload = function () {

Run the test with --no-single-run and open chrome devtools. Set a breakpoint on the handler above and reproduce. You should see the action that causes your issue.

@jnizet
Copy link
Author

jnizet commented Sep 8, 2020

@johnjbarton I don't think there is any issue in my code (which, BTW, isn't even my code, but the standard code generated by Angular CLI).

Even if I reduce the test to the following:

describe('AppComponent', () => {
  it('should work', () => {
    expect(true).toBeTruthy();
  });
});

, any change made to the test causes the error to be displayed between the two executions. And the error message is not dispayed when using a version older than 5.2.0, so I think it's a regression.

Here's the stack trace when I put the breakpoint where you asked:

Karma.onbeforeunload (karma.js:142)
directCallParentKarmaMethod (context.js:288)
contextWindow.onbeforeunload (context.js:219)
navigateContextTo (karma.js:135)
allowClearContextToComplete (karma.js:278)
setTimeout (async)
(anonymous) (karma.js:273)
r.emit (index.js:83)
r.onevent (index.js:83)
r.onpacket (index.js:83)
(anonymous) (index.js:83)
r.emit (index.js:83)
r.ondecoded (index.js:83)
(anonymous) (index.js:83)
r.emit (index.js:83)
a.add (index.js:83)
r.ondata (index.js:83)
(anonymous) (index.js:83)
r.emit (index.js:83)
r.onPacket (index.js:83)
(anonymous) (index.js:83)
r.emit (index.js:83)
r.onPacket (index.js:83)
r.onData (index.js:83)
ws.onmessage (index.js:83)

@johnjbarton
Copy link
Contributor

Please try setting client.clearContext true in your config.

every time an Angular test suite re-executes after some change is saved in a file

Is this specific to Angular or just karma file-watch feature?

@jnizet
Copy link
Author

jnizet commented Sep 8, 2020

client.clearContextset to true makes the error message disappear. But it has the side effect of making the html test report disappear from the browser window. That's apparently why it's set to false, since the karma.conf.js generated by the Angular CLI says:

    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    }

It's still good to know though, because my actual project uses a headless browser anyway.

Is this specific to Angular or just karma file-watch feature?

It's not specific to Angular. As soon as client.clearContext is true, the error appears between two test executions. Here's a repro created with karma init and containing only a trivial jasmine test written in JS: https://github.com/jnizet/karma-repro2.

@nicojs
Copy link
Contributor

nicojs commented Sep 30, 2020

I'm pretty sure it's a regression. We can see it clearly in Stryker, where we rerun the karma instance in fast succession.

I see this line is removed in #3452 :

    // if not clearing context, reloadingContext always true to prevent beforeUnload error
    reloadingContext = !self.config.clearContext

If I add that line back Karma works again as expected.

@johnjbarton did you deliberately remove this? Or got it lost in translation?

@johnjbarton
Copy link
Contributor

@nicojs I think something else must be going on here.
This line

   reloadingContext = !self.config.clearContext

will prevent the onbeforeunload error message in all cases if self.config.clearContext == true. We want to the error if the page does attempt a reload, whether or not the clearContext feature is enabled. To say this another way, we don't want to disable the message for users of clearContext.

johnjbarton added a commit to johnjbarton/karma that referenced this issue Oct 1, 2020
Change the flag name to karmaNavigating and set it along all paths where
karma deliberately navigates. Other paths must be wrong.

Fixes karma-runner#3560
johnjbarton added a commit to johnjbarton/karma that referenced this issue Oct 1, 2020
Change the flag name to karmaNavigating and set it along all paths where
karma deliberately navigates. Other paths must be wrong.

Fixes karma-runner#3560
johnjbarton added a commit to johnjbarton/karma that referenced this issue Oct 2, 2020
Change the flag name to karmaNavigating and set it along all paths where
karma deliberately navigates. Other paths must be wrong.

Fixes karma-runner#3560
johnjbarton added a commit to johnjbarton/karma that referenced this issue Oct 5, 2020
Change the flag name to karmaNavigating and set it along all paths where
karma deliberately navigates. Other paths must be wrong.

Fixes karma-runner#3560
johnjbarton added a commit to johnjbarton/karma that referenced this issue Oct 5, 2020
Change the flag name to karmaNavigating and set it along all paths where
karma deliberately navigates. Other paths must be wrong.

Fixes karma-runner#3560
johnjbarton added a commit to johnjbarton/karma that referenced this issue Oct 5, 2020
Change the flag name to karmaNavigating and set it along all paths where
karma deliberately navigates. Other paths must be wrong.

Fixes karma-runner#3560
johnjbarton added a commit to johnjbarton/karma that referenced this issue Oct 6, 2020
Change the flag name to karmaNavigating and set it along all paths where
karma deliberately navigates. Other paths must be wrong.

Fixes karma-runner#3560
johnjbarton added a commit that referenced this issue Oct 6, 2020
Change the flag name to karmaNavigating and set it along all paths where
karma deliberately navigates. Other paths must be wrong.

Fixes #3560
@jnizet
Copy link
Author

jnizet commented Oct 6, 2020

Thanks for the fix @johnjbarton

gkalpak added a commit to gkalpak/angular that referenced this issue Nov 7, 2020
…5.2.0

This commit downgrades `karma` to version 5.1.1, because of a regression
in version 5.2.0: karma-runner/karma#3560
It has been fixed with karma-runner/karma@05dc28801627e3ce7054 on
master, but the fix is not included in the latest release (v5.2.3).
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 7, 2020
…5.2.0

This commit downgrades `karma` to version 5.1.1, because of a regression
in version 5.2.0: karma-runner/karma#3560
It has been fixed with karma-runner/karma@05dc28801627e3ce7054 on
master, but the fix is not included in the latest release (v5.2.3).
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 9, 2020
…5.2.0

This commit downgrades `karma` to version 5.1.1, because of a regression
in version 5.2.0: karma-runner/karma#3560
It has been fixed with karma-runner/karma@05dc28801627e3ce7054 on
master, but the fix is not included in the latest release (v5.2.3).
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 18, 2020
…5.2.0

This commit downgrades `karma` to version 5.1.1, because of a regression
in version 5.2.0: karma-runner/karma#3560
It has been fixed with karma-runner/karma@05dc28801627e3ce7054 on
master, but the fix is not included in the latest release (v5.2.3).
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 18, 2020
…5.2.0

This commit downgrades `karma` to version 5.1.1, because of a regression
in version 5.2.0: karma-runner/karma#3560
It has been fixed with karma-runner/karma@05dc28801627e3ce7054 on
master, but the fix is not included in the latest release (v5.2.3).
gkalpak added a commit to gkalpak/angular that referenced this issue Nov 18, 2020
…5.2.0

This commit downgrades `karma` to version 5.1.1, because of a regression
in version 5.2.0: karma-runner/karma#3560
It has been fixed with karma-runner/karma@05dc28801627e3ce7054 on
master, but the fix is not included in the latest release (v5.2.3).
AndrewKushnir pushed a commit to angular/angular that referenced this issue Nov 18, 2020
…5.2.0 (#39600)

This commit downgrades `karma` to version 5.1.1, because of a regression
in version 5.2.0: karma-runner/karma#3560
It has been fixed with karma-runner/karma@05dc28801627e3ce7054 on
master, but the fix is not included in the latest release (v5.2.3).

PR Close #39600
AndrewKushnir pushed a commit to angular/angular that referenced this issue Nov 18, 2020
…5.2.0 (#39600)

This commit downgrades `karma` to version 5.1.1, because of a regression
in version 5.2.0: karma-runner/karma#3560
It has been fixed with karma-runner/karma@05dc28801627e3ce7054 on
master, but the fix is not included in the latest release (v5.2.3).

PR Close #39600
@nicojs
Copy link
Contributor

nicojs commented Dec 23, 2020

@johnjbarton this fix still seems unreleased. Could we release this? Stryker users are reporting issues.

@johnjbarton
Copy link
Contributor

We are working on a release now

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
Change the flag name to karmaNavigating and set it along all paths where
karma deliberately navigates. Other paths must be wrong.

Fixes karma-runner#3560
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.
@ShaMan123
Copy link

client.clearContextset to true makes the error message disappear. But it has the side effect of making the html test report disappear from the browser window. That's apparently why it's set to false, since the karma.conf.js generated by the Angular CLI says:

    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    }

It's still good to know though, because my actual project uses a headless browser anyway.

Is this specific to Angular or just karma file-watch feature?

It's not specific to Angular. As soon as client.clearContext is true, the error appears between two test executions. Here's a repro created with karma init and containing only a trivial jasmine test written in JS: https://github.com/jnizet/karma-repro2.

Seems to fix:

    client: {
      clearContext: config.singleRun // leave Jasmine Spec Runner output visible in browser
    }

@yasinkocak
Copy link

yasinkocak commented Sep 6, 2024

When i use jasmine-spec-reporter i get this error, when i remove this reporter error is gone, last update of this 3 years ago

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