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

Function runTestInternal

packages/jest-runner/src/runTest.ts:79–399  ·  view source on GitHub ↗
(
  path: string,
  globalConfig: Config.GlobalConfig,
  projectConfig: Config.ProjectConfig,
  resolver: Resolver,
  context: TestRunnerContext,
  sendMessageToJest?: TestFileEvent,
)

Source from the content-addressed store, hash-verified

77// references to verify if there is a leak, which is not maintainable and error
78// prone. That's why "runTestInternal" CANNOT be inlined inside "runTest".
79async function runTestInternal(
80 path: string,
81 globalConfig: Config.GlobalConfig,
82 projectConfig: Config.ProjectConfig,
83 resolver: Resolver,
84 context: TestRunnerContext,
85 sendMessageToJest?: TestFileEvent,
86): Promise<RunTestInternalResult> {
87 const testSource = fs.readFileSync(path, 'utf8');
88 const docblockPragmas = docblock.parse(docblock.extract(testSource));
89 const customEnvironment = docblockPragmas['jest-environment'];
90
91 const loadTestEnvironmentStart = Date.now();
92 let testEnvironment = projectConfig.testEnvironment;
93
94 if (customEnvironment) {
95 if (Array.isArray(customEnvironment)) {
96 throw new TypeError(
97 `You can only define a single test environment through docblocks, got "${customEnvironment.join(
98 ', ',
99 )}"`,
100 );
101 }
102 testEnvironment = resolveTestEnvironment({
103 ...projectConfig,
104 // we wanna avoid webpack trying to be clever
105 requireResolveFunction: module => require.resolve(module),
106 testEnvironment: customEnvironment,
107 });
108 }
109
110 const cacheFS = new Map([[path, testSource]]);
111 const transformer = await createScriptTransformer(projectConfig, cacheFS);
112
113 const TestEnvironment: typeof JestEnvironment =
114 await transformer.requireAndTranspileModule(testEnvironment);
115 const testFramework: TestFramework =
116 await transformer.requireAndTranspileModule(
117 process.env.JEST_JASMINE === '1'
118 ? require.resolve('jest-jasmine2')
119 : projectConfig.testRunner,
120 );
121 const Runtime: typeof RuntimeClass = interopRequireDefault(
122 projectConfig.runtime
123 ? require(projectConfig.runtime)
124 : require('jest-runtime'),
125 ).default;
126
127 const consoleOut = globalConfig.useStderr ? process.stderr : process.stdout;
128 const consoleFormatter = (type: LogType, message: LogMessage) =>
129 getConsoleOutput(
130 // 4 = the console call is buried 4 stack frames deep
131 BufferedConsole.write([], type, message, 4),
132 projectConfig,
133 globalConfig,
134 );
135
136 let testConsole;

Callers 1

runTestFunction · 0.85

Calls 15

unstable_importModuleMethod · 0.95
requireModuleMethod · 0.95
getSourceMapsMethod · 0.95
setupMethod · 0.95
collectV8CoverageMethod · 0.95
resolveTestEnvironmentFunction · 0.90
createScriptTransformerFunction · 0.90
interopRequireDefaultFunction · 0.90

Tested by

no test coverage detected