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

jasmine option "Stop execution on spec failure" does not work properly in combination with karma #218

Closed
maximedupre opened this issue Sep 26, 2018 · 10 comments · Fixed by #231

Comments

@maximedupre
Copy link

Environment

  • Jasmine core : v3.1.0
  • karma-jasmine: v1.1.2
  • Chrome 69
  • Operating System and version (desktop or mobile): OSX 10.13.6

Please see jasmine/jasmine#1576

@johnjbarton
Copy link
Contributor

I guess this will be fixed by #224

@DirkToewe
Copy link
Contributor

DirkToewe commented Dec 4, 2018

Is there any update on this? stopSpecOnExpectationFailure: true is not working for me with jasmine-core@3.3.0 and karma-jasmine@2.0.1. I've also tried oneFailurePerSpec: true, throwOnExpectationFailure: true and failFast: true.

Edit1: Adding jasmineEnv.configure({ oneFailurePerSpec: true }) to createSpecFilter() in adapter.js seems to work.

Edit2: It seems like oneFailurePerSpec: true has to be set, before boot.js is executed. Is there a particular reason for calling jasmineEnv.configure(jasmineConfig) once and not before __karma__.start() is called?

@johnjbarton
Copy link
Contributor

Please run karma with --log-level debug or the equivalent config file value. Check the 'final' config. It should contain 'clientConfig' with oneFailurePerSpec. That value will be sent to jasmine when the start function is created: https://github.com/karma-runner/karma-jasmine/blob/master/src/adapter.js#L366

@DirkToewe
Copy link
Contributor

DirkToewe commented Dec 5, 2018

I had already done that ... kind of ... using console.log inside of karma-jasmine's createStartFn. But just to be sure here's the debug output (prettified):

// ...
{
   "random":true,
   "oneFailurePerSpec":true,
   "failFast":true,
   "timeoutInterval":3600000
}
// ...

I am fairly certain that the config is correct because if I change createStartFn from:

function createStartFn (karma, jasmineEnv) {
  return function () {
    var clientConfig = karma.config || {}
    var jasmineConfig = clientConfig.jasmine || {}
    jasmineEnv = jasmineEnv || window.jasmine.getEnv()
    jasmineEnv.configure(jasmineConfig)
    window.jasmine.DEFAULT_TIMEOUT_INTERVAL = jasmineConfig.timeoutInterval ||
       window.jasmine.DEFAULT_TIMEOUT_INTERVAL
    jasmineEnv.addReporter(new KarmaReporter(karma, jasmineEnv))
    jasmineEnv.execute()
  }
}

to:

function createStartFn (karma, jasmineEnv) {
  var clientConfig = karma.config || {}
  var jasmineConfig = clientConfig.jasmine || {}
  jasmineEnv = jasmineEnv || window.jasmine.getEnv()
  jasmineEnv.configure(jasmineConfig)
  window.jasmine.DEFAULT_TIMEOUT_INTERVAL = jasmineConfig.timeoutInterval ||
     window.jasmine.DEFAULT_TIMEOUT_INTERVAL

  return function () {
    jasmineEnv.addReporter(new KarmaReporter(karma, jasmineEnv))
    jasmineEnv.execute()
  }
}

The behavior is according to oneFailurePerSpec: true. The prior implentation of createStartFn() only calls jasmineEnv.configure(jasmineConfig) as soon as __karma__.start() is called not before boot.js is executed.

@johnjbarton
Copy link
Contributor

Ok thanks. Seems like an unfortunate design here: critical parts of the execution sequence move between two files.

I don't see anything in boot.js that could not be done directly in adapter.js more clearly.

Here is what I would do:

  1. Remove src/adapter.js, adapter.wrapper and build code.
  2. Place the content of boot.js in to lib/adapter.js.
  3. Create a new function configureJasmine(karma, jasmineEnv) with the body of your createStartFn() and call it before the call to createStartFn().
  4. createStartFn() would just be the return you have.

We can start with just 3 and 4.

@DirkToewe
Copy link
Contributor

Okay. I'm gonna file a PR about 3 & 4 as soon as I get to it.

@johnjbarton
Copy link
Contributor

I believe this issue is fixed in karma-jasmine 2.x. Please reopen if you still see it.

@maximedupre
Copy link
Author

Please reopen as it has not been fixed.

rajsite added a commit to rajsite/VireoSDK that referenced this issue Jun 1, 2019
Calling pending only works for beforeEach jasmine/jasmine#1579

And the stopSpecOnExpectationFailure setting only works for node cli. Have to use oneFailurePerSpec for karma-jasmine:
karma-runner/karma-jasmine#218
rajsite added a commit to rajsite/VireoSDK that referenced this issue Jun 1, 2019
Update to karma-jasmine 2 so that the oneFailurePerSpec flag can be enabled so tests can be marked pending if httpbin is offline: karma-runner/karma-jasmine#218
rajsite added a commit to rajsite/VireoSDK that referenced this issue Jun 3, 2019
Calling pending only works for beforeEach jasmine/jasmine#1579

And the stopSpecOnExpectationFailure setting only works for node cli. Have to use oneFailurePerSpec for karma-jasmine:
karma-runner/karma-jasmine#218
rajsite added a commit to rajsite/VireoSDK that referenced this issue Jun 3, 2019
Update to karma-jasmine 2 so that the oneFailurePerSpec flag can be enabled so tests can be marked pending if httpbin is offline: karma-runner/karma-jasmine#218
rajsite added a commit to rajsite/VireoSDK that referenced this issue Jun 3, 2019
Calling pending only works for beforeEach jasmine/jasmine#1579

And the stopSpecOnExpectationFailure setting only works for node cli. Have to use oneFailurePerSpec for karma-jasmine:
karma-runner/karma-jasmine#218
rajsite added a commit to rajsite/VireoSDK that referenced this issue Jun 3, 2019
Update to karma-jasmine 2 so that the oneFailurePerSpec flag can be enabled so tests can be marked pending if httpbin is offline: karma-runner/karma-jasmine#218
@dickinr
Copy link

dickinr commented May 28, 2021

These changes were seemingly reverted as part of #243 but I don't see why?

@DirkToewe
Copy link
Contributor

Sadly the hacky fix made in PR #231 does not work at all anymore with karma-jasmine 2.0.1

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

Successfully merging a pull request may close this issue.

4 participants