From 9601eb0b72d3b7d65995f68a7104899ae9e70cef Mon Sep 17 00:00:00 2001 From: Steven Kabbes Date: Mon, 24 Mar 2025 15:23:03 -0700 Subject: [PATCH] hacked example for using a wrapped test function --- src/controller.ts | 5 +++-- src/parsing.ts | 20 ++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/controller.ts b/src/controller.ts index b369a0b..1681b36 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -5,12 +5,12 @@ import picomatch from "picomatch"; import * as vscode from "vscode"; import { coverageContext } from "./coverage"; import { DisposableStore, MutableDisposable } from "./disposable"; +import { ExtensionConfig } from "./extension-config"; import { last } from "./iterable"; import { ICreateOpts, ItemType, getContainingItemsForFile, testMetadata } from "./metadata"; import { IParsedNode, parseSource } from "./parsing"; import { RunHandler, TestRunner } from "./runner"; import { ISourceMapMaintainer, SourceMapStore } from "./source-map-store"; -import { ExtensionConfig } from './extension-config'; const diagnosticCollection = vscode.languages.createDiagnosticCollection("nodejs-testing-dupes"); @@ -174,7 +174,8 @@ export class Controller { return; } - const tree = parseSource(contents); + console.log(uri.fsPath); + const tree = parseSource(contents, uri.fsPath); if (!tree.length) { this.deleteFileTests(uri.toString()); return; diff --git a/src/parsing.ts b/src/parsing.ts index ba19fd1..1930681 100644 --- a/src/parsing.ts +++ b/src/parsing.ts @@ -76,9 +76,10 @@ export interface IParsedNode { children: IParsedNode[]; } -export const parseSource = (text: string) => { +export const parseSource = (text: string, fsPath?: string) => { const ast = parse(text, acornOptions); + // A list of tests to see if a function call is a "test" const idTests: ExtractTest[] = []; const stack: { node: Node; r: IParsedNode }[] = []; @@ -86,7 +87,22 @@ export const parseSource = (text: string) => { traverse(ast as Node, { enter(node) { - if (node.type === C.ImportDeclaration && node.source.value === C.NodeTest) { + if (node.type === C.ImportDeclaration && node.source.value === "../utils") { + for (const spec of node.specifiers) { + switch (spec.type) { + case C.ImportNamespaceSpecifier: + case C.ImportDefaultSpecifier: + idTests.push(matchNamespaced(spec.local.name)); + break; + case C.ImportSpecifier: + if (spec.imported.type === C.Identifier) { + console.log(`registering ${spec.imported.name} -> ${spec.local.name}`); + idTests.push(matchIdentified(spec.imported.name, spec.local.name)); + } + break; + } + } + } else if (node.type === C.ImportDeclaration && node.source.value === C.NodeTest) { for (const spec of node.specifiers) { switch (spec.type) { case C.ImportNamespaceSpecifier: