MCPcopy Create free account
hub / github.com/codemix/graph / tryRunTest

Function tryRunTest

packages/graph/scripts/tck-audit.ts:151–208  ·  view source on GitHub ↗

* Try to run a single test by temporarily unskipping it

(test: SkippedTest)

Source from the content-addressed store, hash-verified

149 * Try to run a single test by temporarily unskipping it
150 */
151function tryRunTest(test: SkippedTest): TestResult {
152 const content = fs.readFileSync(test.file, "utf-8");
153 const lines = content.split("\n");
154
155 // Find and modify the line
156 const lineIndex = test.lineNumber - 1;
157 const originalLine = lines[lineIndex];
158
159 if (!originalLine.includes("test.skip")) {
160 return {
161 test,
162 passed: false,
163 error: "Could not find test.skip on expected line",
164 };
165 }
166
167 // Replace test.skip with test
168 const modifiedLine = originalLine.replace("test.skip", "test");
169 lines[lineIndex] = modifiedLine;
170
171 // Write modified file
172 fs.writeFileSync(test.file, lines.join("\n"));
173
174 try {
175 // Run just this test file with a filter for this specific test
176 const testPattern = test.testName.replace(/[[\]()]/g, "\\$&");
177 const relativePath = path.relative(path.join(import.meta.dirname, ".."), test.file);
178
179 const result = spawnSync(
180 "npx",
181 ["vitest", "run", relativePath, "-t", testPattern, "--reporter=basic"],
182 {
183 cwd: path.join(import.meta.dirname, ".."),
184 encoding: "utf-8",
185 timeout: 30000,
186 env: { ...process.env, CI: "true" },
187 },
188 );
189
190 const output = (result.stdout || "") + (result.stderr || "");
191 const passed = result.status === 0 && !output.includes("FAIL");
192
193 return {
194 test,
195 passed,
196 error: passed ? undefined : output.slice(0, 500),
197 };
198 } catch (err) {
199 return {
200 test,
201 passed: false,
202 error: String(err),
203 };
204 } finally {
205 // Restore original file
206 fs.writeFileSync(test.file, content);
207 }
208}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected