MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / testDiscovered

Method testDiscovered

src/shared/test/test_model.ts:508–578  ·  view source on GitHub ↗
(dartCodeDebugSessionID: string, suitePath: string, source: TestSource, testID: number, testName: string | undefined, groupID: number | undefined, testPath: string | undefined, range: Range | undefined, startTime: number | undefined, hasStarted = false)

Source from the content-addressed store, hash-verified

506 }
507
508 public testDiscovered(dartCodeDebugSessionID: string, suitePath: string, source: TestSource, testID: number, testName: string | undefined, groupID: number | undefined, testPath: string | undefined, range: Range | undefined, startTime: number | undefined, hasStarted = false): TestNode {
509 testPath ??= suitePath;
510 const suite = this.suites.getForPath(suitePath)!;
511 const existingTest = suite.reuseMatchingTest(testName);
512 const oldParent = existingTest?.parent;
513 let parent = groupID ? suite.getMyGroup(dartCodeDebugSessionID, groupID)! : suite.node;
514
515 /**
516 * If we're a dynamic test/group, we should be re-parented under the dynamic node that came from
517 * the analyzer.
518 */
519 if (testName && source === TestSource.Result)
520 parent = this.findMatchingDynamicNode(parent, testName) ?? parent;
521
522 const testNode = existingTest || new TestNode(suite, parent, testName, testPath, range);
523
524 suite.storeTest(dartCodeDebugSessionID, testID, testNode);
525
526 if (existingTest) {
527 testNode.parent = parent;
528 testNode.name = testName;
529 testNode.path = testPath;
530 if (range) {
531 const originalRange = testNode.range;
532 testNode.range = range;
533
534 if (!this.config.dynamicTestTracking) {
535 // If we're an Outline node being updated, and we have Results children that
536 // had the same range as us, they should be updated too, so Results nodes do not
537 // drift away from the location over time.
538 if (testNode.testSource === TestSource.Outline) {
539 const children = testNode.children
540 .filter((c) => c.testSource === TestSource.Result)
541 .filter((c) => !c.range || (originalRange && rangesEqual(c.range, originalRange)));
542 for (const child of children)
543 child.range = range;
544 }
545 }
546 }
547 } else {
548 testNode.testSource = source;
549 }
550
551 this.markAsNotDeleted(testNode);
552 testNode.testStartTime = startTime;
553
554 // Remove from old parent if required.
555 const hasChangedParent = oldParent && oldParent !== testNode.parent;
556 if (oldParent && hasChangedParent) {
557 oldParent.children.splice(oldParent.children.indexOf(testNode), 1);
558 this.updateNode({ node: oldParent });
559 }
560
561 // Push to new parent if required.
562 if (!testNode.parent.children.find((n) => n === testNode))
563 testNode.parent.children.push(testNode);
564
565 if (hasStarted) {

Callers

nothing calls this directly

Calls 10

markAsNotDeletedMethod · 0.95
updateNodeMethod · 0.95
setupRangeTrackingMethod · 0.95
rangesEqualFunction · 0.90
getForPathMethod · 0.80
reuseMatchingTestMethod · 0.80
getMyGroupMethod · 0.80
storeTestMethod · 0.80
testStartedMethod · 0.65

Tested by

no test coverage detected