private bool ShouldDiscover(string pathToItem)
        {
            if (string.IsNullOrEmpty(pathToItem))
            {
                return(false);
            }

            if (pathToItem.IndexOf("\\node_modules\\", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                return(false);
            }

            //Setting/updating "TestFramework" property on a file item will cause metedata change in the project file,
            //so we need to re-discover when file change happens.
            if (TypeScriptHelpers.IsSupportedTestProjectFile(pathToItem))
            {
                return(true);
            }

            if (this.IsTestFile(pathToItem))
            {
                if (EqtTrace.IsVerboseEnabled)
                {
                    EqtTrace.Verbose("TestContainerDiscoverer: Found a test {0}.", pathToItem);
                }

                return(true);
            }

            return(false);
        }
Example #2
0
        public static bool TryGetProjectDirectory(this IVsProject project, out string path)
        {
            var succeeded = TryGetProjectPath(project, out path);

            if (succeeded && TypeScriptHelpers.IsSupportedTestProjectFile(path))
            {
                // remove project name from the path.
                path = Path.GetDirectoryName(path);
            }

            return(succeeded);
        }
        public IEnumerable <ITestContainer> GetTestContainers(IVsProject project)
        {
            if (!project.TryGetProjectPath(out var path))
            {
                yield break;
            }

            // No need to search for tests in not supported projects.
            if (!TypeScriptHelpers.IsSupportedTestProjectFile(path))
            {
                yield break;
            }

            if (this.detectingChanges)
            {
                this.SaveModifiedFiles(project);
            }

            if (!this.knownProjects.TryGetValue(path, out var projectInfo) || !TryGetProjectUnitTestProperties(projectInfo.Project, out _, out _))
            {
                // Don't return any containers for projects we don't know about or that we know that they are not configured for JavaScript unit tests.
                yield break;
            }
            projectInfo.HasRequestedContainers = true;

            var latestWrite = project.GetProjectItemPaths().Aggregate(
                this.lastWrite,
                (latest, filePath) =>
            {
                try
                {
                    var ft = File.GetLastWriteTimeUtc(filePath);
                    return((ft > latest) ? ft : latest);
                }
                catch (Exception exc) when(exc is UnauthorizedAccessException || exc is ArgumentException || exc is IOException)
                {
                }
                return(latest);
            });

            yield return(new TestContainer(this, path, latestWrite));
        }