How to use jest-cli - 10 common examples

To help you get started, we’ve selected a few jest-cli 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 electron-userland / electron-builder / test / src / helpers / runTests.ts View on Github external
config,
    runInBand,
    projects: [rootDir],
  }

  if (testPatterns.length > 0) {
    jestOptions.testPathPattern = testPatterns
      .map(it => it.endsWith(".js") || it.endsWith("*") ? it : `${it}\\.js$`)
  }
  if (process.env.CIRCLECI != null || process.env.TEST_JUNIT_REPORT === "true") {
    jestOptions.reporters = ["default", "jest-junit"]
  }

  // console.log(JSON.stringify(jestOptions, null, 2))

  const testResult = await require("jest-cli").runCLI(jestOptions, jestOptions.projects)
  const exitCode = testResult.results == null || testResult.results.success ? 0 : testResult.globalConfig.testFailureExitCode
  if (isCi) {
    process.exit(exitCode)
  }

  await remove(APP_BUILDER_TMP_DIR)
  process.exitCode = exitCode
  if (testResult.globalConfig.forceExit) {
    process.exit(exitCode)
  }
}
github usehenri / henri / packages / core / src / 7.tests.js View on Github external
const options = [
      '--testPathPattern=/test/',
      '--detectOpenHandles',
      '--passWithNoTests',
      //    '--coverage',
      //    '--collectCoverageFrom=["app/**/**/*.js", "!app/views/**/*.js", "!app/routes.js"]',
    ];

    if (!this.initialized) {
      this.henri.pen.info('tests', 'silent first run...');
      options.push('--silent');
      this.initialized = true;
    }

    await runJest.run(options);

    return this.name;
  }
github jsayol / FireSQL / tools / run-tests.ts View on Github external
.then(async (config?: any) => {
    if (config) {
      if (config.type === 'local') {
        require('./tests/emulator');
      } else {
        await jest.run([
          '--verbose',
          '--config',
          resolvePath(__dirname, '../jest.config.js'),
          '--rootDir',
          resolvePath(__dirname, '../')
        ]);
      }
    }
  })
  .catch(() => { /* The promise never rejects */ });
github dsheiko / puppetry / app / main / test-runner.js View on Github external
options = {
          projects: [ cwd ],
          _: targetFiles,
          silent: true,
          // Shall disable output, but instead switch to stderr
          // https://github.com/facebook/jest/issues/5064
          json: true,
          showConfig: false
        };

  strErrCapturer.contents = [];
  // Override stderr
  const save = process.stderr.write.bind( process.stderr );
  process.stderr.write = strErrCapturer.write.bind( strErrCapturer );
  // Run JEST
  const report = await runCLI( options, options.projects );

  // Restore stderr (hopefully)
  process.stderr.write = save;

  return {
    report,
    stdErr: strErrCapturer.contents.join( "\n" )
  };

};
github facebookarchive / atom-ide-ui / modules / nuclide-jest / bin / jest-node.js View on Github external
*/
/* eslint-disable no-console */

const jestCLI = require('jest-cli');
const config = require('../jest.config.js');
const yargs = require('yargs');
const {options} = require('jest-cli/build/cli/args');

// We reach into the internals of Jest to get the options it uses for arg
// parsing with yargs to ensure we parse the args consistently with Jest.
const {argv} = yargs(process.argv.slice(2)).options(options);
// Then we override some of the options with hardcoded values.
argv.watchman = true;
argv.config = JSON.stringify(config);

jestCLI
  .runCLI(argv, [process.cwd()])
  .then(response => process.exit(response.results.success ? 0 : 1));
github 60frames / jestpack / ModuleLoader.js View on Github external
_generateMock(moduleId, ignoreManualMock) {

        let module;

        if (!this._mockMetaDataCache.hasOwnProperty(moduleId)) {
            let origMockRegistry;
            let origModuleRegistry;

            // This allows us to handle circular dependencies while generating an
            // automock.
            this._mockMetaDataCache[moduleId] = moduleMocker.getMetadata({});

            // In order to avoid it being possible for automocking to potentially cause
            // side-effects within the module environment, we need to execute the module
            // in isolation. This accomplishes that by temporarily clearing out the
            // module and mock registries while the module being analyzed is executed.
            //
            // An example scenario where this could cause issue is if the module being
            // mocked has calls into side-effectful APIs on another module.
            origMockRegistry = this._mockRegistry;
            origModuleRegistry = this._environment.global.installedModules;
            this._mockRegistry = {};
            this._environment.global.installedModules = {};

            module = this._webpackRequireModule(moduleId);

            // Restore the "real" module/mock registries
github 60frames / jestpack / ModuleLoader.js View on Github external
// module and mock registries while the module being analyzed is executed.
            //
            // An example scenario where this could cause issue is if the module being
            // mocked has calls into side-effectful APIs on another module.
            origMockRegistry = this._mockRegistry;
            origModuleRegistry = this._environment.global.installedModules;
            this._mockRegistry = {};
            this._environment.global.installedModules = {};

            module = this._webpackRequireModule(moduleId);

            // Restore the "real" module/mock registries
            this._mockRegistry = origMockRegistry;
            this._environment.global.installedModules = origModuleRegistry;

            this._mockMetaDataCache[moduleId] = moduleMocker.getMetadata(module);
        }

        // Check whether a manual mock was registered as a result of running the module
        // via `jest._registerManualMock` / the `ManualMockLoader`.
        if (!ignoreManualMock && this._manualMockMap.hasOwnProperty(moduleId)) {
            return this._webpackRequireModule(this._manualMockMap[moduleId]);
        }

        return moduleMocker.generateFromMetadata(this._mockMetaDataCache[moduleId]);
    }
github learningequality / kolibri / packages / kolibri-tools / lib / cli.js View on Github external
if (process.env.NODE_ENV == null) {
      process.env.NODE_ENV = 'test';
    }
    let config;
    if (options.config) {
      config = path.resolve(process.cwd(), options.config);
      const configIndex = process.argv.findIndex(item => item === '--config');
      process.argv.splice(configIndex, 2);
    } else {
      config = baseConfigPath;
    }
    // Remove the 'test' command that this was invoked with
    process.argv.splice(2, 1);
    process.argv.push('--config');
    process.argv.push(config);
    require('jest-cli/build/cli').run();
  });
github 60frames / jestpack / ModuleLoader.js View on Github external
module = this._webpackRequireModule(moduleId);

            // Restore the "real" module/mock registries
            this._mockRegistry = origMockRegistry;
            this._environment.global.installedModules = origModuleRegistry;

            this._mockMetaDataCache[moduleId] = moduleMocker.getMetadata(module);
        }

        // Check whether a manual mock was registered as a result of running the module
        // via `jest._registerManualMock` / the `ManualMockLoader`.
        if (!ignoreManualMock && this._manualMockMap.hasOwnProperty(moduleId)) {
            return this._webpackRequireModule(this._manualMockMap[moduleId]);
        }

        return moduleMocker.generateFromMetadata(this._mockMetaDataCache[moduleId]);
    }
github 60frames / jestpack / ModuleLoader.js View on Github external
getTestEnvData: () => {
                const frozenCopy = {};
                // Make a shallow copy only because a deep copy seems like
                // overkill..
                Object.keys(this._config.testEnvData).forEach(key => {
                    frozenCopy[key] = this._config.testEnvData[key];
                }, this);
                Object.freeze(frozenCopy);
                return frozenCopy;
            },

            genMockFromModule: moduleId => this._generateMock(moduleId, true),

            genMockFunction: moduleMocker.getMockFunction,

            genMockFn: moduleMocker.getMockFunction,

            mock: moduleId => {
                this._explicitShouldMock[moduleId] = true;
                return runtime;
            },

            /* eslint-disable */
            resetModuleRegistry: () => {
                const envGlobal = this._environment.global;
                Object.keys(envGlobal).forEach(key => {
                    const globalMock = envGlobal[key];
                    if ((typeof globalMock === 'object' && globalMock !== null) ||
                        typeof globalMock === 'function') {
                        globalMock._isMockFunction && globalMock.mockClear();
                    }
                });