public void Will_set_amdbasepath_based_relative_to_settings_file_directory() { var service = new TestableChutzpahTestSettingsService(); var settings = new ChutzpahTestSettingsFile { AMDBasePath = "custom" }; service.Mock <IFileProbe>().Setup(x => x.FindTestSettingsFile(It.IsAny <string>())).Returns(@"C:\settingsDir6\settingsFile.json"); service.Mock <IFileProbe>().Setup(x => x.FindFolderPath(@"C:\settingsDir6\custom")).Returns(@"customPath"); service.Mock <IJsonSerializer>().Setup(x => x.DeserializeFromFile <ChutzpahTestSettingsFile>(It.IsAny <string>())).Returns(settings); service.ClassUnderTest.FindSettingsFile("dir6"); Assert.Equal(@"customPath", settings.AMDBasePath); }
private void ProcessProxy(ChutzpahTestSettingsFile settings, IDictionary <string, string> chutzpahVariables) { if (!string.IsNullOrEmpty(settings.Proxy)) { if (!ValidationHelper.IsValidProxySetting(settings.Proxy)) { settings.Proxy = string.Empty; ChutzpahTracer.TraceInformation("invalid proxy, must be in format of address:port"); } else { ChutzpahTracer.TraceInformation(string.Format("Proxy setting:{0}", settings.Proxy)); } } }
/// <summary> /// If the reference path is rooted (e.g. /some/path) and the user chose to adjust it then change it /// </summary> /// <returns></returns> private static string AdjustPathIfRooted(ChutzpahTestSettingsFile chutzpahTestSettings, string referencePath) { if (chutzpahTestSettings.RootReferencePathMode == RootReferencePathMode.SettingsFileDirectory && (referencePath.StartsWith("/") || referencePath.StartsWith("\\"))) { ChutzpahTracer.TraceInformation( "Changing reference '{0}' to be rooted from settings directory '{1}'", referencePath, chutzpahTestSettings.SettingsFileDirectory); referencePath = chutzpahTestSettings.SettingsFileDirectory + referencePath; } return(referencePath); }
public void Will_not_change_path_root_given_SettingsFileDirectory_RootReferencePathMode() { var processor = new TestableReferenceProcessor(); var referenceFiles = new List <ReferencedFile>(); var settings = new ChutzpahTestSettingsFile { RootReferencePathMode = RootReferencePathMode.DriveRoot, SettingsFileDirectory = @"C:\root" }; var text = @"/// <reference path=""/this/file.js"" /> some javascript code "; processor.ClassUnderTest.GetReferencedFiles(referenceFiles, processor.FrameworkDefinition, text, @"path1\test.js", settings); Assert.True(referenceFiles.Any(x => x.Path.Equals(@"/this/file.js"))); }
public void Will_set_custom_harness_directory_based_relative_to_settings_file_directory() { var service = new TestableChutzpahTestSettingsService(); var settings = new ChutzpahTestSettingsFile { TestHarnessLocationMode = TestHarnessLocationMode.Custom, TestHarnessDirectory = "custom" }; service.Mock <IFileProbe>().Setup(x => x.FindTestSettingsFile(It.IsAny <string>())).Returns(@"C:\settingsDir2\settingsFile.json"); service.Mock <IFileProbe>().Setup(x => x.FindFolderPath(@"C:\settingsDir2\custom")).Returns(@"customPath"); service.Mock <IJsonSerializer>().Setup(x => x.DeserializeFromFile <ChutzpahTestSettingsFile>(It.IsAny <string>())).Returns(settings); service.ClassUnderTest.FindSettingsFileFromDirectory("dir2"); Assert.Equal(@"customPath", settings.TestHarnessDirectory); }
public void Will_exclude_reference_from_harness_in_amd_mode() { var processor = new TestableReferenceProcessor(); var referenceFiles = new List <ReferencedFile>(); var settings = new ChutzpahTestSettingsFile { }; settings.TestHarnessReferenceMode = TestHarnessReferenceMode.AMD; var text = (@"/// <reference path=""lib.js"" /> some javascript code"); processor.ClassUnderTest.GetReferencedFiles(referenceFiles, processor.FrameworkDefinition, text, @"path\test.js", settings); Assert.True(referenceFiles.Any(x => x.Path == @"path\lib.js" && !x.IncludeInTestHarness)); }
private IList <ReferencedFile> GetReferencedFiles( HashSet <string> discoveredPaths, IFrameworkDefinition definition, string textToParse, string currentFilePath, ChutzpahTestSettingsFile chutzpahTestSettings) { var referencedFiles = new List <ReferencedFile>(); Regex regex = RegexPatterns.JsReferencePathRegex; foreach (Match match in regex.Matches(textToParse)) { if (!ShouldIncludeReference(match)) { continue; } string referencePath = match.Groups["Path"].Value; ProcessFilePathAsReference( discoveredPaths, definition, currentFilePath, chutzpahTestSettings, referencePath, referencedFiles, new ReferencePathSettings()); } foreach (Match match in RegexPatterns.JsTemplatePathRegex.Matches(textToParse)) { string referencePath = match.Groups["Path"].Value; referencePath = AdjustPathIfRooted(chutzpahTestSettings, referencePath); string relativeReferencePath = Path.Combine(Path.GetDirectoryName(currentFilePath), referencePath); string absoluteFilePath = fileProbe.FindFilePath(relativeReferencePath); if (referencedFiles.All(r => r.Path != absoluteFilePath)) { ChutzpahTracer.TraceInformation("Added html template '{0}' to referenced files", absoluteFilePath); referencedFiles.Add(new ReferencedFile { Path = absoluteFilePath, IsLocal = false, IncludeInTestHarness = true }); } } return(referencedFiles); }
private void RunBatchCompile(ChutzpahTestSettingsFile testSettings) { try { var result = processHelper.RunBatchCompileProcess(testSettings.Compile); if (result.ExitCode > 0) { throw new ChutzpahCompilationFailedException(result.StandardError, testSettings.SettingsFileName); } } catch (Exception e) { ChutzpahTracer.TraceError(e, "Error during batch compile of {0}", testSettings.SettingsFileName); throw new ChutzpahCompilationFailedException(e.Message, testSettings.SettingsFileName, e); } }
private string GetVersion(ChutzpahTestSettingsFile testSettingsFile) { if (!string.IsNullOrEmpty(testSettingsFile.FrameworkVersion) && (testSettingsFile.FrameworkVersion == "1" || testSettingsFile.FrameworkVersion.StartsWith("1."))) { return("1"); } if (!string.IsNullOrEmpty(testSettingsFile.FrameworkVersion) && (testSettingsFile.FrameworkVersion == "3" || testSettingsFile.FrameworkVersion.StartsWith("3."))) { return("3"); } return("2"); }
private void ResolveBatchCompileConfiguration(ChutzpahTestSettingsFile settings, IDictionary <string, string> chutzpahVariables) { if (settings.Compile != null) { settings.Compile.SettingsFileDirectory = settings.SettingsFileDirectory; settings.Compile.Extensions = settings.Compile.Extensions ?? new List <string>(); // If the mode is executable then set its properties if (settings.Compile.Mode == BatchCompileMode.Executable || (settings.Compile.Mode == null && !string.IsNullOrEmpty(settings.Compile.Executable))) { if (string.IsNullOrEmpty(settings.Compile.Executable)) { throw new ArgumentException("Executable path must be passed for compile setting"); } settings.Compile.Mode = BatchCompileMode.Executable; settings.Compile.Executable = ResolveFilePath(settings, ExpandVariable(chutzpahVariables, settings.Compile.Executable)); settings.Compile.Arguments = ExpandVariable(chutzpahVariables, settings.Compile.Arguments); settings.Compile.WorkingDirectory = ResolveFolderPath(settings, settings.Compile.WorkingDirectory); // Default timeout to 5 minutes if missing settings.Compile.Timeout = settings.Compile.Timeout.HasValue ? settings.Compile.Timeout.Value : 1000 * 60 * 5; } else { settings.Compile.Mode = BatchCompileMode.External; } // If Paths are not given if (!settings.Compile.Paths.Any()) { // If not Paths are given handle backcompat and look at sourcedirectory and outdirectory. // This will also handle the empty case in general since it will set empty values which will get resolved to the Chutzpah Settings file directory settings.Compile.Paths.Add(new CompilePathMap { SourcePath = settings.Compile.SourceDirectory, OutputPath = settings.Compile.OutDirectory }); } foreach (var pathMap in settings.Compile.Paths) { ResolveCompilePathMap(settings, chutzpahVariables, pathMap); } } }
public void Will_expand_variables_from_passed_in_environment() { var service = new TestableChutzpahTestSettingsService(); var environment = new ChutzpahSettingsFileEnvironment("path"); environment.Path = @"dir7"; environment.Properties.Add(new ChutzpahSettingsFileEnvironmentProperty("SomeName", "SomeValue")); var varStr = "%SomeName%"; var settings = new ChutzpahTestSettingsFile { Compile = new BatchCompileConfiguration { Executable = string.Format("path {0} ok", varStr), Arguments = string.Format("path {0} ok", varStr), OutDirectory = string.Format("path {0} ok", varStr), }, References = new [] { new SettingsFileReference { Path = varStr, Include = varStr, Exclude = varStr } }, Tests = new [] { new SettingsFileTestPath { Path = varStr, Include = varStr, Exclude = varStr } }, Transforms = new [] { new TransformConfig { Path = varStr } }, AMDBasePath = varStr, AMDBaseUrl = varStr }; service.Mock <IFileProbe>().Setup(x => x.FindTestSettingsFile(It.IsAny <string>())).Returns(@"C:\settingsDir7\settingsFile.json"); service.Mock <IJsonSerializer>().Setup(x => x.DeserializeFromFile <ChutzpahTestSettingsFile>(It.IsAny <string>())).Returns(settings); service.ClassUnderTest.FindSettingsFileFromDirectory("dir7", new ChutzpahSettingsFileEnvironments(new [] { environment })); Assert.True(settings.Compile.Executable.Contains("SomeValue")); Assert.True(settings.Compile.Arguments.Contains("SomeValue")); Assert.True(settings.Compile.OutDirectory.Contains("SomeValue")); Assert.True(settings.References.ElementAt(0).Path.Contains("SomeValue")); Assert.True(settings.References.ElementAt(0).Includes[0].Contains("SomeValue")); Assert.True(settings.References.ElementAt(0).Excludes[0].Contains("SomeValue")); Assert.True(settings.Tests.ElementAt(0).Path.Contains("SomeValue")); Assert.True(settings.Tests.ElementAt(0).Includes[0].Contains("SomeValue")); Assert.True(settings.Tests.ElementAt(0).Excludes[0].Contains("SomeValue")); Assert.True(settings.Transforms.ElementAt(0).Path.Contains("SomeValue")); Assert.True(settings.AMDBasePath.Contains("SomeValue")); Assert.True(settings.AMDBaseUrl.Contains("SomeValue")); }
private bool TryDetectFramework(string content, PathType pathType, ChutzpahTestSettingsFile chutzpahTestSettings, out IFrameworkDefinition definition) { var strategies = new Func <IFrameworkDefinition>[] { // Check chutzpah settings () => frameworkDefinitions.FirstOrDefault(x => x.FrameworkKey.Equals(chutzpahTestSettings.Framework, StringComparison.OrdinalIgnoreCase)), // Check if we see an explicit reference to a framework file (e.g. <reference path="qunit.js" />) () => frameworkDefinitions.FirstOrDefault(x => x.FileUsesFramework(content, false, pathType)), // Check using basic heuristic like looking for test( or module( for QUnit () => frameworkDefinitions.FirstOrDefault(x => x.FileUsesFramework(content, true, pathType)) }; definition = strategies.Select(x => x()).FirstOrDefault(x => x != null); return(definition != null); }
protected string BuildTestRunnerPath(ChutzpahTestSettingsFile chutzpahTestSettings, TestOptions options, string runnerName) { switch ((options.Engine ?? chutzpahTestSettings.Engine).GetValueOrDefault()) { case Engine.Phantom: return(@"ChutzpahJSRunners\Phantom\" + runnerName); case Engine.Chrome: return(@"ChutzpahJSRunners\Chrome\" + runnerName); case Engine.JsDom: return(@"ChutzpahJSRunners\JsDom\" + runnerName); default: throw new ArgumentException("Unknown browser"); } }
private void SetSettingsFileDirectoryOnRelativePathSettings(ChutzpahTestSettingsFile settings) { foreach (var test in settings.Tests) { test.SettingsFileDirectory = settings.SettingsFileDirectory; } foreach (var reference in settings.References) { reference.SettingsFileDirectory = settings.SettingsFileDirectory; } foreach (var transform in settings.Transforms) { transform.SettingsFileDirectory = settings.SettingsFileDirectory; } }
private List <TestContext> GetContexts() { var transforms = new TransformConfig[] { new TransformConfig { Name = "testtransform1", Path = "D:\testtransform.out" } }; var settings1 = new ChutzpahTestSettingsFile { SettingsFileDirectory = @"D:\directory1", Transforms = new List <TransformConfig> { new TransformConfig { Name = "testtransform1", Path = @"D:\testtransform1.out", SettingsFileDirectory = @"D:\directory1" } } }; var settings2 = new ChutzpahTestSettingsFile { SettingsFileDirectory = @"D:\directory2", Transforms = new List <TransformConfig> { new TransformConfig { Name = "testtransform1", Path = @"D:\testtransform1.out", SettingsFileDirectory = @"D:\directory2" }, new TransformConfig { Name = "testtransform2", Path = @"D:\testtransform2.out", SettingsFileDirectory = @"D:\directory2" } } }; return(new List <TestContext> { new TestContext { TestFileSettings = settings1 }, new TestContext { TestFileSettings = settings1 }, new TestContext { TestFileSettings = settings2 } }); }
private void ResolveTestHarnessDirectory(ChutzpahTestSettingsFile settings, IDictionary <string, string> chutzpahVariables) { if (settings.TestHarnessLocationMode == TestHarnessLocationMode.Custom) { if (settings.TestHarnessDirectory != null) { string absoluteFilePath = ResolveFolderPath(settings, ExpandVariable(chutzpahVariables, settings.TestHarnessDirectory)); settings.TestHarnessDirectory = absoluteFilePath; } if (settings.TestHarnessDirectory == null) { settings.TestHarnessLocationMode = TestHarnessLocationMode.TestFileAdjacent; ChutzpahTracer.TraceWarning("Unable to find custom test harness directory at {0}", settings.TestHarnessDirectory); } } }
public IEnumerable <PathInfo> FindScriptFiles(ChutzpahTestSettingsFile chutzpahTestSettings) { if (chutzpahTestSettings == null) { yield break; } foreach (var pathSettings in chutzpahTestSettings.Tests.Where(x => x != null)) { var includePatterns = pathSettings.Includes.Select(x => UrlBuilder.NormalizeFilePath(x)).ToList(); var excludePatterns = pathSettings.Excludes.Select(x => UrlBuilder.NormalizeFilePath(x)).ToList(); // The path we assume default to the chuzpah.json directory if the Path property is not set var testPath = string.IsNullOrEmpty(pathSettings.Path) ? pathSettings.SettingsFileDirectory : pathSettings.Path; testPath = UrlBuilder.NormalizeFilePath(testPath); testPath = testPath != null?Path.Combine(pathSettings.SettingsFileDirectory, testPath) : null; // If a file path is given just return that file var filePath = FindFilePath(testPath); if (filePath != null) { ChutzpahTracer.TraceInformation("Found file {0} from chutzpah.json", filePath); yield return(GetPathInfo(filePath)); } // If a folder path is given enumerate that folder (recursively) with the optional include/exclude paths var folderPath = FindFolderPath(testPath); if (folderPath != null) { var childFiles = fileSystem.GetFiles(UrlBuilder.NormalizeFilePath(folderPath, false), "*.*", SearchOption.AllDirectories); var validFiles = from file in childFiles let normalizedFile = UrlBuilder.NormalizeFilePath(file) where !IsTemporaryChutzpahFile(normalizedFile) && (!includePatterns.Any() || includePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat))) && (!excludePatterns.Any() || !excludePatterns.Any(pat => NativeImports.PathMatchSpec(normalizedFile, pat))) select file; foreach (var item in validFiles) { yield return(GetPathInfo(item)); } } } }
/// <summary> /// Determines if a compile is needed. To figure this out we check the following things: /// 1. Check if any source file which produces output is missing its output /// 2. Check if any source file which produces output is newer than its output /// 3. Check if any source file which does not produce output is newer than the oldest output file /// </summary> /// <param name="testSettings"></param> /// <param name="filePropeties"></param> /// <returns></returns> private static bool CheckIfCompileIsNeeded(ChutzpahTestSettingsFile testSettings, List <SourceCompileInfo> filePropeties) { if (!filePropeties.Any(x => x.SourceHasOutput)) { return(false); } // If SkipIfUnchanged is true then we check if all the output files are newer than the input files // we will only run the compile if this fails if (testSettings.Compile.SkipIfUnchanged) { var hasMissingOutput = filePropeties .Where(x => x.SourceHasOutput) .Any(x => !x.OutputProperties.Exists); if (!hasMissingOutput) { var pairFileHasChanged = filePropeties.Any(x => x.SourceHasOutput && x.SourceProperties.Exists && x.OutputProperties.Exists && x.SourceProperties.LastModifiedDate > x.OutputProperties.LastModifiedDate); var fileWithNoOutputHasChanged = false; var sourcesWithNoOutput = filePropeties.Where(x => x.SourceProperties.Exists && !x.SourceHasOutput).ToList(); if (sourcesWithNoOutput.Any()) { // Get the time of the newest file change of a file which has no output (like a .d.ts) var newestSourceWithNoOutputFileTime = sourcesWithNoOutput.Max(x => x.SourceProperties.LastModifiedDate); var oldestOutputFileTime = filePropeties .Where(x => x.SourceHasOutput && x.OutputProperties.Exists) .Min(x => x.OutputProperties.LastModifiedDate); fileWithNoOutputHasChanged = newestSourceWithNoOutputFileTime >= oldestOutputFileTime; } return(pairFileHasChanged || fileWithNoOutputHasChanged); } } return(true); }
public void Will_make_amd_path_relative_to_testHarnessLocation() { var processor = new TestableReferenceProcessor(); var testHarnessDirectory = @"c:\some\src\folder"; var referencedFile = new ReferencedFile { Path = @"C:\some\path\code\test.js" }; var referenceFiles = new List <ReferencedFile> { referencedFile }; var settings = new ChutzpahTestSettingsFile { }; processor.ClassUnderTest.SetupAmdFilePaths(referenceFiles, testHarnessDirectory, settings); Assert.Equal("../../path/code/test", referencedFile.AmdFilePath); Assert.Null(referencedFile.AmdGeneratedFilePath); }
public void Will_not_replace_directory_name_containing_extension_in_relative_amd_path() { var processor = new TestableReferenceProcessor(); var testHarnessDirectory = @"c:\some\src\folder"; var referencedFile = new ReferencedFile { Path = @"C:\some\path.jstests\code\test.js" }; var referenceFiles = new List <ReferencedFile> { referencedFile }; var settings = new ChutzpahTestSettingsFile { }; processor.ClassUnderTest.SetupAmdFilePaths(referenceFiles, testHarnessDirectory, settings); Assert.Equal("../../path.jstests/code/test", referencedFile.AmdFilePath); Assert.Null(referencedFile.AmdGeneratedFilePath); }
private IList <ReferencedFile> ExpandNestedReferences( HashSet <string> discoveredPaths, IFrameworkDefinition definition, string currentFilePath, ChutzpahTestSettingsFile chutzpahTestSettings) { try { string textToParse = fileSystem.GetText(currentFilePath); return(GetReferencedFiles(discoveredPaths, definition, textToParse, currentFilePath, chutzpahTestSettings)); } catch (IOException e) { // Unable to get file text ChutzpahTracer.TraceError(e, "Unable to get file text from test reference with path {0}", currentFilePath); } return(new List <ReferencedFile>()); }
public void Will_add_reference_url_to_referenced_files() { var processor = new TestableReferenceProcessor(); var referenceFiles = new List <ReferencedFile> { new ReferencedFile { IsFileUnderTest = true, Path = @"path\test.js", ExpandReferenceComments = true } }; var settings = new ChutzpahTestSettingsFile { }; var text = (@"/// <reference path=""http://a.com/lib.js"" /> some javascript code"); processor.Mock <IFileProbe>().Setup(x => x.GetReferencedFileContent(It.Is <ReferencedFile>(f => f.Path == @"path\test.js"), It.IsAny <ChutzpahTestSettingsFile>())).Returns(text); processor.ClassUnderTest.GetReferencedFiles(referenceFiles, processor.FrameworkDefinition, settings); Assert.True(referenceFiles.Any(x => x.Path == "http://a.com/lib.js")); }
private void ProcessPathSettings(ChutzpahTestSettingsFile settings, IDictionary <string, string> chutzpahVariables) { var i = 0; foreach (var test in settings.Tests) { test.SettingsFileDirectory = settings.SettingsFileDirectory; test.Path = ExpandVariable(chutzpahVariables, test.Path); for (i = 0; i < test.Includes.Count; i++) { test.Includes[i] = ExpandVariable(chutzpahVariables, test.Includes[i]); } for (i = 0; i < test.Excludes.Count; i++) { test.Excludes[i] = ExpandVariable(chutzpahVariables, test.Excludes[i]); } } foreach (var reference in settings.References) { reference.SettingsFileDirectory = settings.SettingsFileDirectory; reference.Path = ExpandVariable(chutzpahVariables, reference.Path); for (i = 0; i < reference.Includes.Count; i++) { reference.Includes[i] = ExpandVariable(chutzpahVariables, reference.Includes[i]); } for (i = 0; i < reference.Excludes.Count; i++) { reference.Excludes[i] = ExpandVariable(chutzpahVariables, reference.Excludes[i]); } } foreach (var transform in settings.Transforms) { transform.SettingsFileDirectory = settings.SettingsFileDirectory; transform.Path = ExpandVariable(chutzpahVariables, transform.Path); } }
private string GetReferenceFileContentAndSetHash(ReferencedFile file, ChutzpahTestSettingsFile settings) { if (!file.IsLocal) { return(null); } var text = fileSystem.GetText(file.Path); if (string.IsNullOrEmpty(file.Hash) && settings.Server != null && settings.Server.Enabled.GetValueOrDefault() && settings.Server.FileCachingEnabled.GetValueOrDefault()) { file.Hash = hasher.Hash(text); } return(text); }
public void Will_make_amd_path_relative_to_amdbaseurl_if_no_amdappdirectory_if_given() { var processor = new TestableReferenceProcessor(); var testHarnessDirectory = @"c:\some\path"; var referencedFile = new ReferencedFile { Path = @"C:\some\path\code\test.js" }; var referenceFiles = new List <ReferencedFile> { referencedFile }; var settings = new ChutzpahTestSettingsFile { AMDBaseUrl = @"C:\some\other" }; processor.ClassUnderTest.SetupAmdFilePaths(referenceFiles, testHarnessDirectory, settings); Assert.Equal("../path/code/test", referencedFile.AmdFilePath); Assert.Null(referencedFile.AmdGeneratedFilePath); }
public void Will_add_chutzpah_reference_to_referenced_files() { var processor = new TestableReferenceProcessor(); var referenceFiles = new List <ReferencedFile> { new ReferencedFile { IsFileUnderTest = true, Path = @"path\test.js" } }; var settings = new ChutzpahTestSettingsFile { }; var text = (@"/// <chutzpah_reference path=""lib.js"" /> some javascript code"); processor.Mock <IFileSystemWrapper>().Setup(x => x.GetText(@"path\test.js")).Returns(text); processor.ClassUnderTest.GetReferencedFiles(referenceFiles, processor.FrameworkDefinition, settings); Assert.True(referenceFiles.Any(x => x.Path.EndsWith("lib.js"))); }
public void Will_add_reference_file_to_referenced_files() { var processor = new TestableReferenceProcessor(); var settings = new ChutzpahTestSettingsFile { }.InheritFromDefault(); var referenceFiles = new List <ReferencedFile> { new ReferencedFile { IsFileUnderTest = true, Path = @"path\test.js", ExpandReferenceComments = true } }; var text = (@"/// <reference path=""lib.js"" /> some javascript code"); processor.Mock <IFileSystemWrapper>().Setup(x => x.GetText(@"path\test.js")).Returns(text); processor.ClassUnderTest.GetReferencedFiles(referenceFiles, processor.FrameworkDefinition, settings); Assert.True(referenceFiles.Any(x => x.Path == @"path\lib.js" && x.IncludeInTestHarness)); }
public static string GetInterfaceType(ChutzpahTestSettingsFile chutzpahTestSettings, string testFilePath, string testFileText) { if (!string.IsNullOrEmpty(chutzpahTestSettings.MochaInterface) && knownInterfaces.Contains(chutzpahTestSettings.MochaInterface, StringComparer.OrdinalIgnoreCase)) { return(chutzpahTestSettings.MochaInterface.ToLowerInvariant()); } var isCoffeeFile = testFilePath.EndsWith(Constants.CoffeeScriptExtension, StringComparison.OrdinalIgnoreCase); if (isCoffeeFile) { if (RegexPatterns.MochaBddTestRegexCoffeeScript.IsMatch(testFileText)) { return(Constants.MochaBddInterface); } if (RegexPatterns.MochaTddOrQunitTestRegexCoffeeScript.IsMatch(testFileText)) { return(RegexPatterns.MochaTddSuiteRegexCoffeeScript.IsMatch(testFileText) ? Constants.MochaTddInterface : Constants.MochaQunitInterface); } if (RegexPatterns.MochaExportsTestRegexCoffeeScript.IsMatch(testFileText)) { return(Constants.MochaExportsInterface); } } else { if (RegexPatterns.MochaBddTestRegexJavaScript.IsMatch(testFileText)) { return(Constants.MochaBddInterface); } if (RegexPatterns.MochaTddOrQunitTestRegexJavaScript.IsMatch(testFileText)) { return(RegexPatterns.MochaTddSuiteRegexJavaScript.IsMatch(testFileText) ? Constants.MochaTddInterface : Constants.MochaQunitInterface); } if (RegexPatterns.MochaExportsTestRegexJavaScript.IsMatch(testFileText)) { return(Constants.MochaExportsInterface); } } return(Constants.MochaBddInterface); }
public void Will_not_add_referenced_file_if_it_is_excluded() { var processor = new TestableReferenceProcessor(); var referenceFiles = new List <ReferencedFile>(); var settings = new ChutzpahTestSettingsFile { }; var text = @"/// <reference path=""lib.js"" /> /// <reference path=""../../js/excluded.js"" chutzpah-exclude=""true"" /> /// <reference path=""../../js/doublenegative.js"" chutzpah-exclude=""false"" /> /// <reference path=""../../js/excluded.js"" chutzpahExclude=""true"" /> /// <reference path=""../../js/doublenegative.js"" chutzpahExclude=""false"" /> some javascript code "; processor.ClassUnderTest.GetReferencedFiles(referenceFiles, processor.FrameworkDefinition, text, @"path1\test.js", settings); Assert.False(referenceFiles.Any(x => x.Path.EndsWith("excluded.js")), "Test context contains excluded reference."); Assert.True(referenceFiles.Any(x => x.Path.EndsWith("doublenegative.js")), "Test context does not contain negatively excluded reference."); }
public void Will_only_include_one_reference_with_mulitple_references_in_html_template() { var processor = new TestableReferenceProcessor(); var referenceFiles = new List <ReferencedFile> { new ReferencedFile { IsFileUnderTest = true, Path = @"path\test.js" } }; var settings = new ChutzpahTestSettingsFile { }; var text = (@"/// <template path=""../../templates/file.html"" /> /// <template path=""../../templates/file.html"" /> some javascript code"); processor.Mock <IFileSystemWrapper>().Setup(x => x.GetText(@"path\test.js")).Returns(text); processor.ClassUnderTest.GetReferencedFiles(referenceFiles, processor.FrameworkDefinition, settings); Assert.Equal(1, referenceFiles.Count(x => x.Path.EndsWith("file.html"))); }