How to use jest-regex-util - 10 common examples

To help you get started, we’ve selected a few jest-regex-util 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 forcedotcom / salesforcedx-vscode / packages / salesforcedx-vscode-lwc / src / testSupport / testRunner / testRunner.ts View on Github external
const testResultFileName = `test-result-${testRunId}.json`;
    const outputFilePath = path.join(tempFolder, testResultFileName);
    // Specify --runTestsByPath if running test on individual files
    let runTestsByPathArgs: string[];
    if (kind === TestInfoKind.TEST_FILE || kind === TestInfoKind.TEST_CASE) {
      const workspaceFolderFsPath = workspaceFolder.uri.fsPath;
      runTestsByPathArgs = [
        '--runTestsByPath',
        normalizeRunTestsByPath(workspaceFolderFsPath, testFsPath)
      ];
    } else {
      runTestsByPathArgs = [];
    }
    const testNamePatternArgs = testName
      ? ['--testNamePattern', `"${escapeStrForRegex(testName)}"`]
      : [];

    let runModeArgs: string[];
    if (testRunType === TestRunType.WATCH) {
      runModeArgs = ['--watch'];
    } else {
      runModeArgs = [];
    }
    const args = [
      ...runModeArgs,
      '--json',
      '--outputFile',
      outputFilePath,
      '--testLocationInResults',
      ...runTestsByPathArgs,
      ...testNamePatternArgs
github facebook / jest / packages / jest-config / src / defaults.js View on Github external
*
 * This source code is licensed under the BSD-style license found in the
 * LICENSE file in the root directory of this source tree. An additional grant
 * of patent rights can be found in the PATENTS file in the same directory.
 *
 * @flow
 */

import type {DefaultOptions} from 'types/Config';

import os from 'os';
import path from 'path';
import {replacePathSepForRegex} from 'jest-regex-util';
import constants from './constants';

const NODE_MODULES_REGEXP = replacePathSepForRegex(constants.NODE_MODULES);

const cacheDirectory = (() => {
  const {getuid} = process;
  if (getuid == null) {
    return path.join(os.tmpdir(), 'jest');
  }
  // On some platforms tmpdir() is `/tmp`, causing conflicts between different
  // users and permission issues. Adding an additional subdivision by UID can
  // help.
  return path.join(os.tmpdir(), 'jest_' + getuid.call(process).toString(36));
})();

module.exports = ({
  automock: false,
  bail: false,
  browser: false,
github forcedotcom / salesforcedx-vscode / packages / salesforcedx-vscode-lwc / src / testSupport / testIndexer / jestUtils.ts View on Github external
export function extractPositionFromFailureMessage(
  testFsPath: string,
  failureMessage: string
) {
  try {
    const locationMatcher = new RegExp(
      escapeStrForRegex(testFsPath) + '\\:(\\d+)\\:(\\d+)',
      'i'
    );
    const matchResult = failureMessage.match(locationMatcher);
    if (matchResult) {
      const lineString = matchResult[1];
      const columnString = matchResult[2];
      const line = parseInt(lineString, 10);
      const column = parseInt(columnString, 10);
      if (isNaN(line) || isNaN(column)) {
        return undefined;
      }
      return new vscode.Position(line - 1, column - 1);
    }
    return undefined;
  } catch (error) {
    return undefined;
github jest-community / jest-watch-typeahead / src / test_name_plugin / plugin.js View on Github external
p.run(value => {
        updateConfigAndRun({
          mode: 'watch',
          testNamePattern: escapeStrForRegex(removeTrimmingDots(value)),
        });
        res();
      }, rej);
    });
github Raathigesh / majestic / server / services / test-file-matcher.ts View on Github external
        .map((dir: string) => escapePathForRegex(dir + pathUtil.sep))
        .join("|")
github facebook / jest / packages / jest-config / src / ValidConfig.ts View on Github external
/**
 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

import {Config} from '@jest/types';
import {replacePathSepForRegex} from 'jest-regex-util';
import {multipleValidOptions} from 'jest-validate';
import {NODE_MODULES} from './constants';

const NODE_MODULES_REGEXP = replacePathSepForRegex(NODE_MODULES);

const initialOptions: Config.InitialOptions = {
  automock: false,
  bail: multipleValidOptions(false, 0),
  browser: false,
  cache: true,
  cacheDirectory: '/tmp/user/jest',
  changedFilesWithAncestor: false,
  changedSince: 'master',
  clearMocks: false,
  collectCoverage: true,
  collectCoverageFrom: ['src', '!public'],
  collectCoverageOnlyFrom: {
    '/this-directory-is-covered/Covered.js': true,
  },
  coverageDirectory: 'coverage',
github Raathigesh / majestic / app / src / renderer / util / jest.ts View on Github external
const pathToRegex = p => replacePathSepForRegex(p);
const regexToMatcher = (testRegex: string) => {
github facebook / jest / packages / jest-config / src / normalize.ts View on Github external
options[key]!.map(pattern =>
    replacePathSepForRegex(pattern.replace(//g, options.rootDir)),
  );
github lingui / js-lingui / packages / conf / src / index.js View on Github external
const path = require("path")
const fs = require("fs")
const chalk = require("chalk")
const cosmiconfig = require("cosmiconfig")
const { validate } = require("jest-validate")
const { replacePathSepForRegex } = require("jest-regex-util")

const NODE_MODULES = replacePathSepForRegex(
  path.sep + "node_modules" + path.sep
)

export function replaceRootDir(conf, rootDir) {
  const replace = s => s.replace("", rootDir)
  ;["srcPathDirs", "srcPathIgnorePatterns", "localeDir"].forEach(key => {
    const value = conf[key]

    if (!value) {
    } else if (typeof value === "string") {
      conf[key] = replace(value)
    } else if (value.length) {
      conf[key] = value.map(replace)
    }
  })
github facebook / jest / packages / jest-config / src / valid_config.js View on Github external
/**
 * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import type {InitialOptions} from 'types/Config';

import {replacePathSepForRegex} from 'jest-regex-util';
import {NODE_MODULES} from './constants';

const NODE_MODULES_REGEXP = replacePathSepForRegex(NODE_MODULES);

export default ({
  automock: false,
  bail: false,
  browser: false,
  cache: true,
  cacheDirectory: '/tmp/user/jest',
  changedFilesWithAncestor: false,
  clearMocks: false,
  collectCoverage: true,
  collectCoverageFrom: ['src', '!public'],
  collectCoverageOnlyFrom: {
    '/this-directory-is-covered/covered.js': true,
  },
  coverageDirectory: 'coverage',
  coveragePathIgnorePatterns: [NODE_MODULES_REGEXP],

jest-regex-util

MIT
Latest version published 10 months ago

Package Health Score

91 / 100
Full package analysis

Similar packages