MCPcopy
hub / github.com/jestjs/jest / spawnJest

Function spawnJest

e2e/runJest.ts:74–130  ·  view source on GitHub ↗
(
  dir: string,
  args: Array<string> = [],
  options: RunJestOptions = {},
  spawnAsync = false,
)

Source from the content-addressed store, hash-verified

72
73// Spawns Jest and returns either a Promise (if spawnAsync is true) or the completed child process
74function spawnJest(
75 dir: string,
76 args: Array<string> = [],
77 options: RunJestOptions = {},
78 spawnAsync = false,
79): execa.ExecaSyncReturnValue | execa.ExecaChildProcess {
80 const isRelative = !path.isAbsolute(dir);
81
82 if (isRelative) {
83 dir = path.resolve(__dirname, dir);
84 }
85
86 const localPackageJson = path.resolve(dir, 'package.json');
87 if (!options.skipPkgJsonCheck && !fs.existsSync(localPackageJson)) {
88 throw new Error(dedent`
89 Make sure you have a local package.json file at
90 "${localPackageJson}".
91 Otherwise Jest will try to traverse the directory tree and find the global package.json, which will send Jest into infinite loop.
92 `);
93 }
94 const env: NodeJS.ProcessEnv = {
95 ...process.env,
96 // Prevent AI agent detection from leaking into child processes, which
97 // would activate the AgentReporter and break output-dependent e2e tests.
98 AI_AGENT: undefined,
99 AUGMENT_AGENT: undefined,
100 CLAUDECODE: undefined,
101 CLAUDE_CODE: undefined,
102 CODEX_SANDBOX: undefined,
103 CODEX_THREAD_ID: undefined,
104 CURSOR_AGENT: undefined,
105 FORCE_COLOR: '0',
106 GEMINI_CLI: undefined,
107 GOOSE_PROVIDER: undefined,
108 NO_COLOR: '1',
109 OPENCODE: undefined,
110 ...options.env,
111 };
112
113 if (options.nodeOptions) env['NODE_OPTIONS'] = options.nodeOptions;
114 if (options.nodePath) env['NODE_PATH'] = options.nodePath;
115
116 const spawnArgs = [JEST_PATH, ...args];
117 const spawnOptions: execa.CommonOptions<string> = {
118 cwd: dir,
119 env,
120 reject: false,
121 stripFinalNewline: !options.keepTrailingNewline,
122 timeout: options.timeout || 0,
123 };
124
125 return (spawnAsync ? execa : execa.sync)(
126 process.execPath,
127 spawnArgs,
128 spawnOptions,
129 );
130}
131

Callers 2

runJestFunction · 0.85
runContinuousFunction · 0.85

Calls 1

resolveMethod · 0.45

Tested by

no test coverage detected