Skip to content

ERROR [karma-server]: UnhandledRejection when updated to 5.0 #367

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

Closed
rinick opened this issue Mar 14, 2020 · 9 comments
Closed

ERROR [karma-server]: UnhandledRejection when updated to 5.0 #367

rinick opened this issue Mar 14, 2020 · 9 comments
Labels

Comments

@rinick
Copy link

rinick commented Mar 14, 2020

my unit tests worked fine with 4.x, and it also worked fine with 5.0 beta-1
but when switching to 5.0 release or 5.0 beta-3, it always show this error after all the tests are passed.

HeadlessChrome 80.0.3987 (Windows 10.0.0): Executed 231 of 231 SUCCESS (9.106 secs / 8.064 secs)
13 03 2020 17:37:51.532:ERROR [karma-server]: UnhandledRejection

any idea how I can trouble shoot this?

@erikbarke erikbarke added the bug label Mar 14, 2020
@erikbarke
Copy link
Collaborator

Do you have an example repo?

@christophercr
Copy link

christophercr commented Mar 14, 2020

@erikbarke I have the exact same issue, and when adding an error handler as suggested in karma-runner/karma#3378 (comment) (@rinick perhaps you can also do that to trouble shoot your problem), I'm able to see the actual error:

TypeError: Cannot read property 'push' of undefined
    at _reporters.forEach (C:\projectPath\node_modules\karma\lib\reporters\multi.js:13:24)
    at Array.forEach (<anonymous>)
    at MultiReporter.addAdapter (C:\projectPath\node_modules\karma\lib\reporters\multi.js:11:21)
    at Server.<anonymous> (C:\projectPath\node_modules\karma\lib\middleware\runner.js:41:18)
    at Object.onceWrapper (events.js:286:20)
    at Server.emit (events.js:203:15)
    at Executor.schedule (C:\projectPath\node_modules\karma\lib\executor.js:30:20)
    at C:\projectPath\node_modules\karma\lib\middleware\runner.js:92:22
    at tryCatcher (C:\projectPath\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\projectPath\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (C:\projectPath\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromise0 (C:\projectPath\node_modules\bluebird\js\release\promise.js:649:10)
    at Promise._settlePromises (C:\projectPath\node_modules\bluebird\js\release\promise.js:729:18)
    at Promise._fulfill (C:\projectPath\node_modules\bluebird\js\release\promise.js:673:18)
    at Promise._resolveCallback (C:\projectPath\node_modules\bluebird\js\release\promise.js:466:57)
    at Promise._settlePromiseFromHandler (C:\projectPath\node_modules\bluebird\js\release\promise.js:559:17)

The code that fails is this line: https://github.com/karma-runner/karma/blob/a673aa8ad76f733565498f2aab13fcd720502be1/lib/reporters/multi.js#L11 because the karma-typescript reporter has no adapters property.

Another thing that I have different compared to your Angular demo is the version of karma-jasmine. That one uses: "^2.0.1 whereas in my app I use version "^3.1.0"... but I'm not sure whether this is part of the root cause of the issue.

@rinick
Copy link
Author

rinick commented Mar 15, 2020

my issue is resolved, thanks to @christophercr 's suggestion.

the issue is caused by lvoconly report

        "lcovonly": {
          "directory": "coverage",
          "subdirectory": "chrome",
          "filename": "karma"
        }

I guess it was a bug in previous version, even I ask for filename karma, previous version still generated another layer of karma subfolder, then put lcov result in it.

latest version actually fixed it, but it failed to write to that file, because a folder with same name already exists.

after deleting the folder the UnhandledRejection is gone

@erikbarke
Copy link
Collaborator

Thanks guys, I've been able to reproduce at least the error @rinick gets by creating a folder with the same name as the lcov file and using the lcovonly report:

infrastructure_error Error: EISDIR: illegal operation on a directory, open '/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/coverage/chrome/karma'
    at Object.openSync (fs.js:457:3)
    at FileWriter.writeFile (/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/node_modules/istanbul-lib-report/lib/file-writer.js:185:41)
    at LcovOnlyReport.onStart (/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/node_modules/istanbul-reports/lib/lcovonly/index.js:17:45)
    at Visitor.value (/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/node_modules/istanbul-lib-report/lib/tree.js:38:38)
    at ReportTree.visit (/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/node_modules/istanbul-lib-report/lib/tree.js:126:17)
    at LcovOnlyReport.execute (/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/node_modules/istanbul-lib-report/lib/report-base.js:12:44)
    at /Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/node_modules/karma-typescript/src/karma/reporter.ts:79:30
    at Array.forEach (<anonymous>)
    at Reporter.create.<anonymous> (/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/node_modules/karma-typescript/src/karma/reporter.ts:59:49)
    at step (/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/node_modules/karma-typescript/dist/karma/reporter.js:33:23)
    at Object.next (/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/node_modules/karma-typescript/dist/karma/reporter.js:14:53)
    at fulfilled (/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/node_modules/karma-typescript/dist/karma/reporter.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  errno: -21,
  syscall: 'open',
  code: 'EISDIR',
  path: '/Users/erikbarke/Development/npm/monounity/karma-typescript/examples/angular2/coverage/chrome/karma'
}

Since this was caused by a bug in an earlier beta version I'm not sure there's anything to fix here, the istanbul reporter is already throwing an error about an "illegal operation on a directory", and having a coverage reporter deleting sub directories is probably a bad thing 🤔

On the other hand, I haven't been able to reproduce your error, @christophercr, what are the steps, do you have an example repo?

@christophercr
Copy link

christophercr commented Mar 16, 2020

@erikbarke I did more troubleshooting and now I know why I get the error. It is because I run the tests via my IDE (IntelliJ - WebStorm) and for some reason, the execution reaches this line: https://github.com/karma-runner/karma/blob/a673aa8ad76f733565498f2aab13fcd720502be1/lib/reporters/multi.js#L11.

However, if I run the tests in a terminal, they work just fine as that line of code is never reached.

Do you think you could add an adapters property to the karma-typescript reporter so that running from an IDE is supported? In my case I find it really useful to run them via the IDE cause there I get more structured and colored output and also I can even go directly to the code of the failing tests by doing Ctrl+click.

You could define the adapters property the same way as the BaseReporter does in Karma: https://github.com/karma-runner/karma/blob/a673aa8ad76f733565498f2aab13fcd720502be1/lib/reporters/base.js#L9. What do you think?

@erikbarke
Copy link
Collaborator

@christophercr, yes, this is probably a good idea and it seems the best way to add these kinds of properties is by using the baseReporterDecorator that Karma provides.

@erikbarke
Copy link
Collaborator

@christophercr, does the fix in #368 work for you?

@christophercr
Copy link

Yes, that does the trick! Then it works like a charm on Webstorm!

Thanks for the fix 😉

erikbarke added a commit that referenced this issue Mar 20, 2020
Use correct 'this' for base reporter, fixes #367
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@rinick @erikbarke @christophercr and others