How to use jest-config - 10 common examples

To help you get started, we’ve selected a few jest-config examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kulshekhar / ts-jest / tests / __helpers__ / test-utils.ts View on Github external
argv: Arguments,
): null | JestConfigNormalize {
  /* tslint:disable */
  const R_OK = (fs.constants && fs.constants.R_OK) || (fs['R_OK'] as number);
  /* tslint:enable */
  try {
    fs.accessSync(filePath, R_OK);
  } catch (e) {
    return null;
  }

  const packageData = require(filePath);
  const config = packageData.jest || {};
  const root = path.dirname(filePath);
  config.rootDir = config.rootDir ? path.resolve(root, config.rootDir) : root;
  return normalize(config, argv);
}
github kulshekhar / ts-jest / tests / __helpers__ / test-utils.ts View on Github external
function readRawConfig(argv: Arguments, root: string): JestConfigNormalize {
  const rawConfig = parseConfig(argv);

  if (typeof rawConfig === 'string') {
    return loadJestConfigFromFile(path.resolve(process.cwd(), rawConfig), argv);
  }

  if (typeof rawConfig === 'object') {
    const config = Object.assign({}, rawConfig);
    config.rootDir = config.rootDir || root;
    return normalize(config, argv);
  }

  // Rawconfig is undefined
  const packageConfig = loadJestConfigFromPackage(
    path.join(root, 'package.json'),
    argv,
  );
  return packageConfig || normalize({ rootDir: root }, argv);
}
github kulshekhar / ts-jest / tests / __helpers__ / test-utils.ts View on Github external
if (typeof rawConfig === 'string') {
    return loadJestConfigFromFile(path.resolve(process.cwd(), rawConfig), argv);
  }

  if (typeof rawConfig === 'object') {
    const config = Object.assign({}, rawConfig);
    config.rootDir = config.rootDir || root;
    return normalize(config, argv);
  }

  // Rawconfig is undefined
  const packageConfig = loadJestConfigFromPackage(
    path.join(root, 'package.json'),
    argv,
  );
  return packageConfig || normalize({ rootDir: root }, argv);
}
github facebook / jest / packages / jest-core / src / cli / index.ts View on Github external
): Promise<{
  results: AggregatedResult;
  globalConfig: Config.GlobalConfig;
}> => {
  const realFs = require('fs');
  const fs = require('graceful-fs');
  fs.gracefulify(realFs);

  let results: AggregatedResult | undefined;

  // If we output a JSON object, we can't write anything to stdout, since
  // it'll break the JSON structure and it won't be valid.
  const outputStream =
    argv.json || argv.useStderr ? process.stderr : process.stdout;

  const {globalConfig, configs, hasDeprecationWarnings} = readConfigs(
    argv,
    projects,
  );

  if (argv.debug) {
    logDebugMessages(globalConfig, configs, outputStream);
  }

  if (argv.showConfig) {
    logDebugMessages(globalConfig, configs, process.stdout);
    exit(0);
  }

  if (argv.clearCache) {
    configs.forEach(config => {
      rimraf.sync(config.cacheDirectory);
github apollographql / apollo-server / jest.config.base.js View on Github external
const { defaults } = require("jest-config");

module.exports = {
  testEnvironment: "node",
    setupFiles: [
      "/../apollo-server-env/dist/index.js"
    ],
    preset: "ts-jest",
    testMatch: null,
    testRegex: "/__tests__/.*\\.test\\.(js|ts)$",
    testPathIgnorePatterns: [
      "/node_modules/",
      "/dist/"
    ],
    moduleFileExtensions: [...defaults.moduleFileExtensions, "ts", "tsx"],
    moduleNameMapper: {
      '^__mocks__/(.*)$': '/../../__mocks__/$1',
      // This regex should match the packages that we want compiled from source
      // through `ts-jest`, as opposed to loaded from their output files in
      // `dist`.
      // We don't want to match `apollo-server-env` and
      // `apollo-engine-reporting-protobuf`, because these don't depend on
      // compilation but need to be initialized from as parto of `prepare`.
      '^(?!apollo-server-env|apollo-engine-reporting-protobuf)(apollo-(?:federation|gateway|server|datasource|cache-control|tracing|engine)[^/]*|graphql-extensions)(?:/dist)?((?:/.*)|$)': '/../../packages/$1/src$2'
    },
    clearMocks: true,
    globals: {
      "ts-jest": {
        tsConfig: "/src/__tests__/tsconfig.json",
        diagnostics: false
      }
github Synerise / synerise-design / config / jest / base.config.js View on Github external
module.exports = {
  coverageDirectory: '/coverage',
  coverageReporters: ['lcov'],
  modulePathIgnorePatterns: ['/scripts/', '/.*/__mocks__'],
  moduleNameMapper: {
    "\\.(css|less|sass|scss)$": "/config/jest/__mocks__/styleMock.js",
    "\\.(jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/config/jest/__mocks__/fileMock.js",
    "\\.svg$": "/config/jest/__mocks__/svgrMock.js"
  },
  rootDir: path.resolve(__dirname, '..', '..'),
  setupFilesAfterEnv: ['/config/jest/setup/index.js'],
  transform: {
    '^.+\\.[jt]sx?$': '/config/jest/babel-transformer.js'
  },
  moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'],
  transformIgnorePatterns: ['/node_modules', '/.*/dist'],
  // watchPlugins: [
  //   'jest-watch-typeahead/filename',
  //   'jest-watch-typeahead/testname'
  // ]
}
github flamelink / flamelink-js-sdk / jest.config.js View on Github external
verbose: true,
  globalSetup: './tools/testing/jest-setup.ts',
  globalTeardown: './tools/testing/jest-teardown.ts',
  // coverageReporters: [`json-summary`, `text`, `html`, `cobertura`],
  collectCoverageFrom: [
    '**/*.{js,ts}',
    '!**/node_modules/**',
    '!**/dist/**',
    '!**/index.cdn.ts'
  ],
  roots: pkgs.filter(p => !p.endsWith('-types')).map(p => `${p}/src`),
  transform: {
    '^.+\\.tsx?$': 'ts-jest'
  },
  testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$',
  moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx']
}
github kristianmandrup / schema-to-yup / packages / schema-walker / jest.config.js View on Github external
const { defaults } = require("jest-config");

module.exports = {
  preset: "ts-jest",
  roots: ["/lib"],
  testEnvironment: "node",
  transform: {
    "^.+\\.tsx?$": "ts-jest"
  },
  testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.ts?$",
  moduleFileExtensions: ["ts", "tsx", ...defaults.moduleFileExtensions]
};

// module.exports = {
//   preset: "ts-jest",
//   testEnvironment: "node",
//   roots: ["/lib"],
//   transform: {
//     "^.+\\.tsx?$": "ts-jest"
//   },
//   // testMatch: ["**/__tests__/**/*.ts?(x)", "**/?(*.)+(spec|test).ts?(x)"],
//   testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
//   moduleFileExtensions: ["ts", "tsx", ...defaults.moduleFileExtensions]
// };

// // (/__tests__/.*|(\.|/)(test|spec))\.tsx?$
github tkrotoff / react-form-with-constraints / packages / react-form-with-constraints / jest.config.js View on Github external
const { defaults } = require('jest-config');

module.exports = {
  setupFiles: ['./jest.setup.ts'],
  coveragePathIgnorePatterns: [...defaults.coveragePathIgnorePatterns, './jest.setup.ts'],

  preset: 'ts-jest',

  globals: {
    'ts-jest': {
      // See https://github.com/kulshekhar/ts-jest/issues/748#issuecomment-423528659
      //
      // Ignore ts-jest error (false positive):
      // "message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`).
      // See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information."
      diagnostics: {
        ignoreCodes: [151001]
      }
    }
  }
};
github transistorsoft / background-geolocation-console / jest.config.js View on Github external
const { defaults } = require('jest-config');

module.exports = {
  // rootDir: './',
  transform: {
    ...defaults.transform,
    '^.+\\.[t|j]sx?$': '/jest.transform.js',
  },
  moduleFileExtensions: [
    'js',
    'jsx',
  ],
  testEnvironment: 'node',
  coveragePathIgnorePatterns: [].concat(
    defaults.coveragePathIgnorePatterns,
    []
  ),
  setupFiles: [
    '/jest.init.js',
  ],
  verbose: true,
};