karma-runner / karma

Spectacular Test Runner for JavaScript
http://karma-runner.github.io
MIT License
11.95k stars 1.71k forks source link

Array in plugin config fails instanceof Array check #1578

Open unional opened 9 years ago

unional commented 9 years ago

I'm using karma-systemjs and found a bug that most likely an issue on karma side, so want to bring it up to your attention.

In karma-systemjs, it will configure systemjs using a config file. In the config, there is a section with an array:

meta: {
  "*": {
    deps: ['jquery', 'moduleB', ...]
  }
}

karma-systemjs loads the config and pass it to the browser. Before karma, instanceof Array is working fine:

// code simplified console.log(config.meta['*'].deps instanceof Array) => true

But inside karma, it fails:

console.log(
  karma.config.systemjs.config.meta['*'].deps,
  karma.config.systemjs.config.meta['*'].deps instanceof Array);

produces:

LOG: ['jquery', 'moduleB', ...], false

Here is a link to the issue I created on karma-systemjs: https://github.com/rolaveric/karma-systemjs/issues/44

dignifiedquire commented 9 years ago

Thanks for the report, it looks like this should be passed through as an Array, I agree. As far as I know this serialization is handled by socket.io, which should be using JSON.stringify/JSON.parse, but maybe there is some point where things do are not passed as they should be.

unional commented 8 years ago

Hi @Dignifiedquire ,

@nkzawa mentioned instanceof Array does not work across iframe: https://github.com/socketio/socket.io/issues/2234#issuecomment-172320250

http://stackoverflow.com/questions/22289727/difference-between-using-array-isarray-and-instanceof-array

My guess is it is not the case here, as those code are in karam-systemjs and not access through any tests (does tests run in iframe?).

Can you confirm?

dignifiedquire commented 8 years ago

Yes the tests are run inside an iframe, so this might very well be the referenced stackoverflow issue. Did you test with Array.isArray yet?

unional commented 8 years ago

Just to confirm, while tests are run in iframe, do plugins also run in iframe?

The code is run before calling karma.start(), https://github.com/rolaveric/karma-systemjs/blob/master/lib/adapter.js#L80-L104

dignifiedquire commented 8 years ago

That part is run outside the iframe, but the tests are executed inside the iframe

unional commented 8 years ago

Then it should not be iframe issue.

unional commented 8 years ago

@Dignifiedquire , how does karma beam the plugin config up to the client? Is it something similar to what @nkzawa describe? https://github.com/socketio/socket.io/issues/2234#issuecomment-172320211

I'm not familiar with karma code, can out point out where that code is located?

Thanks,