Skip to content

Commit 13f47b6

Browse files
authored
Remove Snapshooter and ChilliCream.Testing.Utilities (#9794)
1 parent ea36a50 commit 13f47b6

26 files changed

Lines changed: 125 additions & 64 deletions

src/Directory.Packages.props

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
<PackageVersion Include="BenchmarkDotNet.Diagnostics.dotMemory" Version="0.15.8" />
1515
<PackageVersion Include="ChilliCream.ModelContextProtocol.AspNetCore" Version="1.3.0" />
1616
<PackageVersion Include="ChilliCream.Nitro.App" Version="$(NitroVersion)" />
17-
<PackageVersion Include="ChilliCream.Testing.Utilities" Version="0.2.0" />
1817
<PackageVersion Include="coverlet.collector" Version="10.0.0" />
1918
<PackageVersion Include="DiffPlex" Version="1.9.0" />
2019
<PackageVersion Include="Duende.IdentityModel" Version="7.1.0" />
@@ -54,7 +53,6 @@
5453
<PackageVersion Include="ProjNET" Version="2.0.0" />
5554
<PackageVersion Include="RabbitMQ.Client" Version="7.0.0" />
5655
<PackageVersion Include="RavenDB.Client" Version="7.0.0" />
57-
<PackageVersion Include="Snapshooter.Xunit" Version="0.5.4" />
5856
<PackageVersion Include="Spectre.Console.Json" Version="0.55.2" />
5957
<PackageVersion Include="Spectre.Console" Version="0.55.2" />
6058
<PackageVersion Include="Spectre.Console.Testing" Version="0.55.2" />

src/StrawberryShake/Client/test/Core.Tests/Integration/IntegrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Text.Json;
44
using System.Threading;
55
using System.Threading.Tasks;
6-
using ChilliCream.Testing;
6+
using CookieCrumble;
77
using StrawberryShake.Integration.Mappers;
88
using StrawberryShake.Serialization;
99

src/StrawberryShake/Client/test/Core.Tests/Integration/Mappers/DroidHeroMapper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.Collections.Generic;
3-
using ChilliCream.Testing;
43

54
namespace StrawberryShake.Integration.Mappers
65
{

src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/EntityGeneratorTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using ChilliCream.Testing;
21
using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper;
32

43
namespace StrawberryShake.CodeGeneration.CSharp;

src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/ErrorGeneratorTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using ChilliCream.Testing;
21
using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper;
32

43
namespace StrawberryShake.CodeGeneration.CSharp;

src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
using System.Runtime.CompilerServices;
33
using System.Text;
44
using Microsoft.CodeAnalysis;
5-
using ChilliCream.Testing;
65
using HotChocolate;
76
using HotChocolate.Language;
8-
using Snapshooter;
9-
using Snapshooter.Xunit;
107
using StrawberryShake.CodeGeneration.Analyzers;
118
using StrawberryShake.CodeGeneration.Analyzers.Models;
129
using StrawberryShake.CodeGeneration.Utilities;
13-
using Snapshot = Snapshooter.Xunit.Snapshot;
1410
using RequestStrategyGen = StrawberryShake.Tools.Configuration.RequestStrategy;
1511
using static StrawberryShake.CodeGeneration.CSharp.CSharpGenerator;
1612

@@ -140,11 +136,7 @@ public static void AssertResult(
140136

141137
if (settings.SnapshotFile is not null)
142138
{
143-
documents.ToString()
144-
.MatchSnapshot(
145-
new SnapshotFullName(
146-
settings.SnapshotFile,
147-
Snapshot.FullName().FolderPath));
139+
MatchSnapshotAtPath(documents.ToString(), settings.SnapshotFile);
148140
}
149141
else
150142
{
@@ -200,12 +192,17 @@ public static AssertSettings CreateIntegrationTest(
200192
TransportProfile[]? profiles = null,
201193
AccessModifier accessModifier = AccessModifier.Public,
202194
bool noStore = false,
203-
[CallerMemberName] string? testName = null)
195+
[CallerMemberName] string? testName = null,
196+
[CallerFilePath] string? callerFilePath = null)
204197
{
205-
var snapshotFullName = Snapshot.FullName();
206-
var testFile = System.IO.Path.Combine(
207-
snapshotFullName.FolderPath,
208-
testName + "Test.cs");
198+
ArgumentException.ThrowIfNullOrEmpty(testName);
199+
ArgumentException.ThrowIfNullOrEmpty(callerFilePath);
200+
201+
var folder = System.IO.Path.GetDirectoryName(callerFilePath)
202+
?? throw new ArgumentException(
203+
$"Could not determine directory from caller file path '{callerFilePath}'.",
204+
nameof(callerFilePath));
205+
var testFile = System.IO.Path.Combine(folder, testName + "Test.cs");
209206
var ns = "StrawberryShake.CodeGeneration.CSharp.Integration." + testName;
210207

211208
if (!File.Exists(testFile))
@@ -219,13 +216,11 @@ public static AssertSettings CreateIntegrationTest(
219216

220217
return new AssertSettings
221218
{
222-
ClientName = testName! + "Client",
219+
ClientName = testName + "Client",
223220
Namespace = ns,
224221
AccessModifier = accessModifier,
225222
StrictValidation = true,
226-
SnapshotFile = System.IO.Path.Combine(
227-
snapshotFullName.FolderPath,
228-
testName + "Test.Client.cs"),
223+
SnapshotFile = System.IO.Path.Combine(folder, testName + "Test.Client.cs"),
229224
RequestStrategy = requestStrategy,
230225
NoStore = noStore,
231226
Profiles = (profiles ??
@@ -235,6 +230,46 @@ public static AssertSettings CreateIntegrationTest(
235230
};
236231
}
237232

233+
private static void MatchSnapshotAtPath(string content, string snapshotFile)
234+
{
235+
content = content.Replace("\r\n", "\n");
236+
237+
if (!File.Exists(snapshotFile))
238+
{
239+
CheckStrictMode();
240+
File.WriteAllText(snapshotFile, content);
241+
return;
242+
}
243+
244+
var existing = File.ReadAllText(snapshotFile).Replace("\r\n", "\n");
245+
if (string.Equals(existing, content, StringComparison.Ordinal))
246+
{
247+
return;
248+
}
249+
250+
var folder = System.IO.Path.GetDirectoryName(snapshotFile)!;
251+
var mismatchDir = System.IO.Path.Combine(folder, "__snapshots__", "__mismatch__");
252+
Directory.CreateDirectory(mismatchDir);
253+
var mismatchFile = System.IO.Path.Combine(mismatchDir, System.IO.Path.GetFileName(snapshotFile));
254+
File.WriteAllText(mismatchFile, content);
255+
256+
Assert.Fail($"Snapshot mismatch. Mismatch file written to {mismatchFile}");
257+
}
258+
259+
private static void CheckStrictMode()
260+
{
261+
var value = Environment.GetEnvironmentVariable("COOKIE_CRUMBLE_STRICT_MODE");
262+
263+
if (string.Equals(value, "on", StringComparison.Ordinal)
264+
|| (bool.TryParse(value, out var b) && b))
265+
{
266+
Assert.Fail(
267+
"Strict mode is enabled and no snapshot has been found "
268+
+ "for the current test. Create a new snapshot locally and "
269+
+ "rerun your tests.");
270+
}
271+
}
272+
238273
private static ClientModel CreateClientModel(
239274
string[] sourceText,
240275
bool strictValidation,

src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/InputGeneratorTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using ChilliCream.Testing;
21
using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper;
32

43
namespace StrawberryShake.CodeGeneration.CSharp;

src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/AnyScalarDefaultSerializationTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using HotChocolate.AspNetCore.Tests.Utilities;
33
using HotChocolate.Types;
44
using Microsoft.Extensions.DependencyInjection;
5-
using Snapshooter.Xunit;
65
using StrawberryShake.Transport.WebSockets;
76

87
namespace StrawberryShake.CodeGeneration.CSharp.Integration.AnyScalarDefaultSerialization;

src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/EntityIdOrDataTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using HotChocolate.AspNetCore.Tests.Utilities;
22
using Microsoft.Extensions.DependencyInjection;
33
using HotChocolate.Types;
4-
using Snapshooter.Xunit;
54

65
namespace StrawberryShake.CodeGeneration.CSharp.Integration.EntityIdOrData;
76

src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsIntrospectionTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using HotChocolate.AspNetCore.Tests.Utilities;
22
using Microsoft.Extensions.DependencyInjection;
3-
using Snapshooter.Xunit;
43
using StrawberryShake.Transport.WebSockets;
54

65
namespace StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsIntrospection;

0 commit comments

Comments
 (0)