Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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;
Expand Down
20 changes: 18 additions & 2 deletions src/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,33 @@ 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 }[] = [];
stack.push({ node: undefined, r: { children: [] } } as any);

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") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this hard-coded value here, it would read the setting and determine if the import matches the configuration.

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:
Expand Down