Skip to content

Commit

Permalink
Allow compilation inheritance and rev to version 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mmanela committed Feb 2, 2016
1 parent 6248789 commit d483d2a
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 41 deletions.
13 changes: 8 additions & 5 deletions Chutzpah/BatchCompiler/BatchCompilerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ where testSettings.Compile.Extensions.Any(x => file.Path.EndsWith(x, StringCompa
{
RunBatchCompile(testSettings);
}
else if(testSettings.Compile.Mode == BatchCompileMode.External)
else
{
ChutzpahTracer.TraceWarning("Chutzpah determined generated .js files are missing but the compile mode is External so Chutzpah can't compile them. Test results may be wrong.");
}
Expand All @@ -87,13 +87,16 @@ where testSettings.Compile.Extensions.Any(x => file.Path.EndsWith(x, StringCompa
var error = string.Format("Couldn't find generated path for {0} at {1}", file.Path, outputPath);
ChutzpahTracer.TraceError(error);

// Throw and fail here since if we cant find the file we cannot be sure anything will run
throw new FileNotFoundException(error, outputPath);
if (!testSettings.Compile.IgnoreMissingFiles.GetValueOrDefault())
{
// Throw and fail here since if we cant find the file we cannot be sure anything will run
throw new FileNotFoundException(error, outputPath);
}
}

if (!string.IsNullOrWhiteSpace(file.GeneratedFilePath))
{
file.SourceMapFilePath = testSettings.Compile.UseSourceMaps ? sourceMapDiscoverer.FindSourceMap(file.GeneratedFilePath) : null;
file.SourceMapFilePath = testSettings.Compile.UseSourceMaps.GetValueOrDefault() ? sourceMapDiscoverer.FindSourceMap(file.GeneratedFilePath) : null;
}
}
}
Expand Down Expand Up @@ -133,7 +136,7 @@ private static bool CheckIfCompileIsNeeded(ChutzpahTestSettingsFile testSettings

// 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)
if (testSettings.Compile.SkipIfUnchanged.GetValueOrDefault())
{
var hasMissingOutput = filePropeties
.Where(x => x.SourceHasOutput)
Expand Down
23 changes: 18 additions & 5 deletions Chutzpah/ChutzpahTestSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -313,19 +313,25 @@ private void ResolveBatchCompileConfiguration(ChutzpahTestSettingsFile settings,


// If the mode is executable then set its properties
if (settings.Compile.Mode == BatchCompileMode.Executable)
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;
}



Expand All @@ -347,15 +353,21 @@ private void ResolveBatchCompileConfiguration(ChutzpahTestSettingsFile settings,
private void ResolveCompilePathMap(ChutzpahTestSettingsFile settings, IDictionary<string, string> chutzpahVariables, CompilePathMap pathMap)
{
var sourcePath = pathMap.SourcePath;
bool? sourcePathIsFile;
bool? sourcePathIsFile = false;

// If SourcePath is null then we will assume later on this is the current settings directory
pathMap.SourcePath = ResolvePath(settings, sourcePath, out sourcePathIsFile);
if (pathMap.SourcePath == null)
{
throw new FileNotFoundException("Unable to find file/directory specified by SourcePath of {0}", (sourcePath ?? ""));
}


pathMap.SourcePathIsFile = sourcePathIsFile.HasValue ? sourcePathIsFile.Value : false;

// If OutputPath is null then we will assume later on this is the current settings directory
// We do not use the resolvePath method here since the path may not exist yet

pathMap.OutputPath = FileProbe.NormalizeFilePath(Path.Combine(settings.SettingsFileDirectory, ExpandVariable(chutzpahVariables, pathMap.OutputPath)));
if (pathMap.OutputPath == null)
{
Expand All @@ -374,6 +386,7 @@ private void ResolveCompilePathMap(ChutzpahTestSettingsFile settings, IDictionar
{
pathMap.OutputPathIsFile = pathMap.OutputPath.EndsWith(".js", StringComparison.OrdinalIgnoreCase);
}

}


Expand All @@ -382,10 +395,10 @@ private string ResolvePath(ChutzpahTestSettingsFile settings, string path, out b
isFile = null;

var filePath = ResolveFilePath(settings, path);
if(filePath == null)
if (filePath == null)
{
filePath = ResolveFolderPath(settings, path);
if(filePath != null)
if (filePath != null)
{
isFile = false;
}
Expand Down Expand Up @@ -415,7 +428,7 @@ private string ResolveFilePath(ChutzpahTestSettingsFile settings, string path)
string absoluteFilePath = fileProbe.FindFilePath(relativeLocationPath);
return absoluteFilePath;
}


private string ExpandVariable(IDictionary<string, string> chutzpahCompileVariables, string str)
{
Expand Down
2 changes: 1 addition & 1 deletion Chutzpah/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Chutzpah
{
public static class Constants
{
public const string ChutzpahVersion = "4.1.0";
public const string ChutzpahVersion = "4.2.0";

public const string TestFileFolder = "TestFiles";

Expand Down
4 changes: 2 additions & 2 deletions Chutzpah/Coverage/BlanketJsCoverageEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public CoverageData DeserializeCoverageObject(string json, TestContext testConte
var coveredPath = referencedFile.GeneratedFilePath ?? referencedFile.Path;

// If the user is using source maps then always take sourcePath and not generates.
if (testContext.TestFileSettings.Compile != null && testContext.TestFileSettings.Compile.UseSourceMaps && referencedFile.SourceMapFilePath != null)
if (testContext.TestFileSettings.Compile != null && testContext.TestFileSettings.Compile.UseSourceMaps.GetValueOrDefault() && referencedFile.SourceMapFilePath != null)
{
coveredPath = referencedFile.Path;
}
Expand All @@ -204,7 +204,7 @@ public CoverageData DeserializeCoverageObject(string json, TestContext testConte
string[] sourceLines = fileSystem.GetLines(coveredPath);
int?[] lineExecutionCounts = entry.Value;

if (testContext.TestFileSettings.Compile != null && testContext.TestFileSettings.Compile.UseSourceMaps && referencedFile.SourceMapFilePath != null)
if (testContext.TestFileSettings.Compile != null && testContext.TestFileSettings.Compile.UseSourceMaps.GetValueOrDefault() && referencedFile.SourceMapFilePath != null)
{
lineExecutionCounts = this.lineCoverageMapper.GetOriginalFileLineExecutionCounts(entry.Value, sourceLines.Length, referencedFile);
}
Expand Down
18 changes: 12 additions & 6 deletions Chutzpah/Models/BatchCompileConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace Chutzpah.Models
{
public enum BatchCompileMode
{
Executable,
External
External,
Executable
}


Expand Down Expand Up @@ -51,15 +51,14 @@ public BatchCompileConfiguration()
Extensions = new List<string>();
ExtensionsWithNoOutput = new List<string>();
SkipIfUnchanged = true;
Mode = BatchCompileMode.Executable;
Paths = new List<CompilePathMap>();
}

/// <summary>
/// Determines the mode of the compile setting. By default it is to run the executable but if you set it to External
/// then Chutzpah assumes some external force will compile and Chutzpah will just look for generated JS files
/// </summary>
public BatchCompileMode Mode { get; set; }
public BatchCompileMode? Mode { get; set; }

/// <summary>
/// The extension of the files which are getting compiled
Expand Down Expand Up @@ -118,17 +117,24 @@ public BatchCompileConfiguration()
/// This is defaulted to true but if you hit issues since it is possible chutzpah might not know about all the files your compilation
/// code is using then you can turn this off. Ideally you can tell Chutzpah about these and then set this to be more performant
/// </summary>
public bool SkipIfUnchanged { get; set; }
public bool? SkipIfUnchanged { get; set; }

/// <summary>
/// Configures whether .map files should be loaded (if available) to convert under-test JS
/// line numbers to those of their original source files.
/// </summary>
public bool UseSourceMaps { get; set; }
public bool? UseSourceMaps { get; set; }

/// <summary>
/// Should Chutzpah ignore files it expects to find compiled. If set
/// to true Chutzpah will log an error otherwise it will throw
/// </summary>
public bool? IgnoreMissingFiles{ get; set; }

/// <summary>
/// The settings file directory that this batch compile configuration came from
/// </summary>
[JsonIgnore]
public string SettingsFileDirectory { get; set; }
}
}
16 changes: 16 additions & 0 deletions Chutzpah/Models/ChutzpahTestSettingsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Text.RegularExpressions;
using System.Linq;
using Newtonsoft.Json;

namespace Chutzpah.Models
{
Expand Down Expand Up @@ -238,6 +239,7 @@ private ChutzpahTestSettingsFile(bool isDefaultSetings) : this()
/// <summary>
/// The path to the settings file
/// </summary>
[JsonIgnore]
public string SettingsFileDirectory { get; set; }

/// <summary>
Expand Down Expand Up @@ -387,6 +389,20 @@ public ChutzpahTestSettingsFile InheritFrom(ChutzpahTestSettingsFile parent)
{
this.Compile = parent.Compile;
}
else if(this.Compile != null && parent.Compile != null)
{
this.Compile.Arguments = this.Compile.Arguments ?? parent.Compile.Arguments;
this.Compile.Executable = this.Compile.Executable ?? parent.Compile.Executable;
this.Compile.Extensions = this.Compile.Extensions.Any() ? this.Compile.Extensions : parent.Compile.Extensions;
this.Compile.ExtensionsWithNoOutput = this.Compile.ExtensionsWithNoOutput.Any() ? this.Compile.ExtensionsWithNoOutput : parent.Compile.ExtensionsWithNoOutput;
this.Compile.Mode = this.Compile.Mode ?? parent.Compile.Mode;
this.Compile.IgnoreMissingFiles = this.Compile.IgnoreMissingFiles ?? parent.Compile.IgnoreMissingFiles;
this.Compile.UseSourceMaps = this.Compile.UseSourceMaps ?? parent.Compile.UseSourceMaps;
this.Compile.SkipIfUnchanged = this.Compile.SkipIfUnchanged ?? parent.Compile.SkipIfUnchanged;
this.Compile.WorkingDirectory = this.Compile.WorkingDirectory ?? parent.Compile.WorkingDirectory;
this.Compile.Timeout = this.Compile.Timeout ?? parent.Compile.Timeout;
this.Compile.Paths = this.Compile.Paths.Concat(parent.Compile.Paths).ToList();
}


this.AMDBaseUrl = this.AMDBaseUrl ?? parent.AMDBaseUrl;
Expand Down
2 changes: 1 addition & 1 deletion Chutzpah/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyVersion("4.2.0.0")]
2 changes: 1 addition & 1 deletion ConsoleRunner/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyVersion("4.2.0.0")]
6 changes: 3 additions & 3 deletions Facts.Integration/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyFileVersion("4.1.0.0")]
// [assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyFileVersion("4.2.0.0")]
2 changes: 2 additions & 0 deletions Facts/Library/BatchCompilerServiceFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public TestContext BuildContext()
SettingsFileDirectory = @"C:\src",
Compile = new BatchCompileConfiguration
{
Mode = BatchCompileMode.Executable,
Executable = "compile.bat",
SkipIfUnchanged = true,
WorkingDirectory = @"C:\src",
Paths = new List<CompilePathMap>
Expand Down
6 changes: 3 additions & 3 deletions Facts/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyFileVersion("4.1.0.0")]
// [assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyFileVersion("4.2.0.0")]
6 changes: 3 additions & 3 deletions PerfTester/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyFileVersion("4.1.0.0")]
// [assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyFileVersion("4.2.0.0")]
6 changes: 3 additions & 3 deletions VS.Common/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyFileVersion("4.1.0.0")]
// [assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyFileVersion("4.2.0.0")]
6 changes: 3 additions & 3 deletions VS2012.TestAdapter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyFileVersion("4.1.0.0")]
// [assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyFileVersion("4.2.0.0")]
4 changes: 2 additions & 2 deletions VS2012/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyFileVersion("4.1.0.0")]
[assembly: AssemblyVersion("4.2.0.0")]
[assembly: AssemblyFileVersion("4.2.0.0")]

[assembly: InternalsVisibleTo("VS2012_IntegrationTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5d0d0037c1860700951dacd66f284af268c594cd703483d37e8eb3182e5d5dec2201673145ef8d2145a82a3156e5d22f675634b1bc328114f1431129e62e86517e323eb6b3f6ea6e813fba1f50bfddfecafa2d8ba5900c021a7e1b6b14d3f4f8d6b65173e38a9ce2143324d7e24deaf5a0aee6f00499a57ad2b2dc51fde9dbd")]
[assembly: InternalsVisibleTo("VS2012_UnitTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5d0d0037c1860700951dacd66f284af268c594cd703483d37e8eb3182e5d5dec2201673145ef8d2145a82a3156e5d22f675634b1bc328114f1431129e62e86517e323eb6b3f6ea6e813fba1f50bfddfecafa2d8ba5900c021a7e1b6b14d3f4f8d6b65173e38a9ce2143324d7e24deaf5a0aee6f00499a57ad2b2dc51fde9dbd")]
2 changes: 1 addition & 1 deletion VS2012/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="VS11.Plugin.Chutzpah.67f38ef0-909a-40b5-b183-9477ad8c266a" Version="4.1.0" Language="en-US" Publisher="Matthew Manela" />
<Identity Id="VS11.Plugin.Chutzpah.67f38ef0-909a-40b5-b183-9477ad8c266a" Version="4.2.0" Language="en-US" Publisher="Matthew Manela" />
<DisplayName>Chutzpah Test Adapter for the Test Explorer</DisplayName>
<Description xml:space="preserve">Chutzpah adapter for the Visual Studio Unit Test Explorer. Chutzpah is an open source JavaScript test runner which enables you to run JavaScript unit tests from the command line and from inside of Visual Studio.</Description>
<MoreInfo>https://github.com/mmanela/chutzpah</MoreInfo>
Expand Down
2 changes: 1 addition & 1 deletion VisualStudioContextMenu/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("4.1.0.0")]
[assembly: AssemblyVersion("4.2.0.0")]



2 changes: 1 addition & 1 deletion VisualStudioContextMenu/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="0a3da9d8-a5b6-4fb9-b423-ef87ff203628" Version="4.1.0" Language="en-US" Publisher="Matthew Manela" />
<Identity Id="0a3da9d8-a5b6-4fb9-b423-ef87ff203628" Version="4.2.0" Language="en-US" Publisher="Matthew Manela" />
<DisplayName>Chutzpah Test Runner Context Menu Extension</DisplayName>
<Description>Chutzpah is an open source JavaScript test runner which helps you integrate JavaScript unit testing into your website. It enables you to run JavaScript unit tests from the command line and from inside of Visual Studio.</Description>
<License>EULA.rtf</License>
Expand Down

0 comments on commit d483d2a

Please sign in to comment.