webpacker: Running unit tests with Karma - Error: EACCES: permission denied, mkdir '/_karma_webpack_'

Posting here to see if others are having this issue and if it’s one with the configuration Webpacker creates.

I had this working with many previous versions of the wonderful JavaScript toolchain, but now with the latest of everything, I get

Error: EACCES: permission denied, mkdir '/_karma_webpack_'

The source for karma-webpack seems to be totally wrong, but it’s been like that for 10+ months, so I think there’s a subtly I’m not aware of.

I’m using the latest Webpacker-generated configuration files, with zero changes.

My devDependencies are:

  "devDependencies": {
    "jasmine": "^2.6.0",
    "jasmine-core": "^2.6.2",
    "karma": "^1.7.0",
    "karma-jasmine": "^1.1.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "karma-webpack": "^2.0.3",
    "testdouble": "^2.1.2"
  }

My karma.conf.js looks like:

module.exports = function(config) {
  config.set({
    frameworks: ['jasmine'],
    files: [
      '**/*.spec.js'
    ],
    preprocessors: {
      '**/*.spec.js': [ 'webpack' ]
    },
    webpack: require('../../config/webpack/test.js'),
    browsers: ['PhantomJS'] })
}

If I sudo mkdir /_karma_webpack_ && sudo chmod 777 /_karma_webpack everything works. This is not a great solution, but i have no idea how to change it or why it’s now broken.

Anyone have any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

Oh, and to be specific about what I did:

--- a/config/webpack/shared.js
+++ b/config/webpack/shared.js
@@ -40,8 +40,8 @@ module.exports = {
     new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
     new ManifestPlugin({
       publicPath: output.publicPath,
-      writeToFileEmit: true
-    })
+      writeToFileEmit: env.NODE_ENV !== 'test'
+     })
   ],

(edited, based on @renchap 's comment)

My understanding is the only way to use karma on files that have been run through webpack is to use the karma-webpack preprocessor. My understanding is that it tells karma “use webpack on the files and then make them available to tests”.

I’m not sure what your alternative is - where does the JS you posted go and what is it intended to do? Could be ignorance - I only know what I’ve been able to get to function and what I posted above achieves that after many hours of frustration 😃