From 808248230ff7fd0b981beb3e22388737fd34770c Mon Sep 17 00:00:00 2001 From: Aleksandr Kanunnikov Date: Wed, 20 May 2020 12:31:59 +0300 Subject: [PATCH] bugfix: go-to definition tests jumping --- .../core/template-definition-provider.ts | 4 ++-- src/utils/layout-helpers.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/builtin-addons/core/template-definition-provider.ts b/src/builtin-addons/core/template-definition-provider.ts index d46c9093..de4ec59f 100644 --- a/src/builtin-addons/core/template-definition-provider.ts +++ b/src/builtin-addons/core/template-definition-provider.ts @@ -7,7 +7,7 @@ import { isLinkToTarget, isLinkComponentRouteTarget } from './../../utils/ast-he import ASTPath from './../../glimmer-utils'; import { getGlobalRegistry } from './../../utils/registry-api'; import { normalizeToClassicComponent } from '../../utils/normalizers'; -import { isTemplatePath, getComponentNameFromURI, isModuleUnificationApp, getPodModulePrefix } from './../../utils/layout-helpers'; +import { isTemplatePath, isTestFile, getComponentNameFromURI, isModuleUnificationApp, getPodModulePrefix } from './../../utils/layout-helpers'; import { getAbstractHelpersParts, @@ -26,7 +26,7 @@ export function getPathsFromRegistry(type: 'helper' | 'modifier' | 'component', const absRoot = path.normalize(root); const registry = getGlobalRegistry(); const bucket: any = registry[type].get(name) || new Set(); - return Array.from(bucket).filter((el: string) => path.normalize(el).includes(absRoot) && fs.existsSync(el)) as string[]; + return Array.from(bucket).filter((el: string) => path.normalize(el).includes(absRoot) && !isTestFile(path.normalize(el)) && fs.existsSync(el)) as string[]; } export function provideComponentTemplatePaths(root: string, rawComponentName: string) { diff --git a/src/utils/layout-helpers.ts b/src/utils/layout-helpers.ts index 860e6dab..a62fda43 100644 --- a/src/utils/layout-helpers.ts +++ b/src/utils/layout-helpers.ts @@ -274,6 +274,18 @@ export function isTemplatePath(filePath: string) { return filePath.endsWith('.hbs'); } +export function normalizedPath(filePath: string) { + if (filePath.includes('\\')) { + return filePath.split('\\').join('/'); + } else { + return filePath; + } +} + +export function isTestFile(filePath: string) { + return normalizedPath(filePath).includes('/tests/'); +} + export function hasAddonFolderInPath(name: string) { return name.includes(path.sep + 'addon' + path.sep); }