How to use jest-validate - 10 common examples

To help you get started, we’ve selected a few jest-validate 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 jest-community / jest-junit / index.js View on Github external
function JestJUnit (globalConfig, options) {
  // See if constructor was invoked statically
  // which indicates jest-junit was invoked as a testResultsProcessor
  // and show deprecation warning

  if (globalConfig.hasOwnProperty('testResults')) {
    const newConfig = JSON.stringify({
      reporters: ['jest-junit']
    }, null, 2);

    jestValidate.logValidationWarning('testResultsProcessor support is deprecated. Please use jest reporter. See https://github.com/jest-community/jest-junit#usage', newConfig);
    return processor(globalConfig);
  }

  this._globalConfig = globalConfig;
  this._options = options;

  this.onTestResult = (test, testResult, aggregatedResult) => {
    if (testResult.console && testResult.console.length > 0) {
      consoleBuffer[testResult.testFilePath] = testResult.console;
    }
  };

  this.onRunComplete = (contexts, results) => {
    processor(results, this._options, this._globalConfig.rootDir);
  };
}
github ehmicky / gulp-execa / src / options / upstream.js View on Github external
import { Buffer } from 'buffer'

import { multipleValidOptions } from 'jest-validate'

// Examples for the core `child_process.spawn()` options
export const CHILD_PROCESS_OPTS = {
  cwd: '/home/user',
  env: { HOME: '/home/user' },
  argv0: 'command',
  stdio: multipleValidOptions('pipe', ['pipe', 'pipe', 'pipe']),
  serialization: 'json',
  detached: false,
  uid: 0,
  gid: 0,
  shell: multipleValidOptions(true, '/bin/bash'),
  windowsVerbatimArguments: true,
  windowsHide: true,
  encoding: 'utf8',
}

// Hack to make `jest-validate` validate Streams but print them nicely
const stream = {
  toJSON() {
    return 'Stream'
  },
}

// Examples for the `execa` options
export const EXECA_OPTS = {
  extendEnv: true,
  stripFinalNewline: true,
github ehmicky / gulp-execa / src / options / upstream.js View on Github external
extendEnv: true,
  stripFinalNewline: true,
  preferLocal: true,
  localDir: '/home/user',
  input: multipleValidOptions('input', Buffer.from(''), stream),
  reject: true,
  cleanup: true,
  all: true,
  execPath: '/usr/bin/noed',
  timeout: 5000,
  buffer: true,
  maxBuffer: 1e8,
  // eslint-disable-next-line no-magic-numbers
  killSignal: multipleValidOptions('SIGTERM', 9),
  stdin: multipleValidOptions('pipe', 0, stream),
  stdout: multipleValidOptions('pipe', 1, stream),
  stderr: multipleValidOptions('pipe', 2, stream),
}
github ehmicky / gulp-execa / src / options / upstream.js View on Github external
export const EXECA_OPTS = {
  extendEnv: true,
  stripFinalNewline: true,
  preferLocal: true,
  localDir: '/home/user',
  input: multipleValidOptions('input', Buffer.from(''), stream),
  reject: true,
  cleanup: true,
  all: true,
  execPath: '/usr/bin/noed',
  timeout: 5000,
  buffer: true,
  maxBuffer: 1e8,
  // eslint-disable-next-line no-magic-numbers
  killSignal: multipleValidOptions('SIGTERM', 9),
  stdin: multipleValidOptions('pipe', 0, stream),
  stdout: multipleValidOptions('pipe', 1, stream),
  stderr: multipleValidOptions('pipe', 2, stream),
}
github ehmicky / gulp-execa / src / options / upstream.js View on Github external
stripFinalNewline: true,
  preferLocal: true,
  localDir: '/home/user',
  input: multipleValidOptions('input', Buffer.from(''), stream),
  reject: true,
  cleanup: true,
  all: true,
  execPath: '/usr/bin/noed',
  timeout: 5000,
  buffer: true,
  maxBuffer: 1e8,
  // eslint-disable-next-line no-magic-numbers
  killSignal: multipleValidOptions('SIGTERM', 9),
  stdin: multipleValidOptions('pipe', 0, stream),
  stdout: multipleValidOptions('pipe', 1, stream),
  stderr: multipleValidOptions('pipe', 2, stream),
}
github ehmicky / gulp-execa / src / options / main.js View on Github external
const validateOpts = function({ opts, defaultOpts, forcedOpts }) {
  const exampleConfig = filterObj(
    { ...EXAMPLE_OPTS, ...defaultOpts },
    key => !hasOwnProperty.call(forcedOpts, key),
  )

  try {
    validate(opts, { exampleConfig, recursiveBlacklist: ['env'] })
  } catch (error) {
    // `jest-validate` `error.stack` just repeats `error.message`
    throwError(error, { showStack: false })
  }

  validateCustom({ opts })
}
github facebook / metro / packages / metro-config / src / loadConfig.js View on Github external
async function loadConfig(
  argv?: YargArguments = {},
  defaultConfigOverrides?: InputConfigT = {},
): Promise {
  argv.config = overrideArgument(argv.config);

  const configuration = await loadMetroConfigFromDisk(
    argv.config,
    argv.cwd,
    defaultConfigOverrides,
  );

  validate(configuration, {
    exampleConfig: await validConfig(),
    recursiveBlacklist: ['reporter', 'resolver', 'transformer'],
  });

  // Override the configuration with cli parameters
  const configWithArgs = overrideConfigWithArguments(configuration, argv);

  const overriddenConfig = {};

  // The resolver breaks if "json" is missing from `resolver.sourceExts`
  const sourceExts = configWithArgs.resolver.sourceExts;
  if (!configWithArgs.resolver.sourceExts.includes('json')) {
    overriddenConfig.resolver = {
      sourceExts: [...sourceExts, 'json'],
    };
  }
github facebook / jest / packages / jest-config / src / normalize.ts View on Github external
export default function normalize(
  initialOptions: Config.InitialOptions,
  argv: Config.Argv,
  configPath?: Config.Path | null,
  projectIndex: number = Infinity,
): {
  hasDeprecationWarnings: boolean;
  options: AllOptions;
} {
  const {hasDeprecationWarnings} = validate(initialOptions, {
    comment: DOCUMENTATION_NOTE,
    deprecatedConfig: DEPRECATED_CONFIG,
    exampleConfig: VALID_CONFIG,
    recursiveBlacklist: [
      'collectCoverageOnlyFrom',
      // 'coverageThreshold' allows to use 'global' and glob strings on the same
      // level, there's currently no way we can deal with such config
      'coverageThreshold',
      'globals',
      'moduleNameMapper',
      'testEnvironmentOptions',
      'transform',
    ],
  });

  let options = normalizePreprocessor(
github lingui / js-lingui / packages / conf / src / index.js View on Github external
export function getConfig({ cwd, configPath } = {}) {
  const configExplorer = cosmiconfig("lingui")
  const defaultRootDir = cwd || process.cwd()

  const result = configExists(configPath)
    ? configExplorer.loadSync(configPath)
    : configExplorer.searchSync(defaultRootDir)

  const raw = { ...defaultConfig, ...(result ? result.config : {}) }

  validate(raw, configValidation)
  // Use deprecated fallbackLanguage, if defined
  raw.fallbackLocale = raw.fallbackLocale || raw.fallbackLanguage || ""

  const rootDir = result ? path.dirname(result.filepath) : defaultRootDir
  return replaceRootDir(raw, rootDir)
}
github okonet / lint-staged / src / config-util / validateConfig.js View on Github external
)} was found in the config root.

  You are probably trying to mix simple and advanced config formats. Adding

  ${chalk.bold(`"linters": {
    "${option}": ${JSON.stringify(config[option])}
  }`)}

  will fix it and remove this message.`

    const comment = options.comment
    const name = (options.title && options.title.warning) || 'WARNING'
    return logValidationWarning(name, message, comment)
  }
  // If it is not glob pattern, use default jest-validate reporter
  return unknownOptionWarning(config, example, option, options)
}

jest-validate

Generic configuration validation tool that helps you with warnings, errors and deprecation messages as well as showing users examples of correct configuration.

MIT
Latest version published 7 months ago

Package Health Score

93 / 100
Full package analysis

Similar packages