Skip to content

Commit

Permalink
Merge pull request #77 from cake-contrib/feature/0.14.0
Browse files Browse the repository at this point in the history
Feature/0.14.0
  • Loading branch information
pascalberger authored Jun 25, 2018
2 parents 3ba5c4b + 8345cda commit 7ceacf0
Show file tree
Hide file tree
Showing 23 changed files with 908 additions and 25 deletions.
3 changes: 0 additions & 3 deletions nuspec/nuget/Cake.Npm.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
<releaseNotes>https://github.com/cake-contrib/Cake.Npm/releases/tag/0.13.0</releaseNotes>
</metadata>
<files>
<file src="net46\Cake.Npm.dll" target="lib\net46" />
<file src="net46\Cake.Npm.pdb" target="lib\net46" />
<file src="net46\Cake.Npm.xml" target="lib\net46" />
<file src="netstandard2.0\Cake.Npm.dll" target="lib\netstandard2.0" />
<file src="netstandard2.0\Cake.Npm.pdb" target="lib\netstandard2.0" />
<file src="netstandard2.0\Cake.Npm.xml" target="lib\netstandard2.0" />
Expand Down
9 changes: 4 additions & 5 deletions src/Cake.Npm.Tests/Cake.Npm.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net46;netcoreapp2.0</TargetFrameworks>
<NetStandardImplicitPackageVersion Condition=" '$(TargetFramework)' == 'netstandard2.0' ">2.0</NetStandardImplicitPackageVersion>
<TargetFramework>netcoreapp2.0</TargetFramework>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
Expand All @@ -11,9 +10,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.26.0" />
<PackageReference Include="Cake.Testing" Version="0.26.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Cake.Testing" Version="0.28.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Shouldly" Version="3.0.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
Expand Down
16 changes: 16 additions & 0 deletions src/Cake.Npm.Tests/Ci/NpmCiToolTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Cake.Core.Diagnostics;
using Cake.Npm.Ci;
using Xunit;

namespace Cake.Npm.Tests.Ci
Expand Down Expand Up @@ -90,6 +91,21 @@ public void Should_Use_Cake_LogLevel_If_LogLevel_Is_Set_To_Default(
// Then
Assert.Equal(expected, result.Args);
}

[Fact]
public void Should_Include_Production_Flag()
{
// Given
var fixture = new NpmCiToolFixture();
fixture.Settings.ForProduction();

// When
var result = fixture.Run();

// Then
Assert.Equal("ci --production", result.Args);
}

}
}
}
17 changes: 17 additions & 0 deletions src/Cake.Npm.Tests/Set/NpmSetToolFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Cake.Npm.Set;

namespace Cake.Npm.Tests.Set
{
internal sealed class NpmSetToolFixture : NpmFixture<NpmSetSettings>
{
public NpmSetToolFixture()
{
}

protected override void RunTool()
{
var tool = new NpmSetTool(FileSystem, Environment, ProcessRunner, Tools, Log);
tool.Set(Settings);
}
}
}
73 changes: 73 additions & 0 deletions src/Cake.Npm.Tests/Set/NpmSetToolTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Cake.Npm.Set;
using Shouldly;
using Xunit;

namespace Cake.Npm.Tests.Set
{
public class NpmSetToolTests
{
public sealed class TheSetMethod
{
[Fact]
public void Should_Redirect_Standard_Error()
{
var fixture = new NpmSetToolFixture();
fixture.Settings.RedirectStandardError = true;
fixture.Settings.Key = "progress";
fixture.Settings.Value = "false";
var result = fixture.Run();

Assert.True(result.Process.RedirectStandardError);
}

[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
var fixture = new NpmSetToolFixture();
fixture.Settings = null;

// When
var result = Record.Exception(() => fixture.Run());

// Then
result.IsArgumentNullException("settings");
}

[Fact]
public void Should_Add_Mandatory_Arguments()
{
// Given
var fixture = new NpmSetToolFixture();
fixture.Settings.Key = "progress";
fixture.Settings.Value = "false";

// When
var result = fixture.Run();

// Then
result.Args.ShouldStartWith("set");
}

[Theory]
[InlineData("progress", "false", false, "\"progress\"=\"false\"")]
[InlineData("progress", "false", true, "\"progress\"=\"false\" -g")]
[InlineData("progress state", "hello world", true, "\"progress state\"=\"hello world\" -g")]
public void Should_Create_Set_Command_Arguments(string key, string value, bool global, string expected)
{
// Given
var fixture = new NpmSetToolFixture();
fixture.Settings.Key = key;
fixture.Settings.Value = value;
fixture.Settings.Global = global;

// When
var result = fixture.Run();

// Then
result.Args.ShouldEndWith(expected);
}

}
}
}
17 changes: 17 additions & 0 deletions src/Cake.Npm.Tests/Update/NpmUpdateToolFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Cake.Npm.Update;

namespace Cake.Npm.Tests.Update
{
internal sealed class NpmUpdateToolFixture : NpmFixture<NpmUpdateSettings>
{
public NpmUpdateToolFixture()
{
}

protected override void RunTool()
{
var tool = new NpmUpdateTool(FileSystem, Environment, ProcessRunner, Tools, Log);
tool.Update(Settings);
}
}
}
64 changes: 64 additions & 0 deletions src/Cake.Npm.Tests/Update/NpmUpdateToolTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Cake.Npm.Update;
using Xunit;

namespace Cake.Npm.Tests.Update
{
public class NpmUpdateToolTests
{
public sealed class TheUpdateMethod
{
[Fact]
public void Should_Redirect_Standard_Error()
{
var fixture = new NpmUpdateToolFixture();
fixture.Settings.RedirectStandardError = true;

var result = fixture.Run();

Assert.True(result.Process.RedirectStandardError);
}

[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
var fixture = new NpmUpdateToolFixture();
fixture.Settings = null;

// When
var result = Record.Exception(() => fixture.Run());

// Then
result.IsArgumentNullException("settings");
}

[Fact]
public void Should_Add_Mandatory_Arguments()
{
// Given
var fixture = new NpmUpdateToolFixture();

// When
var result = fixture.Run();

// Then
Assert.Equal("update", result.Args);
}

[Fact]
public void Should_Include_Global_Flag()
{
// Given
var fixture = new NpmUpdateToolFixture();
fixture.Settings.UpdateGlobalPackages();

// When
var result = fixture.Run();

// Then
Assert.Equal("update -g", result.Args);
}

}
}
}
20 changes: 20 additions & 0 deletions src/Cake.Npm.Tests/Version/NpmVersionToolFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Text;
using Cake.Npm.Version;

namespace Cake.Npm.Tests.Version
{
internal sealed class NpmVersionToolFixture : NpmFixture<NpmVersionSettings>
{
public NpmVersionToolFixture()
{
}

protected override void RunTool()
{
var tool = new NpmVersionTool(FileSystem, Environment, ProcessRunner, Tools, Log);
Version = tool.Version(Settings);
}

public string Version { get; private set; }
}
}
102 changes: 102 additions & 0 deletions src/Cake.Npm.Tests/Version/NpmVersionToolTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using Cake.Core;
using Shouldly;
using Xunit;

namespace Cake.Npm.Tests.Version
{
public class NpmVersionToolTests
{
public sealed class TheVersionMethod
{
[Fact]
public void Should_Throw_If_Settings_Are_Null()
{
// Given
var fixture = new NpmVersionToolFixture();
fixture.Settings = null;

// When
var result = Record.Exception(() => fixture.Run());

// Then
result.IsArgumentNullException("settings");
}

[Fact]
public void Should_Add_Mandatory_Arguments()
{
// Given
var fixture = new NpmVersionToolFixture();

// When
var result = fixture.Run();

// Then
Assert.Equal("version", result.Args);
}

[Fact]
public void Should_Determine_Version_From_StandardOutput()
{
string[] versionInfo = new[]
{
"{",
" npm: '5.8.0',",
" ares: '1.10.1-DEV',",
" cldr: '32.0',",
" http_parser: '2.8.0',",
" icu: '60.1',",
" modules: '57',",
" nghttp2: '1.25.0',",
" node: '8.11.1',",
" openssl: '1.0.2o',",
" tz: '2017c',",
" unicode: '10.0',",
" uv: '1.19.1',",
" v8: '6.2.414.50',",
" zlib: '1.2.11'",
"}",
"",
"",
"╭─────────────────────────────────────╮",
"│ │",
"│ Update available 5.6.0 → 6.1.0 │",
"│ Run npm i -g npm to update │",
"│ │",
"╰─────────────────────────────────────╯"
};

// Given
var fixture = new NpmVersionToolFixture();
fixture.ProcessRunner.Process.SetStandardOutput(versionInfo);

// When
var result = fixture.Run();

// Then
fixture.Version.ShouldBe("5.8.0");
}

[Theory]
[InlineData("{npm: '1.0.0'}", "1.0.0")]
[InlineData("{ npm: '1.0.0',\r\n{stuff: '0.0.1' }", "1.0.0")]
[InlineData("", "")]
[InlineData(null, "")]
[InlineData("not valid", "")]
public void Should_Determine_Version_From_StandardOutput_Scenarios(string standardOutput, string expectedVersion)
{
string[] output = standardOutput.SplitLines();

// Given
var fixture = new NpmVersionToolFixture();
fixture.ProcessRunner.Process.SetStandardOutput(output);

// When
var result = fixture.Run();

// Then
fixture.Version.ShouldBe(expectedVersion);
}
}
}
}
Loading

0 comments on commit 7ceacf0

Please sign in to comment.