"use strict";

var _fs = require("fs");

var _path = _interopRequireDefault(require("path"));

var _libAlias = require("./libAlias");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const appPath = process.cwd();

const appGlobals = _path.default.resolve(appPath, '__testUtils__', 'globals.js');

const commonConfig = {
  coverageReporters: ['json', 'html', 'json-summary', 'text'],
  collectCoverage: true,
  moduleDirectories: [_path.default.resolve(__dirname, '..', '..', 'node_modules'), 'node_modules'],
  transform: {
    '^.+\\.(js|jsx|ts|tsx)$': _path.default.resolve(__dirname, '..', 'jest', 'preProcessors', 'jsPreprocessor.js'),
    '^.+\\.css$': _path.default.resolve(__dirname, '..', 'jest', 'preProcessors', 'cssPreprocessor.js'),
    '^(?!.*\\.(js|jsx|css|json)$)': _path.default.resolve(__dirname, '..', 'jest', 'preProcessors', 'otherFilesPreprocessor.js')
  },
  moduleNameMapper: _libAlias.jestModuleNameMapper,
  // moduleNameMapper: {
  //   ...moduleNameMapper,
  //   '\\.(css|less)$': 'identity-obj-proxy'
  // },
  transformIgnorePatterns: ['/node_modules/(?!(@zohodesk|@zohodesk-private)/)'],
  // transformIgnorePatterns: ['/node_modules.*?.js$'],
  moduleFileExtensions: ['js', 'ts', 'tsx'],
  setupFiles: [(0, _fs.existsSync)(appGlobals) && appGlobals, _path.default.resolve(__dirname, '..', 'jest', 'setup.js')].filter(Boolean),
  globals: {
    __DEVELOPMENT__: true,
    __DOCS__: false,
    __TEST__: true
  }
};

module.exports = (...args) => {
  const [appFolder, forCommittedFiles = false] = args;

  if (forCommittedFiles) {
    return Object.assign({}, commonConfig, {
      coverageDirectory: _path.default.resolve(appPath, 'commitCoverage'),
      testResultsProcessor: _path.default.resolve(__dirname, '..', 'jest', 'commitedFilesResult.js')
    });
  }

  return Object.assign({}, commonConfig, {
    rootDir: appPath,
    testPathIgnorePatterns: ['/node_modules/', 'docs'],
    unmockedModulePathPatterns: ['__tests__', 'node_modules', '.*'],
    roots: [`<rootDir>/${appFolder}/`],
    testRegex: '(/__tests__/.*|\\.(test|spec))\\.(jsx|js|json|node|ts|tsx)$',
    testResultsProcessor: _path.default.resolve(__dirname, '..', 'jest', 'result.js')
  });
};