// @flow
/* eslint-disable global-require, import/no-dynamic-require */

// import fs from 'fs';
import path from 'path';
import defaultsDeep from 'lodash/defaultsDeep';
import * as reporters from '../reporters';

export const defaultConfig = {
  tests: [],
  testUrl: null,
  server: {
    host: '0.0.0.0',
    port: 3090,
  },
  storage: {
    baseline: 'vrtest/baseline',
    output: 'vrtest/output',
  },
  selenium: {},
  profiles: [],
  reporters: [],
};

export function readConfig(overrides?: Object = {}): vrtest$Config {
  let config = overrides;

  if (typeof config === 'string') {
    // $FlowFixMe
    config = require(path.resolve(process.cwd(), config));
  }

  if (config.tests && !Array.isArray(config.tests)) {
    config.tests = [config.tests];
  }

  if (config.reporters && !Array.isArray(config.reporters)) {
    config.reporters = [config.reporters];
  } else if (!config.reporters || !config.reporters.length) {
    config.reporters = [reporters.spec];
  }

  if (!config.testUrl) {
    config.testUrl = `http://${config.server.host}:${config.server.port}`;
  }

  return defaultsDeep({}, config, defaultConfig);
}

@@ -978,22 +978,93 @@
 %0A  %7D%0A%0A  
-if (!c
+const mergedConfig = defaultsDeep(%7B%7D, config, defaultConfig);%0A%0A  if (!mergedC
 onfig.te
@@ -1068,33 +1068,39 @@
 .testUrl) %7B%0A    
-c
+mergedC
 onfig.testUrl = 
@@ -1109,17 +1109,23 @@
 ttp://$%7B
-c
+mergedC
 onfig.se
@@ -1137,17 +1137,23 @@
 host%7D:$%7B
-c
+mergedC
 onfig.se
@@ -1183,47 +1183,20 @@
 urn 
-defaultsDeep(%7B%7D, config, default
+merged
 Config
-)
 ;%0A%7D%0A

Fix config merging