private static void TestPositions(bool coffeeScript, string[] lines, FilePosition[] positions) { var path = coffeeScript ? "path.coffee" : "path"; var processor = new TestableMochaLineNumberProcessor(); var file = new ReferencedFile { IsLocal = true, IsFileUnderTest = true, Path = path }; processor.ClassUnderTest.Process(new Mock <IFrameworkDefinition>().Object, file, String.Join("\n", lines), new ChutzpahTestSettingsFile().InheritFromDefault()); Assert.True( file.FilePositions.Contains(positions.Length - 1), "Should not have less than the expected number of FilePositions"); Assert.False( file.FilePositions.Contains(positions.Length), "Should not have more than the expected number of FilePositions"); for (int i = 0; i < positions.Length; i++) { var expectedPosition = positions[i]; var actualPosition = file.FilePositions[i]; Assert.True( expectedPosition.Line == actualPosition.Line, string.Format("Line indexes should match for position {0}.\nActual: {1}, Expected: {2}", i, actualPosition.Line, expectedPosition.Line)); Assert.True( expectedPosition.Column == actualPosition.Column, string.Format("Column indexes should match for position {0}.\nActual: {1}, Expected: {2}", i, actualPosition.Column, expectedPosition.Column)); } }
public override Regex GetTestPattern(ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings) { var mochaFrameworkDefinition = MochaDefinition.GetInterfaceType(settings, referencedFile.Path, testFileText); var isCoffeeFile = referencedFile.Path.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase); switch (mochaFrameworkDefinition) { case Constants.MochaQunitInterface: return(isCoffeeFile ? RegexPatterns.MochaTddOrQunitTestRegexCoffeeScript : RegexPatterns.MochaTddOrQunitTestRegexJavaScript); case Constants.MochaBddInterface: return(isCoffeeFile ? RegexPatterns.MochaBddTestRegexCoffeeScript : RegexPatterns.MochaBddTestRegexJavaScript); case Constants.MochaTddInterface: return(isCoffeeFile ? RegexPatterns.MochaTddOrQunitTestRegexCoffeeScript : RegexPatterns.MochaTddOrQunitTestRegexJavaScript); case Constants.MochaExportsInterface: return(isCoffeeFile ? RegexPatterns.MochaExportsTestRegexCoffeeScript : RegexPatterns.MochaExportsTestRegexJavaScript); default: return(isCoffeeFile ? RegexPatterns.MochaBddTestRegexCoffeeScript : RegexPatterns.MochaBddTestRegexJavaScript); } }
public ShortcutIcon(ReferencedFile referencedFile) : base(referencedFile, "link", false) { Attributes.Add("rel", "shortcut icon"); Attributes.Add("type", "image/png"); Attributes.Add("href", GetAbsoluteFileUrl(referencedFile)); }
public ExternalStylesheet(ReferencedFile referencedFile) : base(referencedFile, "link", false) { Attributes.Add("rel", "stylesheet"); Attributes.Add("type", "text/css"); Attributes.Add("href", referencedFile.PathForUseInTestHarness); }
private void ExpandGraphNode(SolutionGraph graph, ProjectGraphNode node) { if (node.IsAlreadyExpanded) { return; } foreach (var projectRef in node.Project.ProjectReferences) { var projectRefNode = TryCreateGraphNode(graph, projectRef); if (projectRefNode != null) { node.ProjectRequirements.Add(projectRefNode); } } var nugetPackages = _nugetReferenceReader.TryReadPackagesConfig(node.Project.ProjectDirectory); foreach (var fileReference in node.Project.FileReferences) { var nugetPackage = nugetPackages?.FindPackage(fileReference.Include.ID); if (nugetPackage != null) { var nugetReference = new NugetReference(node.Project, nugetPackage, fileReference.GetFile(), fileReference.VersionFromPath ?? VersionWithSuffix.Empty()); node.NugetPackageRequirements.Add(nugetReference); } else { var reference = new ReferencedFile(node.Project, fileReference.GetFile(), fileReference.Include.Version); node.FileRequirements.Add(reference); } } }
public void Will_set_line_position_to_zero_when_no_matching_file_position() { var reader = new TestableTestCaseStreamReader(); var json = @"#_#TestDone#_# {""type"":""TestDone"",""testCase"":{""moduleName"":""module"",""testName"":""test"",""testResults"":[]}}"; var referencedFile = new ReferencedFile { IsFileUnderTest = true, Path = "inputTestFile", FilePositions = new FilePositions() }; var context = new TestContext { TestHarnessPath = "htmlTestFile", InputTestFile = "inputTestFile", ReferencedFiles = new[] { referencedFile } }; var stream = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(json))); var processStream = new ProcessStream(new Mock <IProcessWrapper>().Object, stream); var callback = new Mock <ITestMethodRunnerCallback>(); TestCase result = null; callback.Setup(x => x.TestFinished(It.IsAny <TestCase>())).Callback <TestCase>(t => result = t); reader.ClassUnderTest.Read(processStream, new TestOptions(), context, callback.Object, false); Assert.NotNull(result); Assert.Equal("module", result.ModuleName); Assert.Equal("test", result.TestName); Assert.Equal(0, result.Line); Assert.Equal(0, result.Column); }
public void Will_get_map_line_numbers_to_test_result() { var reader = new TestableTestCaseStreamReader(); var json = JsonStreamEvents.FileStartEventJson + JsonStreamEvents.TestStartEventJson + JsonStreamEvents.TestDoneEventJson; var referencedFile = new ReferencedFile { IsFileUnderTest = true, Path = "inputTestFile", FilePositions = new FilePositions() }; referencedFile.FilePositions.Add(1, 3, "test"); var context = new TestContext { TestHarnessPath = "htmlTestFile", ReferencedFiles = new[] { referencedFile } }; var stream = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(json))); var processStream = new ProcessStream(new Mock <IProcessWrapper>().Object, stream); var callback = new Mock <ITestMethodRunnerCallback>(); TestCase result = null; callback.Setup(x => x.TestFinished(It.IsAny <TestCase>())).Callback <TestCase>(t => result = t); reader.ClassUnderTest.Read(processStream, new TestOptions(), context, callback.Object, false); Assert.NotNull(result); Assert.Equal("module", result.ModuleName); Assert.Equal("test", result.TestName); Assert.Equal(1, result.Line); Assert.Equal(3, result.Column); }
/// <summary> /// Build test context with file and position info. /// </summary> /// <param name="fileTestPositionInfos"> /// Item1: file /// Item2: test /// Item3: line /// Item4: column /// </param> /// <returns></returns> public TestContext BuildContext(params Tuple <string, string, int, int>[] fileTestPositionInfos) { var referencedFiles = new List <ReferencedFile>(); var files = fileTestPositionInfos.Select(x => x.Item1).Distinct().ToList(); foreach (var file in files) { var referencedFile = new ReferencedFile { Path = file, IsFileUnderTest = true }; var positionsForFile = fileTestPositionInfos.Where(x => x.Item1 == file); foreach (var position in positionsForFile) { referencedFile.FilePositions.Add(position.Item3, position.Item4, position.Item2); } referencedFiles.Add(referencedFile); } if (files != null && files.Count > 0) { return(new TestContext { InputTestFiles = files, InputTestFilesString = string.Join(",", files), ReferencedFiles = referencedFiles }); } else { return(new TestContext()); } }
private IList <TestHarnessItem> ChooseRefList(ReferencedFile referencedFile, string referencePath) { var codeCoverageEnabled = (!chutzpahTestSettings.EnableCodeCoverage.HasValue && testOptions.CoverageOptions.Enabled) || (chutzpahTestSettings.EnableCodeCoverage.HasValue && chutzpahTestSettings.EnableCodeCoverage.Value); // If CodeCoverage is enabled and we are in Execution mode make sure we load requirejs before the code coverage files var amdLoader = codeCoverageEnabled && RegexPatterns.IsRequireJsFileName.IsMatch(Path.GetFileName(referencedFile.Path)) && testOptions.TestExecutionMode == TestExecutionMode.Execution; IList <TestHarnessItem> list = null; if (referencedFile.IsTestFrameworkFile) { list = TestFrameworkDependencies; } else if (referencedFile.IsCodeCoverageDependency || amdLoader) { list = CodeCoverageDependencies; } else if (referencePath.EndsWith(Constants.CssExtension, StringComparison.OrdinalIgnoreCase)) { list = ReferencedStyles; } else if (referencePath.EndsWith(Constants.JavaScriptExtension, StringComparison.OrdinalIgnoreCase)) { list = ReferencedScripts; } else if (referencePath.EndsWith(Constants.HtmlScriptExtension, StringComparison.OrdinalIgnoreCase) || referencePath.EndsWith(Constants.HtmScriptExtension, StringComparison.OrdinalIgnoreCase)) { list = ReferencedHtmlTemplates; } return(list); }
public void Will_set_line_position_to_zero_when_no_matching_file_position() { var reader = new TestableTestCaseStreamReader(); var json = JsonStreamEvents.FileStartEventJson + JsonStreamEvents.TestStartEventJson + JsonStreamEvents.TestDoneEventJson; var referencedFile = new ReferencedFile { IsFileUnderTest = true, Path = "inputTestFile", FilePositions = new FilePositions() }; var context = new TestContext { TestHarnessPath = "htmlTestFile", ReferencedFiles = new[] { referencedFile } }; var stream = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(json))); var processStream = new ProcessStreamStringSource(new Mock <IProcessWrapper>().Object, stream, 1000); var callback = new Mock <ITestMethodRunnerCallback>(); TestCase result = null; callback.Setup(x => x.TestFinished(It.Is <TestContext>(testContext => testContext == context), It.IsAny <TestCase>())).Callback <TestContext, TestCase>((c, t) => result = t); reader.ClassUnderTest.Read(processStream, new TestOptions(), context, callback.Object); Assert.NotNull(result); Assert.Equal("module", result.ModuleName); Assert.Equal("test", result.TestName); Assert.Equal(0, result.Line); Assert.Equal(0, result.Column); }
public ShortcutIcon(ReferencedFile referencedFile) : base(referencedFile, "link", false) { Attributes.Add("rel", "shortcut icon"); Attributes.Add("type", "image/png"); Attributes.Add("href", referencedFile.PathForUseInTestHarness); }
public ExternalStylesheet(ReferencedFile referencedFile) : base(referencedFile, "link", false) { Attributes.Add("rel", "stylesheet"); Attributes.Add("type", "text/css"); Attributes.Add("href", GetAbsoluteFileUrl(referencedFile)); }
/// <summary> /// Is this a source mapping for the current referenced file /// </summary> private bool IsCurrentFile(string relativePath, ReferencedFile referencedFile) { var candidatePath = UrlBuilder.NormalizeFilePath(new Uri(Path.Combine(Path.GetDirectoryName(referencedFile.SourceMapFilePath), relativePath)).AbsolutePath); var normalisedReferencedFilePath = UrlBuilder.NormalizeFilePath(new Uri(referencedFile.Path).AbsolutePath); return(normalisedReferencedFilePath.Equals(candidatePath, StringComparison.OrdinalIgnoreCase)); }
/// <summary> /// /// </summary> /// <param name="parentNode"></param> /// <param name="myReferencedFile"></param> /// <param name="theirReferencedFile"></param> /// <returns>True if the referenced files were different and a node was added, false if they were the same and no node was added.</returns> private bool AddReferencedFileNode(TreeListNode parentNode, ReferencedFile myReferencedFile, ReferencedFile theirReferencedFile) { if (myReferencedFile != null && theirReferencedFile != null) { if (Slyce.Common.Utility.StringsAreEqual(theirReferencedFile.FileName, myReferencedFile.FileName, false) && theirReferencedFile.UseInWorkbench == myReferencedFile.UseInWorkbench) { return(false); } if (theirReferencedFile.FileName != myReferencedFile.FileName) { AddNodeBoth("Location", theirReferencedFile.FileName, myReferencedFile.FileName, parentNode, null); } if (theirReferencedFile.UseInWorkbench != myReferencedFile.UseInWorkbench) { AddNodeBoth("Display In Workbench", theirReferencedFile.UseInWorkbench, myReferencedFile.UseInWorkbench, parentNode, null); } } else if (theirReferencedFile != null) { AddNodeTheirs("Location", theirReferencedFile.FileName, "", parentNode, null); AddNodeTheirs("Display In Workbench", theirReferencedFile.UseInWorkbench, "", parentNode, null); } else if (myReferencedFile != null) { AddNodeMine("Location", "", myReferencedFile.FileName, parentNode, null); AddNodeMine("Display In Workbench", "", myReferencedFile.UseInWorkbench, parentNode, null); } return(true); }
protected virtual void ProcessProjectReferences(XmlNodeList nodes, IDesignerProject project, string projectFilename) { if (nodes == null) { return; } List <ReferencedFile> referencedFiles = new List <ReferencedFile>(); foreach (XmlNode referenceNode in nodes) { NodeProcessor proc = new NodeProcessor(referenceNode); string relativeFileName = proc.Attributes.GetString("filename"); bool mergeWithAssembly = proc.Attributes.GetBool("mergewithassembly"); bool useInWorkbench = proc.Attributes.GetBool("useinworkbench"); bool isProvider = proc.Attributes.GetBool("isprovider"); string fileName = controller.ToAbsolutePath(relativeFileName, projectFilename); ReferencedFile file = new ReferencedFile(fileName, mergeWithAssembly, useInWorkbench); file.IsProvider = isProvider; referencedFiles.Add(file); } project.SetReferencedFiles(referencedFiles); }
public void Process(IFrameworkDefinition frameworkDefinition, ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings) { if (!referencedFile.IsFileUnderTest) { return; } var regExp = settings.TestPatternRegex ?? GetTestPattern(referencedFile, testFileText, settings); var lines = fileSystem.GetLines(referencedFile.Path); int lineNum = 1; foreach (var line in lines) { var match = regExp.Match(line); while (match.Success) { var testNameGroup = match.Groups["TestName"]; var testName = testNameGroup.Value; if (!string.IsNullOrWhiteSpace(testName)) { referencedFile.FilePositions.Add(lineNum, testNameGroup.Index + 1, testName); } match = match.NextMatch(); } lineNum++; } }
public override Regex GetTestPattern(ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings) { var isCoffeeFile = referencedFile.Path.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase); var regExp = isCoffeeFile ? RegexPatterns.JasmineTestRegexCoffeeScript : RegexPatterns.JasmineTestRegexJavaScript; return(regExp); }
private static void AddLineNumber(ReferencedFile referencedFile, int testIndex, JsTestCase jsTestCase) { if (referencedFile != null && referencedFile.FilePositions.Contains(testIndex)) { var position = referencedFile.FilePositions[testIndex]; jsTestCase.TestCase.Line = position.Line; jsTestCase.TestCase.Column = position.Column; } }
public void Will_get_skip_if_file_is_not_under_test() { var processor = new TestableMochaLineNumberProcessor(); var file = new ReferencedFile { IsLocal = true, IsFileUnderTest = false, Path = "path" }; processor.ClassUnderTest.Process(new Mock<IFrameworkDefinition>().Object, file, "", new ChutzpahTestSettingsFile().InheritFromDefault()); processor.Mock<IFileSystemWrapper>().Verify(x => x.GetLines(It.IsAny<string>()), Times.Never()); }
public Html(ReferencedFile referencedFile, IFileSystemWrapper fileSystem) : base(referencedFile, null, false) { contents = fileSystem.GetText(referencedFile.Path); if (referencedFile.TemplateOptions.Mode == TemplateMode.Script) { contents = string.Format(scriptTagWrapper, referencedFile.TemplateOptions.Id, referencedFile.TemplateOptions.Type, contents); } }
/// <summary> /// Processes a referenced file according to the framework's needs. /// </summary> /// <param name="referencedFile">A referenced file to process.</param> /// <param name="testFileText"></param> /// <param name="settings"></param> public void Process(ReferencedFile referencedFile, string testFileText, ChutzpahTestSettingsFile settings) { if (FileProcessors != null) { foreach (IReferencedFileProcessor item in FileProcessors) { item.Process(this, referencedFile, testFileText, settings); } } }
public void Will_return_true_for_coffee_script_files() { var converter = new TestableCoffeeScriptFileGenerator(); var file = new ReferencedFile { Path = "somePath.coffee" }; var result = converter.ClassUnderTest.CanHandleFile(file); Assert.True(result); }
protected void WriteGeneratedReferencedFile(ReferencedFile referencedFile, string generatedContent, IList <string> temporaryFiles) { var folderPath = Path.GetDirectoryName(referencedFile.Path); var fileName = Path.GetFileNameWithoutExtension(referencedFile.Path) + ".js"; var newFilePath = Path.Combine(folderPath, string.Format(Constants.ChutzpahTemporaryFileFormat, Thread.CurrentThread.ManagedThreadId, fileName)); fileSystem.WriteAllText(newFilePath, generatedContent); referencedFile.GeneratedFilePath = newFilePath; temporaryFiles.Add(newFilePath); }
public void Will_return_false_for_non_typescript_script_files() { var converter = new TestableTypeScriptFileGenerator(); var file = new ReferencedFile { Path = "somePath.js" }; var result = converter.ClassUnderTest.CanHandleFile(file); Assert.False(result); }
public TestFileContext(ReferencedFile referencedFile, TestContext testContext, bool coverageEnabled) { SeenTests = new HashSet <Tuple <string, string> >(); ReferencedFile = referencedFile; TestContext = testContext; TestFileSummary = new TestFileSummary(referencedFile.Path); if (coverageEnabled) { TestFileSummary.CoverageObject = new CoverageData(); } }
private static IEnumerable <ReferencedFile> FlattenReferenceGraph(ReferencedFile rootFile) { var flattenedFileList = new List <ReferencedFile>(); foreach (ReferencedFile childFile in rootFile.ReferencedFiles) { flattenedFileList.AddRange(FlattenReferenceGraph(childFile)); } flattenedFileList.Add(rootFile); return(flattenedFileList); }
protected static string GetAbsoluteFileUrl(ReferencedFile referencedFile) { string referencePath = string.IsNullOrEmpty(referencedFile.GeneratedFilePath) ? referencedFile.Path : referencedFile.GeneratedFilePath; if (!RegexPatterns.SchemePrefixRegex.IsMatch(referencePath)) { // Encode the reference path and then decode / (forward slash) and \ (back slash) into / (forward slash) return(FileProbe.GenerateFileUrl(referencePath)); } return(referencePath); }
public void Will_do_nothing_when_file_is_not_supported() { var generator = new TestableCompileToJavascriptFileGenerator(); generator.ClassUnderTest.CanHandle = false; var file = new ReferencedFile { Path = "somePath.js" }; var tempFiles = new List <string>(); generator.ClassUnderTest.Generate(new[] { file }, tempFiles, new ChutzpahTestSettingsFile()); Assert.Equal("somePath.js", file.Path); Assert.Empty(tempFiles); }
public void Will_set_amd_path_for_reference_path_and_generated_path() { var processor = new TestableReferenceProcessor(); var testHarnessDirectory = @"C:\some\path"; var referencedFile = new ReferencedFile { Path = @"C:\some\path\code\test.ts", GeneratedFilePath = @"C:\some\path\code\_Chutzpah.1.test.js" }; var referenceFiles = new List <ReferencedFile> { referencedFile }; processor.ClassUnderTest.SetupAmdFilePaths(referenceFiles, testHarnessDirectory, new ChutzpahTestSettingsFile().InheritFromDefault()); Assert.Equal("code/test", referencedFile.AmdFilePath); }
public void Will_return_compiled_files() { var generator = new TestableTypeScriptFileGenerator(); var file = new ReferencedFile { Path = "path1.ts" }; generator.Mock <ITypeScriptEngineWrapper>().Setup(x => x.Compile(It.IsAny <string>(), It.IsAny <object[]>())).Returns("{\"path1.ts\" :\"compiled\""); generator.Mock <IFileSystemWrapper>().Setup(x => x.GetText(It.IsAny <string>())).Returns("content"); generator.Mock <ITypeScriptEngineWrapper>().Setup(x => x.Compile(It.IsAny <string>())).Returns((string)null); var result = generator.ClassUnderTest.GenerateCompiledSources(new[] { file }, new ChutzpahTestSettingsFile()); Assert.Equal("compiled", result[file.Path]); }