Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

karma-webpack plugin: where does the bundle file go?

I am using Karma with the karma-webpack plugin for bundling and transpiling with babel. When a test has an error, I get a nice message with a line number for the bundle, like the following:

Service: DocumentService

✗ gets the correct number of advisors clients

TypeError: undefined is not an object (evaluating 'GLOBALS.TESTING_ENV') (line 37)

This is great, but I cannot find where to access the bundle file and inspect the lines described.

I tried using the output option in the webpack config, but that doesn't seem to do anything.

Here is my karma.conf:

module.exports = function(config) {
  config.set({

    basePath: __dirname + '/',

    frameworks: ['phantomjs-shim', 'jasmine'],

    files: [
      './test/**/*spec.js'
    ],
    
    preprocessors: {
      'src/**/*.js': ['webpack'],
      'test/**/*.js': ['webpack']
    },

    webpack: {
      mode: 'development',
      output: {
          path: path.resolve(__dirname, './build/'),
          filename: 'app-[name].js',
          chunkFilename: 'app-vendors.[chunkhash].js'
      },
      module: {
        rules: [
          {
            test: /\.js$/,
            exclude: /node_modules/,
            use: ['babel-loader']
          }
        ]
      }
    },

    reporters: ['spec'],

    specReporter: {
      suppressErrorSummary: false,
      suppressFailed: false,
      suppressPassed: false,
      suppressSkipped: false,
      showSpecTiming: false,
      failFast: false 
    },

    autoWatch: false,

    browsers: ['PhantomJS'],

    singleRun: true,
    
    ...

  })
}

Where does the test bundle file build to? Is there a way I can configure it so that I can inspect the bundle?

like image 550
mhatch Avatar asked Nov 07 '22 17:11

mhatch


1 Answers

Struggled with this as well and after revisiting this issue I finally solved it for me.

The files are not written to the disk because karma uses webpack-dev-middleware by default which keeps all files in memory. If you want the files to be emitted to the filesystem try

webpackMiddleware: {
  writeToDisk: true,
}

Though in its current version karma-webpack overrides the output path with path.join(os.tmpdir(), '_karma_webpack_', indexPath, '/').

like image 86
epsilon Avatar answered Nov 15 '22 08:11

epsilon