// we can just use the exact same webpack config by requiring it
// however, remember to delete the original entry since we don't
// need it during tests
let webpackConfig = require('./webpack.config.js');
delete webpackConfig.entry;

// karma.conf.js
module.exports = function (config) {
	config.set({
		browsers: [
			'FirefoxHeadless',
			//'ChromiumHeadless',
		],
		customLaunchers: {
			FirefoxHeadless: {
				base: 'Firefox',
				flags: ['-headless']
			}
		},
		frameworks: ['mocha'],
		// this is the entry file for all our tests.
		files: [
			'./test/index.js',
		],
		// we will pass the entry file to webpack for bundling.
		preprocessors: {
			'**/*': [ 'webpack', 'sourcemap' ],
		},
		reporters: [
			'mocha',
			'coverage'
		],

		coverageReporter: {
			dir: './coverage',
			reporters: [
				{ type: 'html', subdir: 'report-html' },
				{ type: 'lcov', subdir: 'report-lcov' },
				{ type: 'cobertura', subdir: '.', file: 'cobertura.txt' },
				{ type: 'lcovonly', subdir: '.', file: 'report-lcovonly.txt' },
				{ type: 'teamcity', subdir: '.', file: 'teamcity.txt' },
				{ type: 'text', subdir: '.', file: 'text.txt' },
				{ type: 'text-summary', subdir: '.', file: 'text-summary.txt' },
			]
		},

		// use the webpack config
		webpack: webpackConfig,
		// avoid walls of useless text
		webpackMiddleware: {
			stats: 'errors-only'
		},
		singleRun: true,
	});
};
