How to use the jest.runCLI function in jest

To help you get started, we’ve selected a few 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 nordcloud / serverless-jest-plugin / lib / run-tests.js View on Github external
if (allFunctions.indexOf(functionName) >= 0) {
          setEnv(serverless, functionName);
          Object.assign(config, { testRegex: `${functionName}\\.test\\.[jt]s$` });
        } else {
          return reject(`Function "${functionName}" not found`);
        }
      } else {
        const functionsRegex = allFunctions.map(name => `${name}\\.test\\.[jt]s$`).join('|');
        Object.assign(config, { testRegex: functionsRegex });
      }
    }

    // eslint-disable-next-line dot-notation
    process.env['SERVERLESS_TEST_ROOT'] = serverless.config.servicePath;

    return runCLI(config, [serverless.config.servicePath])
      .then((output) => {
        if (output.results.success) {
          resolve(output);
        } else {
          reject(output.results);
        }
      })
      .catch(e => reject(e));
  });
github basys / basys / packages / basys / lib / index.js View on Github external
function unitTest(projectDir) {
  const configPath = path.join(projectDir, 'jest.config.js');
  const jestConfig = fs.pathExistsSync(configPath)
    ? require(configPath)
    : require('./webpack/jest-config');
  const argv = {config: JSON.stringify(jestConfig)};
  require('jest').runCLI(argv, [projectDir]); // BUG: should be tests/unit?
}
github ArkEcosystem / core / __tests__ / e2e / lib / test-runner.js View on Github external
runJestTest(path) {
        const options = {
            projects: [__dirname],
            silent: true,
            testPathPattern: ["tests/scenarios/" + this.scenario + "/" + path.replace(/\//g, "\\/")],
            modulePathIgnorePatterns: ["dist/"],
        };

        jest.runCLI(options, options.projects)
            .then(success => {
                console.log(`[test-runner] Test ${path} was run successfully`);
                this.testResults.push(success.results);

                this.failedTestSuites += success.results.numFailedTestSuites;
            })
            .catch(failure => {
                console.error(`[test-runner] Error running test ${path} : ${failure}`);
            });
    }
github oracle / netsuite-suitecloud-node-cli / testing-framework / services / SuiteCloudJestUnitTestRunner.js View on Github external
run: async function(args) {
		try {
			const jestResult = await jest.runCLI(args, [process.cwd()]);
			if (!jestResult.results.success) {
				throw TranslationService.getMessage(MESSAGES.UNIT_TEST.TEST_FAILED);
			}
		} catch (error) {
			throw TranslationService.getMessage(MESSAGES.UNIT_TEST.TEST_FAILURES_PRESENT);
		}
	}
};
github youzan / vant / packages / vant-cli / src / commands / jest.ts View on Github external
export function test(command: any) {
  setNodeEnv('test');

  genPackageEntry({
    outputPath: PACKAGE_ENTRY_FILE
  });

  const config = {
    rootDir: ROOT,
    watch: command.watch,
    config: JEST_CONFIG_FILE,
    clearCache: command.clearCache
  } as any;

  runCLI(config, [ROOT])
    .then(response => {
      if (!response.results.success && !command.watch) {
        process.exit(1);
      }
    })
    .catch(err => {
      console.log(err);

      if (!command.watch) {
        process.exit(1);
      }
    });
}
github moment / luxon / tasks / unit.js View on Github external
async function test() {
  const opts = {
    collectCoverage: true,
    coverageDirectory: 'build/coverage',
    collectCoverageFrom: ['src/**', '!src/zone.js', '!src/luxonFilled.js'],
    ci: !!process.env.CI,
    testEnvironment: 'node'
  };

  if (process.env.LIMIT_JEST) {
    opts.maxWorkers = 4;
  }

  return jest.runCLI(opts, ['./test']);
}
github nrwl / nx / packages / jest / src / builders / jest / jest.impl.ts View on Github external
if (options.findRelatedTests) {
    const parsedTests = options.findRelatedTests.split(',').map(s => s.trim());
    config._.push(...parsedTests);
    config.findRelatedTests = true;
  }

  if (options.clearCache) {
    config.clearCache = true;
  }

  if (options.reporters && options.reporters.length > 0) {
    config.reporters = options.reporters;
  }

  return from(runCLI(config, [options.jestConfig])).pipe(
    map(results => {
      return {
        success: results.results.success
      };
    })
  );
}
github stryker-mutator / stryker / packages / stryker-jest-runner / src / jestTestAdapters / JestPromiseTestAdapter.ts View on Github external
public run(jestConfig: Configuration, projectRoot: string, fileNameUnderTest?: string): Promise {
    jestConfig.reporters = [];
    const config = JSON.stringify(jestConfig);
    this.log.trace(`Invoking Jest with config ${config}`);
    if (fileNameUnderTest) {
      this.log.trace(`Only running tests related to ${fileNameUnderTest}`);
    }

    return runCLI({
      ...(fileNameUnderTest && { _: [fileNameUnderTest], findRelatedTests: true}),
      config,
      runInBand: true,
      silent: true
    }, [projectRoot]);
  }
}
github intraxia / wp-gistpen / commands / E2ECommand.tsx View on Github external
Kefir.stream(emitter => {
        process.env.NODE_ENV = 'test';
        process.env.BABEL_ENV = 'test';
        emitter.value(actions.testRun.request());
        jest.runCLI(buildArgv(argv), projects).then(({ results }) => {
          if (results.success) {
            emitter.value(actions.testRun.success());
          } else {
            emitter.value(actions.testRun.failure());
          }
          emitter.value(actions.shutdown.request());
        });
      })
    )