Example #1
0
        internal bool IsTestFile(string pathToFile)
        {
            var project = this.GetTestProjectFromFile(pathToFile);

            if (project == null)
            {
                //The file is not included in the project.
                //Don't look for tests in it.
                return(false);
            }

            //
            //Check to see if we are dealing with a TypeScript file
            //  If we are then switch the test container to the underlying js file
            //
            if (TypeScriptHelpers.IsTypeScriptFile(pathToFile))
            {
                var jsFile = TypeScriptHelpers.GetTypeScriptBackedJavaScriptFile(project, pathToFile);
                if (jsFile == null || !File.Exists(jsFile))
                {
                    //Ignore the file for now.  On the next build event the typescript compiler will generate the file
                    //  at that point this function gets invoked again on the .ts file and we'll see the newly created .js file
                    return(false);
                }
            }
            else if (!TypeScriptHelpers.IsJavaScriptFile(pathToFile))
            {
                return(false);
            }

            if (TryGetProjectUnitTestProperties(project, out var testRoot, out _) &&
                !string.IsNullOrEmpty(testRoot) &&
                project.TryGetProjectDirectory(out var root))
            {
                var testRootPath = Path.Combine(root, testRoot);

                return(CommonUtils.IsSubpathOf(testRootPath, pathToFile));
            }

            ErrorHandler.Succeeded(((IVsHierarchy)project).ParseCanonicalName(pathToFile, out var itemId));

            return(IsTestFile(itemId, project));
        }