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

Using 'window.__karma__.info()` API to send arbitrary objects to the server does not work #2192

Closed
devanshah1 opened this issue Jun 25, 2016 · 20 comments · Fixed by #2637 or karronoli/redpen#10 · May be fixed by Omrisnyk/npm-lockfiles#122, Omrisnyk/npm-lockfiles#132 or satoshinakamoto007/bitcore#1135

Comments

@devanshah1
Copy link

devanshah1 commented Jun 25, 2016

Expected behavior

Expect the info emitter to be dispatched which is set in the reporter. The reporter is expected to write to console a message. Refer to: https://groups.google.com/forum/#!topic/karma-users/ShR96TcKm6Q

Actual behavior

Nothing is written to the terminal/console.

Enviroment Details

Steps to reproduce the behaviour

  1. Clone Repo: https://github.com/devanshah1/sample
  2. Run bash npm install in repo folder
  3. Run bash npm install src in repo folder
  4. Run npm test in repo folder
  5. Now in the console you should see "info emitter was called and following is the object" printed if the info event was triggered
@devanshah1 devanshah1 changed the title Using 'window.__karma__.info()` API to send arbitrary objects to the server, the info emitter is not dispatched through reporter Using 'window.__karma__.info()` API to send arbitrary objects to the server does not work Jun 27, 2016
@devanshah1
Copy link
Author

devanshah1 commented Jun 29, 2016

Any one have an idea?

@devanshah1
Copy link
Author

devanshah1 commented Jul 3, 2016

@dignifiedquire Are you aware of any karma reporter plugins which are using the window.karma.info API?

@dignifiedquire
Copy link
Member

@devanshah1 I know of nothing that actually uses this api I'm afraid

@devanshah1
Copy link
Author

@dignifiedquire Do you know of any other way to send arbitrary objects to the server from the client?

@devanshah1
Copy link
Author

@dignifiedquire I started taking a look at this issues and had a quick question regarding it, in terms of how it should be used? When you call the window.karma.info() API would it be able to be picked up by any reporter that is registered. And Also would the API only work if where you are calling it from is part of a karma start function.

@devanshah1
Copy link
Author

@dignifiedquire would you be able to provide some context in terms of how the actual socket call is made, I see that the emmiter is from the karma.js file, but how is this actually emmited for reporter to pick up. By the looks of it is through socket.io, like just wanted to figure out if the following from https://github.com/karma-runner/karma/blob/master/client/karma.js is actually called or not:

  this.info = function (info) {
    // TODO(vojta): introduce special API for this
    if (!startEmitted && util.isDefined(info.total)) {
      socket.emit('start', info)
      startEmitted = true
    } else {
      socket.emit('info', info)
    }
  }

@dignifiedquire
Copy link
Member

It is called and should be working afaict. But I have never tried to use it so there might be issues with it.

@devanshah1
Copy link
Author

@dignifiedquire If I was to use socket.io on client side and dispatch an custom event and then have the reporter listening on this event, would this work?

@devanshah1
Copy link
Author

@dignifiedquire any idea on an ETA, in terms of if this is in fact an issues in Karma or something I am doing that is wrong to use the actual API?

@surya66
Copy link

surya66 commented Sep 8, 2016

I am also seeing the same issue with this API, is there a ETA on this?

@devanshah1
Copy link
Author

devanshah1 commented Dec 13, 2016

@dignifiedquire @wesleycho @maksimr I used the localStorage.debug = '*'; option in the browser to enable the logs in karma to see if the info emit was going through, I did see that the emit was dispatch. Do you happen to know where I can look to verify if the reporter has received it or to verify if the emmiter is registered from the reporter.

@devanshah2
Copy link

@dignifiedquire @wesleycho @maksimr Not sure if you have had a change to take a look at this one.

@maksimr maksimr self-assigned this Mar 29, 2017
@maksimr
Copy link
Contributor

maksimr commented Mar 29, 2017

After some investigation, I think it never worked as you want.
Browser emits only 'browser_log' event.
Yes, all log information implemented through 'info' event.

Answers to questions:

Are you aware of any karma reporter plugins which are using the window.karma.info API?

Yes, karma itself because karma sends console.log through info method.

Do you know of any other way to send arbitrary objects to the server from the client?

As a workaround(hack), you can inject executor to your reporter and use sockets directly.

how it should be used?

As in your example, only the event will be named as 'browser_info'.

client:

 window.__karma__.info({foo: 'foo'});

server/backend:

emitter.on('browser_info', () => {});

@dignifiedquire If I was to use socket.io on client side and dispatch an custom event and then have the reporter listening on this event, would this work?

No, because emitter is not socket, only browser subscribed on all sockets events so you could create custom method in custom browser launcher like 'onFoo' and send event 'foo'.

API would it be able to be picked up by any reporter that is registered

No matter reporter, browser or another code. If you inject emitter and subscribe on 'browser_info' you will receive event.

And Also would the API only work if where you are calling it from is part of a karma start function.

I think it will be called only if browser starts to execute tests as It was done for 'browser_log'

By the looks of it is through socket.io, like just wanted to figure out if the following from https://github.com/karma-runner/karma/blob/master/client/karma.js is actually called or not:

Yes, it works

any idea on an ETA, in terms of if this is in fact an issues in Karma or something I am doing that is wrong to use the actual API?

I will try add such functionality soon

cc @devanshah1 @devanshah2

@devanshah1
Copy link
Author

@maksimr Thanks a lot for taking a look at this. So the PR that you added I should be able to add

emitter.on('browser_info', () => {});

to the reporter and then on the client side stilling having:

window.__karma__.info({foo: 'foo'});

will make things work right?

@maksimr
Copy link
Contributor

maksimr commented Mar 29, 2017

@devanshah1 yup

@devanshah1
Copy link
Author

@maksimr Awesome thanks a lot for this PR

@devanshah1
Copy link
Author

@dignifiedquire @maksimr Any idea on when this can be released?

@dignifiedquire
Copy link
Member

I will try to make a release over the weekend

@devanshah1
Copy link
Author

@dignifiedquire Thanks a lot

@devanshah1
Copy link
Author

@dignifiedquire @maksimr Thanks a lot for this, works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment