karma icon indicating copy to clipboard operation
karma copied to clipboard

Glob Brace Expansion Doesn't Work For `config.files`

Open npetruzzelli opened this issue 3 years ago • 1 comments

I want to run & preprocess files for the following extensions:

  • .cjs
  • .js
  • .jsx
  • .mjs
  • .ts
  • .tsx

I can accomplish this with a single preprocessors entry, but I need at least two files entries.


  config.set({
    // ... other config
    files: [
      {pattern: 'src/**/*.test.[jt]s?(x)', watched: false}, // js | jsx | ts | tsx
      {pattern: 'src/**/*.test.[cm]js', watched: false} // cjs | mjs
    ],
    preprocessors: {
      'src/**/*.test.{[jt]s?(x),[cm]js}': ['webpack'], // All 6 extensions
    },
  })

Setting aside the unlikelihood of any single project ever needing to work with all these extensions: as far as I can tell, brace expansion seems to be disabled for files. Is this intentional or a bug?

The docs don't say anything on the matter, one way or the other, though I'm leaning towards this is bug thanks to the following:

... all the patterns will get resolved into files using glob, so you can use minimatch expressions

Both Glob and Minimatch have support for brace expansion.

I've been digging around in the code to try to get more information, but I'm not yet sure I have the correct files to dive deeper into.

npetruzzelli avatar Feb 26 '21 19:02 npetruzzelli

I think it is just for historical reasons. And I agree that it would make sense to support braces expansion in files as well.

AFAICT preprocessors use minimatch, but files use glob. Maybe just a matter to pass a flag, because they have different defaults, not sure. In any case, PR would be welcome to allow brace expansions for files. But note that it is a pretty dangerous change, so we'll probably hold with the merge until the next major.

devoto13 avatar Mar 04 '21 20:03 devoto13