public void CreateTestHarness(TestContext testContext, TestOptions options) { if (!string.IsNullOrEmpty(testContext.TestHarnessPath)) { // If we already have a test harness path then this means we executed on an existing html file or url // So we dont need to generate the harness return; } referenceProcessor.SetupPathsFormattedForTestHarness(testContext, testContext.ReferencedFiles.ToList()); SetupAmdPathsIfNeeded(testContext.TestFileSettings, testContext.ReferencedFiles.ToList(), testContext.TestHarnessDirectory); string testFilePathHash = hasher.Hash(string.Join(",", testContext.InputTestFiles)); string testHtmlFilePath = Path.Combine(testContext.TestHarnessDirectory, string.Format(Constants.ChutzpahTemporaryFileFormat, testFilePathHash, "test.html")); testContext.TemporaryFiles.Add(testHtmlFilePath); var templatePath = GetTestHarnessTemplatePath(testContext.FrameworkDefinition, testContext.TestFileSettings); string testHtmlTemplate = fileSystem.GetText(templatePath); var harness = new TestHarness(testContext, options, testContext.ReferencedFiles, fileSystem, urlBuilder); if (testContext.CoverageEngine != null) { testContext.CoverageEngine.PrepareTestHarnessForCoverage(harness, testContext.FrameworkDefinition, testContext.TestFileSettings); } var kvps = testContext.ReferencedFiles .Where(x => x.IsFileUnderTest) .SelectMany(x => x.FrameworkReplacements); var frameworkReplacements = new Dictionary <string, string>(); foreach (var pair in kvps) { frameworkReplacements[pair.Key] = pair.Value; } string testHtmlText = harness.CreateHtmlText(testHtmlTemplate, frameworkReplacements); fileSystem.Save(testHtmlFilePath, testHtmlText); testContext.TestHarnessPath = testHtmlFilePath; }
public void CreateTestHarness(TestContext testContext, TestOptions options) { if (!string.IsNullOrEmpty(testContext.TestHarnessPath)) { // If we already have a test harness path then this means we executed on an existing html file or url // So we dont need to generate the harness return; } SetupAmdPathsIfNeeded(testContext.TestFileSettings, testContext.ReferencedFiles.ToList(), testContext.TestHarnessDirectory); string testFilePathHash = hasher.Hash(string.Join(",",testContext.InputTestFiles)); string testHtmlFilePath = Path.Combine(testContext.TestHarnessDirectory, string.Format(Constants.ChutzpahTemporaryFileFormat, testFilePathHash, "test.html")); testContext.TemporaryFiles.Add(testHtmlFilePath); var templatePath = GetTestHarnessTemplatePath(testContext.FrameworkDefinition, testContext.TestFileSettings); string testHtmlTemplate = fileSystem.GetText(templatePath); var harness = new TestHarness(testContext.TestFileSettings, options, testContext.ReferencedFiles, fileSystem); if (testContext.CoverageEngine != null) { testContext.CoverageEngine.PrepareTestHarnessForCoverage(harness, testContext.FrameworkDefinition, testContext.TestFileSettings); } var kvps = testContext.ReferencedFiles .Where(x => x.IsFileUnderTest) .SelectMany(x => x.FrameworkReplacements); var frameworkReplacements = new Dictionary<string, string>(); foreach (var pair in kvps) { frameworkReplacements[pair.Key] = pair.Value; } string testHtmlText = harness.CreateHtmlText(testHtmlTemplate, frameworkReplacements); fileSystem.Save(testHtmlFilePath, testHtmlText); testContext.TestHarnessPath = testHtmlFilePath; }
public void CreateTestHarness(TestContext testContext, TestOptions options) { if (!string.IsNullOrEmpty(testContext.TestHarnessPath)) { // If we already have a test harness path then this means we executed on an existing html file or url // So we dont need to generate the harness return; } SetupAmdPathsIfNeeded(testContext.TestFileSettings, testContext.ReferencedFiles.ToList(), testContext.TestHarnessDirectory); string testFilePathHash = hasher.Hash(testContext.InputTestFile); string testHtmlFilePath = Path.Combine(testContext.TestHarnessDirectory, string.Format(Constants.ChutzpahTemporaryFileFormat, testFilePathHash, "test.html")); testContext.TemporaryFiles.Add(testHtmlFilePath); var templatePath = GetTestHarnessTemplatePath(testContext.FrameworkDefinition, testContext.TestFileSettings); string testHtmlTemplate = fileSystem.GetText(templatePath); var harness = new TestHarness(testContext.TestFileSettings, options, testContext.ReferencedFiles, fileSystem); if (testContext.CoverageEngine != null) { testContext.CoverageEngine.PrepareTestHarnessForCoverage(harness, testContext.FrameworkDefinition, testContext.TestFileSettings); } string testFileContents = fileSystem.GetText(testContext.InputTestFile); var frameworkReplacements = testContext.FrameworkDefinition.GetFrameworkReplacements(testContext.TestFileSettings, testContext.InputTestFile, testFileContents) ?? new Dictionary <string, string>(); string testHtmlText = harness.CreateHtmlText(testHtmlTemplate, frameworkReplacements); fileSystem.Save(testHtmlFilePath, testHtmlText); testContext.TestHarnessPath = testHtmlFilePath; }
private string CreateTestHarness( IFrameworkDefinition definition, ChutzpahTestSettingsFile chutzpahTestSettings, TestOptions options, string inputTestFilePath, IEnumerable<ReferencedFile> referencedFiles, ICoverageEngine coverageEngine, IList<string> temporaryFiles) { string inputTestFileDir = Path.GetDirectoryName(inputTestFilePath); string testFilePathHash = hasher.Hash(inputTestFilePath); string testHarnessDirectory; switch (chutzpahTestSettings.TestHarnessLocationMode) { case TestHarnessLocationMode.TestFileAdjacent: testHarnessDirectory = inputTestFileDir; break; case TestHarnessLocationMode.SettingsFileAdjacent: testHarnessDirectory = chutzpahTestSettings.SettingsFileDirectory; break; case TestHarnessLocationMode.Custom: testHarnessDirectory = chutzpahTestSettings.TestHarnessDirectory; break; default: throw new ArgumentOutOfRangeException("chutzpahTestSettings"); } string testHtmlFilePath = Path.Combine(testHarnessDirectory, string.Format(Constants.ChutzpahTemporaryFileFormat, testFilePathHash, "test.html")); temporaryFiles.Add(testHtmlFilePath); string templatePath = fileProbe.GetPathInfo(Path.Combine(Constants.TestFileFolder, definition.TestHarness)).FullPath; string testHtmlTemplate = fileSystem.GetText(templatePath); string amdModulePath = ""; if (chutzpahTestSettings.TestHarnessReferenceMode == TestHarnessReferenceMode.AMD && inputTestFilePath.Contains(testHarnessDirectory)) { amdModulePath = inputTestFilePath .Replace(Path.GetExtension(inputTestFilePath), "") .Replace(testHarnessDirectory, "") .Replace("\\", "/") .Trim('/', '\\'); } var harness = new TestHarness(chutzpahTestSettings, options, referencedFiles, fileSystem, amdModulePath); if (coverageEngine != null) { coverageEngine.PrepareTestHarnessForCoverage(harness, definition); } string testFileContents = fileSystem.GetText(inputTestFilePath); var frameworkReplacements = definition.GetFrameworkReplacements(chutzpahTestSettings, inputTestFilePath, testFileContents) ?? new Dictionary<string, string>(); string testHtmlText = harness.CreateHtmlText(testHtmlTemplate, frameworkReplacements); fileSystem.Save(testHtmlFilePath, testHtmlText); return testHtmlFilePath; }