xref: /expo/packages/jest-expo/bin/jest.js (revision 3b40a433)
1#!/usr/bin/env node
2'use strict';
3
4const childProcess = require('child_process');
5const jestPackageJson = require('jest/package.json');
6const path = require('path');
7const process = require('process');
8
9// This small program is a proxy for the "jest" program defined by the Jest package. The proxy is
10// necessary because Jest is not a dependency of the Expo package. Some package managers (e.g., npm)
11// don't hoist binaries provided by nested dependencies, so to consistently define a program named
12// "jest" we use this proxy script.
13//
14// We forward all arguments and stdio streams to the real "jest" program and exit with the same
15// signal or status code.
16//
17// If you need to run Jest with the JS debugger enabled, run Jest directly. It is usually under
18// node_modules/jest/bin/jest.js.
19const jestPackagePath = path.dirname(require.resolve('jest/package.json'));
20const jestProgramPath = path.resolve(
21  jestPackagePath,
22  jestPackageJson.bin.jest || jestPackageJson.bin
23);
24const jestProgramArgs = process.argv.slice(2);
25const jestWithArgs = [jestProgramPath].concat(jestProgramArgs);
26const result = childProcess.spawnSync('node', jestWithArgs, { stdio: 'inherit' });
27
28if (result.signal) {
29  process.kill(process.pid, result.signal);
30} else {
31  process.exit(result.status);
32}
33