Exclude files from test

I am using code to request all src files except main.js for coverage. I need to add another file to ignore or ignore all files that have this extension.

const srcContext = require.context('../../src/renderer', true, /^\.\/(?!main(\.js)?$)/)

      

This is what I am using, I also need to exclude _icons.scss or exclude all .scss from coverage. I tried to implement some new regex but it doesn't work as expected

Thank!

+3


source to share


1 answer


You can use the following updated template:

/^\.\/(?!(?:main(\.js)?|.*\.scss)$)/
         ^^^           ^^^^^^^^^^

      

The key here is to add an alternative to the part that matches the filenames after ./

.



Details of the template :

  • ^

    - beginning of line
  • \.\/

    - literal substring ./

  • (?!(?:main(\.js)?|.*\.scss)$)

    - a negative result that does not match if the following patterns match:
    • (?:main(\.js)?|.*\.scss)

      - substrings main

      or main.js

      (at the end of the string)
    • |

      - or
    • .*\.scss

      - any 0+ characters other than line break characters ( .*

      ) up to the last substring .scss

      that is on ...
    • $

      - end of line.
+1


source







All Articles