Exclude scss files from karma

I want karma to completely ignore / not care / not pay attention to style files.

I have the following in my webpack configuration, which causes webpack not to import files during build.

plugins: [
    new webpack.IgnorePlugin(/\.(less|scss)$/), // ignore styles when running specs
    new webpack.IgnorePlugin(/client\/utils/), // ignore polyfills
],

However, when Karma starts up, it tries to import, which, of course, will fail:

Uncaught Error: Cannot find module "./view.scss"

I tried to add very strongly the exception swapping to the karma configuration

exclude: [
    {
        pattern: '**/*.less',
        type: 'module',
    },
    {
        pattern: '**/*.scss',
        type: 'module',
    },
]

And I tried ignore-styles (which throws an error out of the box).

I just want it to skip stylesheets because they have nothing to do with tests and just waste time. I don’t understand how so complicated it is.

Error Project Example

https://github.com/jshado1/fetch-mock-test (, npm install ).

:

Uncaught Error: Cannot find module "./test.scss" at webpack:///…/src/client/TestComponent.jsx:3:0
+4
1

webpack.config , karma-webpack, null-loader *.scss.

- :

module: {
    rules: [
      {
        test: /\.scss/,
        use: 'null-loader'
      }
    ]
  }
+3

Source: https://habr.com/ru/post/1693711/


All Articles