How to use the ts-jest/utils.pathsToModuleNameMapper function in ts-jest

To help you get started, we’ve selected a few ts-jest 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 ngxs / store / jest.config.js View on Github external
// https://jestjs.io/docs/en/configuration
// Configuring Jest
const path = require('path');
const { pathsToModuleNameMapper: resolver } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');

const moduleNameMapper = resolver(compilerOptions.paths, { prefix: '/' });
const CI = process.env['CI'] === 'true';

if (!CI) {
  console.log('[DEBUG]: moduleNameMapper');
  console.log(JSON.stringify(moduleNameMapper, null, 4));
}

module.exports = {
  displayName: 'ngxs',
  projects: [''],
  rootDir: path.resolve('.'),

  /**
   * A set of global variables that need to be available in all test environments.
   */
  globals: {
github SolidZORO / leaa / packages / leaa-api / jest.config.js View on Github external
/* eslint-disable import/no-extraneous-dependencies */
const { defaults: tsjPreset } = require('ts-jest/presets');

// 🔰 Tips, if `tsconfig.json`, here will be open
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');

module.exports = {
  transform: {
    ...tsjPreset.transform,
    '^.+\\.tsx?$': 'ts-jest',
  },
  moduleFileExtensions: ['ts', 'js'],
  //
  // 🔰 Tips, if `tsconfig.json`, here will be open
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '/' }),
  //
  modulePathIgnorePatterns: ['/_dist/', '/_deploy/'],
  testRegex: 'src.*\\.(test|spec).(ts|tsx|js)$',
  collectCoverageFrom: [
    'src/**/*.{js,jsx,tsx,ts}',
    '!**/node_modules/**',
    '!**/vendor/**',
    '!**/dist/**',
    '!**/_dist/**',
    '!**/_deploy/**',
  ],
  // coverageReporters: ['json', 'lcov'],
  testEnvironment: 'node',
  collectCoverage: true,
  // coverageDirectory: './coverage',
};
github algolia / algoliasearch-client-javascript / jest.config.js View on Github external
/* eslint-disable import/no-commonjs, functional/immutable-data */
const { pathsToModuleNameMapper } = require('ts-jest/utils');

const { compilerOptions } = require('./tsconfig');

const config = {
  testMatch: ['**/__tests__/**/*.test.ts'],
  preset: 'ts-jest',
  setupFilesAfterEnv: ['config/jest.js', 'jest-mock-console/dist/setupTestFramework.js'],
  transform: {
    '^.+\\.ts?$': 'ts-jest',
  },
  moduleFileExtensions: ['js', 'ts'],
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '/' }),
  transformIgnorePatterns: [],
  coverageReporters: ['text'],
  collectCoverage: true,
  collectCoverageFrom: ['**/src*/*.ts', '!**/src/__tests__/*.ts'],
  coverageThreshold: {
    global: {
      branches: 100,
      functions: 100,
      lines: 100,
      statements: 100,
    },
  },
};

module.exports = {
  projects: [
github netdata / netdata-ui / jest.config.js View on Github external
paths: {
      "@/*": ["./*"],
    },
  },
}

const { compilerOptions } = tsPathConfig

module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
  testPathIgnorePatterns: ["/test/", "/node_modules/", "lib"],
  moduleDirectories: ["node_modules", "src"],
  moduleNameMapper: {
    "^.+\\.(css|less|scss)$": "identity-obj-proxy",
    ...pathsToModuleNameMapper(compilerOptions.paths, { prefix: "/" }),
    "\\.svg": "/src/__mocks__/filemock.tsx",
  },
  globals: {
    // All globals should be in upper case due webpack configuration
    DEVELOPMENT: true,
  },
}
github pankod / react-native-picker-modal-view / jest.config.js View on Github external
"tsx",
		"js",
		"jsx",
		"json",
		"node"
	],
	"roots": [
		""
	],
	"modulePathIgnorePatterns": ["/example"],
	"globals": {
		"ts-jest": {
			"tsConfig": "./tsconfig.json"
		}
	},
	"moduleNameMapper": pathsToModuleNameMapper(compilerOptions.paths /*, { prefix: '/' } */),
	"modulePaths": [
		""
	],
	"testEnvironment": "jsdom",
	"setupFiles": [
		"./setupTests.ts"
	],
	"setupFilesAfterEnv": ["/setupTests.ts"]
};
github react-spring / react-spring / jest.config.js View on Github external
function getModuleNameMapper(paths) {
  if (!paths) return
  const map = pathsToModuleNameMapper(paths)
  for (const key in map) {
    map[key] = map[key].replace('./', '/')
  }
  return map
}
github jmcdo29 / zeldaPlay / src / client / jest.config.js View on Github external
displayName: 'client',
  roots: ['/app'],
  preset: 'jest-preset-angular',
  globals: {
    'ts-jest': {
      tsConfigFile: './tsconfig.spec.json'
    },
    __TRANSFORM_HTML__: true
  },
  transform: {
    '^.+\\.(ts|js|html)$':
      '/../../node_modules/jest-preset-angular/preprocessor.js'
  },
  testMatch: ['**/*.spec.ts'],
  moduleFileExtensions: ['ts', 'js', 'json', 'html'],
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {prefix: '/'}),
  transformIgnorePatterns: ['node_modules/(?!@ngrx)'],
  snapshotSerializers: [
    '/../../node_modules/jest-preset-angular/AngularSnapshotSerializer.js',
    '/../../node_modules/jest-preset-angular/HTMLCommentSerializer.js'
  ],
  setupFilesAfterEnv: ['/setupJest.ts'],
  coverageDirectory: '/../../coverage/client'
  
}
github ModusCreateOrg / gimbal / packages / gimbal-core / jest.config.js View on Github external
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');

module.exports = {
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
    prefix: '/',
  }),
  roots: ['/src'],
  transform: {
    '^.+\\.tsx?$': 'ts-jest',
  },
};
github ModusCreateOrg / gimbal / packages / plugin-sqlite / jest.config.js View on Github external
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');

module.exports = {
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
    prefix: '/',
  }),
  roots: ['/src'],
  transform: {
    '^.+\\.tsx?$': 'ts-jest',
  },
};
github stoplightio / prism / jest.config.js View on Github external
const { pathsToModuleNameMapper } = require('ts-jest/utils');
const path = require('path')
const { mapValues } = require('lodash')
const { compilerOptions } = require('./packages/tsconfig.test');

const projectDefault = {
  moduleNameMapper: mapValues(pathsToModuleNameMapper(compilerOptions.paths), v => path.resolve(path.join('packages', v))),
  testEnvironment: 'node',
  transform: {
    '^.+\\.(ts)$': 'ts-jest',
  }
};

module.exports = {
  projects: [
    {
      ...projectDefault,
      displayName: 'HTTP-SERVER',
      testMatch: ['/packages/http-server/src/**/__tests__/*.*.ts'],
      globals: {
        'ts-jest': {
          tsConfig: '/packages/tsconfig.test.json',
        },