lucono/karma-test-explorer

`reporters` in config could be a string

dminkovsky opened this issue · 6 comments

Describe the Bug

This tool expects reporters to be undefined or an array:

(config.reporters ??= []).splice(0, config.reporters.length, reporterName);

However, contrary to the docs, Karma 6.3.16 accepts a single string value for reporters as well. Since my config was configured with a single string value, it would have saved me a lot of time if this tool also accepted single string values.

Steps to Reproduce the Behavior

Use a string value for reporters. See that Karma works, but this tool fails due to the line above.

Describe the Expected Behavior

This tool can accept single string reporter values, like Karma.

Is this a common pattern to simply specify the reporter name string as the karma.conf.js reporters field when there's only one reporter in use? If so, this can be added in a future release. Otherwise, it seems like an unofficial and undocumented karma config API and it may not make sense to add support for it given that the official API is supported and working as expected.

Hi @lucono. I don't know whether there's a common usage like that: this is the first Karma config I've seen and I don't know what the origin of it was in the codebase. I just thought I'd report it, because getting this plugin up was quite challenging with this undocumented setting. I think many people would have given up:

  • The error was hidden (you have to know how to look at and find the correct logs in VSCode)
  • Once I found the error, it was unclear what the problem was (sorry I didn't post the error, but it was something like "splice is undefined" with a trace to the line above).

But, whatever you decide to do with this issue, even if you close it, it'll be searchable on The Web :)

Thank you for this tool! It's been great.

Here's the error. It's in "Karma Server" output:

------------------------------------
Karma Test Explorer: Launching Karma
------------------------------------

16 08 2022 09:29:26.499:ERROR [config]: Error in config file!
 TypeError: (intermediate value)(intermediate value)(intermediate value).splice is not a function
    at lt.addReporter (/Users/dmitry/.vscode/extensions/lucono.karma-test-explorer-0.7.3/dist/karma.conf.js:2:9956)
    at module.exports (/Users/dmitry/.vscode/extensions/lucono.karma-test-explorer-0.7.3/dist/karma.conf.js:2:10571)
    at Object.parseConfig (/Users/dmitry/dev/editor-html/node_modules/karma/lib/config.js:469:26)
    at Object.exports.run (/Users/dmitry/dev/editor-html/node_modules/karma/lib/cli.js:288:26)
    at Object.<anonymous> (/Users/dmitry/dev/editor-html/node_modules/karma/bin/karma:3:23)
    at Module._compile (node:internal/modules/cjs/loader:1163:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1216:10)
    at Module.load (node:internal/modules/cjs/loader:1035:32)
    at Module._load (node:internal/modules/cjs/loader:876:12)
    at Function.c._load (node:electron/js2c/asar_bundle:5:13343)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

@dminkovsky Try out the fix in the beta branch to confirm if it resolves the issue. You can use the vsix from the CI build, or build it yourself from the beta branch.

Seems to be working! :)

Screen Shot 2022-08-24 at 7 18 21 AM

Released in v0.7.4