From b22920d14856835020dff5efc8d511e7bae9d652 Mon Sep 17 00:00:00 2001 From: Glen Date: Thu, 28 May 2026 17:40:44 +0200 Subject: [PATCH 1/3] Remove Snapshooter and ChilliCream.Testing.Utilities --- src/Directory.Packages.props | 2 - .../Integration/IntegrationTests.cs | 2 +- .../Integration/Mappers/DroidHeroMapper.cs | 2 +- .../EntityGeneratorTests.cs | 1 - .../ErrorGeneratorTests.cs | 1 - .../GeneratorTestHelper.cs | 48 ++++++++++++------- .../InputGeneratorTests.cs | 1 - .../AnyScalarDefaultSerializationTest.cs | 1 - .../Integration/EntityIdOrDataTest.cs | 1 - .../Integration/StarWarsIntrospectionTest.cs | 1 - .../StarWarsTypeNameOnInterfacesTest.cs | 1 - .../StarWarsTypeNameOnUnionsTest.cs | 1 - .../Integration/StarWarsUnionListTest.cs | 1 - .../Integration/TestGeneration.cs | 1 - ...st.Execute_StarWarsIntrospection_Test.snap | 4 +- .../NoStoreStarWarsGeneratorTests.cs | 1 - .../OperationGeneratorTests.cs | 1 - .../ScalarGeneratorTests.cs | 1 - .../SchemaGeneratorTests.cs | 1 - .../StarWarsGeneratorTests.cs | 1 - .../GeneratorTestHelper.cs | 48 ++++++++++++------- .../Mappers/TestDataHelper.cs | 2 +- .../Utilities/OperationDocumentHelperTests.cs | 3 +- .../Utilities/QueryDocumentRewriterTests.cs | 1 - .../Utilities/SchemaHelperTests.cs | 1 - .../CodeGeneration/test/Directory.Build.props | 16 ++++++- 26 files changed, 82 insertions(+), 62 deletions(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 170605a97f9..97799bb54e6 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -14,7 +14,6 @@ - @@ -54,7 +53,6 @@ - diff --git a/src/StrawberryShake/Client/test/Core.Tests/Integration/IntegrationTests.cs b/src/StrawberryShake/Client/test/Core.Tests/Integration/IntegrationTests.cs index cdd8247b93d..899f9c10e31 100644 --- a/src/StrawberryShake/Client/test/Core.Tests/Integration/IntegrationTests.cs +++ b/src/StrawberryShake/Client/test/Core.Tests/Integration/IntegrationTests.cs @@ -3,7 +3,7 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using ChilliCream.Testing; +using CookieCrumble; using StrawberryShake.Integration.Mappers; using StrawberryShake.Serialization; diff --git a/src/StrawberryShake/Client/test/Core.Tests/Integration/Mappers/DroidHeroMapper.cs b/src/StrawberryShake/Client/test/Core.Tests/Integration/Mappers/DroidHeroMapper.cs index ab783ca33b7..1c33945fe2f 100644 --- a/src/StrawberryShake/Client/test/Core.Tests/Integration/Mappers/DroidHeroMapper.cs +++ b/src/StrawberryShake/Client/test/Core.Tests/Integration/Mappers/DroidHeroMapper.cs @@ -1,6 +1,6 @@ using System; using System.Collections.Generic; -using ChilliCream.Testing; +using CookieCrumble; namespace StrawberryShake.Integration.Mappers { diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/EntityGeneratorTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/EntityGeneratorTests.cs index ebe07373ebe..add4e822cc4 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/EntityGeneratorTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/EntityGeneratorTests.cs @@ -1,4 +1,3 @@ -using ChilliCream.Testing; using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper; namespace StrawberryShake.CodeGeneration.CSharp; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/ErrorGeneratorTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/ErrorGeneratorTests.cs index 1af2a362e0d..ee2a16412e5 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/ErrorGeneratorTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/ErrorGeneratorTests.cs @@ -1,4 +1,3 @@ -using ChilliCream.Testing; using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper; namespace StrawberryShake.CodeGeneration.CSharp; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs index 9ce46417165..eff7b11bd30 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs @@ -2,15 +2,11 @@ using System.Runtime.CompilerServices; using System.Text; using Microsoft.CodeAnalysis; -using ChilliCream.Testing; using HotChocolate; using HotChocolate.Language; -using Snapshooter; -using Snapshooter.Xunit; using StrawberryShake.CodeGeneration.Analyzers; using StrawberryShake.CodeGeneration.Analyzers.Models; using StrawberryShake.CodeGeneration.Utilities; -using Snapshot = Snapshooter.Xunit.Snapshot; using RequestStrategyGen = StrawberryShake.Tools.Configuration.RequestStrategy; using static StrawberryShake.CodeGeneration.CSharp.CSharpGenerator; @@ -140,11 +136,7 @@ public static void AssertResult( if (settings.SnapshotFile is not null) { - documents.ToString() - .MatchSnapshot( - new SnapshotFullName( - settings.SnapshotFile, - Snapshot.FullName().FolderPath)); + MatchSnapshotAtPath(documents.ToString(), settings.SnapshotFile); } else { @@ -200,12 +192,11 @@ public static AssertSettings CreateIntegrationTest( TransportProfile[]? profiles = null, AccessModifier accessModifier = AccessModifier.Public, bool noStore = false, - [CallerMemberName] string? testName = null) + [CallerMemberName] string? testName = null, + [CallerFilePath] string? callerFilePath = null) { - var snapshotFullName = Snapshot.FullName(); - var testFile = System.IO.Path.Combine( - snapshotFullName.FolderPath, - testName + "Test.cs"); + var folder = System.IO.Path.GetDirectoryName(callerFilePath)!; + var testFile = System.IO.Path.Combine(folder, testName + "Test.cs"); var ns = "StrawberryShake.CodeGeneration.CSharp.Integration." + testName; if (!File.Exists(testFile)) @@ -223,9 +214,7 @@ public static AssertSettings CreateIntegrationTest( Namespace = ns, AccessModifier = accessModifier, StrictValidation = true, - SnapshotFile = System.IO.Path.Combine( - snapshotFullName.FolderPath, - testName + "Test.Client.cs"), + SnapshotFile = System.IO.Path.Combine(folder, testName + "Test.Client.cs"), RequestStrategy = requestStrategy, NoStore = noStore, Profiles = (profiles ?? @@ -235,6 +224,31 @@ public static AssertSettings CreateIntegrationTest( }; } + private static void MatchSnapshotAtPath(string content, string snapshotFile) + { + content = content.Replace("\r\n", "\n"); + + if (!File.Exists(snapshotFile)) + { + File.WriteAllText(snapshotFile, content); + return; + } + + var existing = File.ReadAllText(snapshotFile).Replace("\r\n", "\n"); + if (string.Equals(existing, content, StringComparison.Ordinal)) + { + return; + } + + var folder = System.IO.Path.GetDirectoryName(snapshotFile)!; + var mismatchDir = System.IO.Path.Combine(folder, "__snapshots__", "__mismatch__"); + Directory.CreateDirectory(mismatchDir); + var mismatchFile = System.IO.Path.Combine(mismatchDir, System.IO.Path.GetFileName(snapshotFile)); + File.WriteAllText(mismatchFile, content); + + Assert.Fail($"Snapshot mismatch. Mismatch file written to {mismatchFile}"); + } + private static ClientModel CreateClientModel( string[] sourceText, bool strictValidation, diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/InputGeneratorTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/InputGeneratorTests.cs index 8da411722c0..3fee3ce1d60 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/InputGeneratorTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/InputGeneratorTests.cs @@ -1,4 +1,3 @@ -using ChilliCream.Testing; using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper; namespace StrawberryShake.CodeGeneration.CSharp; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/AnyScalarDefaultSerializationTest.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/AnyScalarDefaultSerializationTest.cs index 69feefb6510..f81b11d920e 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/AnyScalarDefaultSerializationTest.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/AnyScalarDefaultSerializationTest.cs @@ -2,7 +2,6 @@ using HotChocolate.AspNetCore.Tests.Utilities; using HotChocolate.Types; using Microsoft.Extensions.DependencyInjection; -using Snapshooter.Xunit; using StrawberryShake.Transport.WebSockets; namespace StrawberryShake.CodeGeneration.CSharp.Integration.AnyScalarDefaultSerialization; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/EntityIdOrDataTest.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/EntityIdOrDataTest.cs index e67578c7768..2c9de883612 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/EntityIdOrDataTest.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/EntityIdOrDataTest.cs @@ -1,7 +1,6 @@ using HotChocolate.AspNetCore.Tests.Utilities; using Microsoft.Extensions.DependencyInjection; using HotChocolate.Types; -using Snapshooter.Xunit; namespace StrawberryShake.CodeGeneration.CSharp.Integration.EntityIdOrData; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsIntrospectionTest.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsIntrospectionTest.cs index 60674bf7cda..8a70f4de852 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsIntrospectionTest.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsIntrospectionTest.cs @@ -1,6 +1,5 @@ using HotChocolate.AspNetCore.Tests.Utilities; using Microsoft.Extensions.DependencyInjection; -using Snapshooter.Xunit; using StrawberryShake.Transport.WebSockets; namespace StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsIntrospection; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsTypeNameOnInterfacesTest.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsTypeNameOnInterfacesTest.cs index 2b421d1d4b8..59c2b4f5bd5 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsTypeNameOnInterfacesTest.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsTypeNameOnInterfacesTest.cs @@ -1,6 +1,5 @@ using HotChocolate.AspNetCore.Tests.Utilities; using Microsoft.Extensions.DependencyInjection; -using Snapshooter.Xunit; using StrawberryShake.Transport.WebSockets; namespace StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsTypeNameOnInterfaces; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsTypeNameOnUnionsTest.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsTypeNameOnUnionsTest.cs index ecfc8a1dcfc..2a0db3b6aa3 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsTypeNameOnUnionsTest.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsTypeNameOnUnionsTest.cs @@ -1,6 +1,5 @@ using HotChocolate.AspNetCore.Tests.Utilities; using Microsoft.Extensions.DependencyInjection; -using Snapshooter.Xunit; using StrawberryShake.Transport.WebSockets; namespace StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsTypeNameOnUnions; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsUnionListTest.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsUnionListTest.cs index 22fb7d9a449..c0ed1a1945d 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsUnionListTest.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/StarWarsUnionListTest.cs @@ -1,6 +1,5 @@ using HotChocolate.AspNetCore.Tests.Utilities; using Microsoft.Extensions.DependencyInjection; -using Snapshooter.Xunit; using StrawberryShake.Transport.WebSockets; namespace StrawberryShake.CodeGeneration.CSharp.Integration.StarWarsUnionList; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/TestGeneration.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/TestGeneration.cs index ed4f613148a..62544fe22cc 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/TestGeneration.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/TestGeneration.cs @@ -1,4 +1,3 @@ -using ChilliCream.Testing; using StrawberryShake.Tools.Configuration; using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/__snapshots__/StarWarsIntrospectionTest.Execute_StarWarsIntrospection_Test.snap b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/__snapshots__/StarWarsIntrospectionTest.Execute_StarWarsIntrospection_Test.snap index 5a902cdb1d5..b2d41708e6f 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/__snapshots__/StarWarsIntrospectionTest.Execute_StarWarsIntrospection_Test.snap +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/Integration/__snapshots__/StarWarsIntrospectionTest.Execute_StarWarsIntrospection_Test.snap @@ -1,4 +1,4 @@ -{ +{ "Data": { "__schema": { "QueryType": { @@ -7471,4 +7471,4 @@ "Errors": [], "Extensions": {}, "ContextData": {} -} \ No newline at end of file +} diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/NoStoreStarWarsGeneratorTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/NoStoreStarWarsGeneratorTests.cs index 2fab6dad93a..f90446b29d4 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/NoStoreStarWarsGeneratorTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/NoStoreStarWarsGeneratorTests.cs @@ -1,4 +1,3 @@ -using ChilliCream.Testing; using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper; namespace StrawberryShake.CodeGeneration.CSharp; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/OperationGeneratorTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/OperationGeneratorTests.cs index dd7c5d999b0..be29459cd53 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/OperationGeneratorTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/OperationGeneratorTests.cs @@ -1,4 +1,3 @@ -using ChilliCream.Testing; using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper; namespace StrawberryShake.CodeGeneration.CSharp; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/ScalarGeneratorTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/ScalarGeneratorTests.cs index 31c4e3d41e0..47db0dde6a5 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/ScalarGeneratorTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/ScalarGeneratorTests.cs @@ -1,4 +1,3 @@ -using ChilliCream.Testing; using Xunit.Sdk; using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/SchemaGeneratorTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/SchemaGeneratorTests.cs index 572f56f7e67..b5d0892970f 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/SchemaGeneratorTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/SchemaGeneratorTests.cs @@ -1,4 +1,3 @@ -using ChilliCream.Testing; using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper; namespace StrawberryShake.CodeGeneration.CSharp; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/StarWarsGeneratorTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/StarWarsGeneratorTests.cs index 5b682d0405c..c748a88d15e 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/StarWarsGeneratorTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/StarWarsGeneratorTests.cs @@ -1,4 +1,3 @@ -using ChilliCream.Testing; using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper; namespace StrawberryShake.CodeGeneration.CSharp; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs index 6adc40bdaa1..679f0a7e2aa 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs @@ -1,15 +1,11 @@ using System.Runtime.CompilerServices; using System.Text; using Microsoft.CodeAnalysis; -using ChilliCream.Testing; using HotChocolate; using HotChocolate.Language; -using Snapshooter; -using Snapshooter.Xunit; using StrawberryShake.CodeGeneration.Analyzers; using StrawberryShake.CodeGeneration.Analyzers.Models; using StrawberryShake.CodeGeneration.Utilities; -using Snapshot = Snapshooter.Xunit.Snapshot; using RequestStrategyGen = StrawberryShake.Tools.Configuration.RequestStrategy; using static StrawberryShake.CodeGeneration.CSharp.CSharpGenerator; @@ -138,11 +134,7 @@ public static void AssertResult( if (settings.SnapshotFile is not null) { - documents.ToString() - .MatchSnapshot( - new SnapshotFullName( - settings.SnapshotFile, - Snapshot.FullName().FolderPath)); + MatchSnapshotAtPath(documents.ToString(), settings.SnapshotFile); } else { @@ -197,12 +189,11 @@ public static AssertSettings CreateIntegrationTest( RequestStrategyGen requestStrategy = RequestStrategyGen.Default, TransportProfile[]? profiles = null, bool noStore = false, - [CallerMemberName] string? testName = null) + [CallerMemberName] string? testName = null, + [CallerFilePath] string? callerFilePath = null) { - var snapshotFullName = Snapshot.FullName(); - var testFile = System.IO.Path.Combine( - snapshotFullName.FolderPath, - testName + "Test.cs"); + var folder = System.IO.Path.GetDirectoryName(callerFilePath)!; + var testFile = System.IO.Path.Combine(folder, testName + "Test.cs"); var ns = "StrawberryShake.CodeGeneration.CSharp.Integration." + testName; if (!File.Exists(testFile)) @@ -219,9 +210,7 @@ public static AssertSettings CreateIntegrationTest( ClientName = testName! + "Client", Namespace = ns, StrictValidation = true, - SnapshotFile = System.IO.Path.Combine( - snapshotFullName.FolderPath, - testName + "Test.Client.cs"), + SnapshotFile = System.IO.Path.Combine(folder, testName + "Test.Client.cs"), RequestStrategy = requestStrategy, NoStore = noStore, Profiles = (profiles ?? @@ -231,6 +220,31 @@ public static AssertSettings CreateIntegrationTest( }; } + private static void MatchSnapshotAtPath(string content, string snapshotFile) + { + content = content.Replace("\r\n", "\n"); + + if (!File.Exists(snapshotFile)) + { + File.WriteAllText(snapshotFile, content); + return; + } + + var existing = File.ReadAllText(snapshotFile).Replace("\r\n", "\n"); + if (string.Equals(existing, content, StringComparison.Ordinal)) + { + return; + } + + var folder = System.IO.Path.GetDirectoryName(snapshotFile)!; + var mismatchDir = System.IO.Path.Combine(folder, "__snapshots__", "__mismatch__"); + Directory.CreateDirectory(mismatchDir); + var mismatchFile = System.IO.Path.Combine(mismatchDir, System.IO.Path.GetFileName(snapshotFile)); + File.WriteAllText(mismatchFile, content); + + Assert.Fail($"Snapshot mismatch. Mismatch file written to {mismatchFile}"); + } + private static ClientModel CreateClientModel( string[] sourceText, bool strictValidation, diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Mappers/TestDataHelper.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Mappers/TestDataHelper.cs index 35316ce7ee9..ca1db15b673 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Mappers/TestDataHelper.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Mappers/TestDataHelper.cs @@ -6,7 +6,7 @@ using StrawberryShake.CodeGeneration.Analyzers; using StrawberryShake.CodeGeneration.Analyzers.Models; using StrawberryShake.CodeGeneration.Utilities; -using static ChilliCream.Testing.FileResource; +using static CookieCrumble.FileResource; namespace StrawberryShake.CodeGeneration.Mappers; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/OperationDocumentHelperTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/OperationDocumentHelperTests.cs index ee4b30438db..c1be9873d81 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/OperationDocumentHelperTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/OperationDocumentHelperTests.cs @@ -1,6 +1,5 @@ using HotChocolate.Language; -using Snapshooter.Xunit; -using static ChilliCream.Testing.FileResource; +using static CookieCrumble.FileResource; using static HotChocolate.Language.Utf8GraphQLParser; using static StrawberryShake.CodeGeneration.Utilities.OperationDocumentHelper; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/QueryDocumentRewriterTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/QueryDocumentRewriterTests.cs index 40de5304962..486e695fcf3 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/QueryDocumentRewriterTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/QueryDocumentRewriterTests.cs @@ -3,7 +3,6 @@ using HotChocolate.Language.Utilities; using HotChocolate.StarWars; using Microsoft.Extensions.DependencyInjection; -using Snapshooter.Xunit; namespace StrawberryShake.CodeGeneration.Utilities; diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/SchemaHelperTests.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/SchemaHelperTests.cs index 9453173af84..3ff109307c2 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/SchemaHelperTests.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Tests/Utilities/SchemaHelperTests.cs @@ -1,4 +1,3 @@ -using ChilliCream.Testing; using HotChocolate.Language; using HotChocolate.Types; using StrawberryShake.CodeGeneration.Extensions; diff --git a/src/StrawberryShake/CodeGeneration/test/Directory.Build.props b/src/StrawberryShake/CodeGeneration/test/Directory.Build.props index 895e450bc18..a88f34ecaa6 100644 --- a/src/StrawberryShake/CodeGeneration/test/Directory.Build.props +++ b/src/StrawberryShake/CodeGeneration/test/Directory.Build.props @@ -7,11 +7,17 @@ + + - + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all @@ -19,7 +25,6 @@ - runtime; build; native; contentfiles; analyzers; buildtransitive @@ -27,4 +32,11 @@ + + + + + From eeedd1d49174d6b5bb4340a4b9a7c4240f464f4c Mon Sep 17 00:00:00 2001 From: Glen Date: Thu, 28 May 2026 18:17:10 +0200 Subject: [PATCH 2/3] Honor `COOKIE_CRUMBLE_STRICT_MODE` in MatchSnapshotAtPath --- .../Integration/Mappers/DroidHeroMapper.cs | 1 - .../GeneratorTestHelper.cs | 15 +++++++++++++++ .../GeneratorTestHelper.cs | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/StrawberryShake/Client/test/Core.Tests/Integration/Mappers/DroidHeroMapper.cs b/src/StrawberryShake/Client/test/Core.Tests/Integration/Mappers/DroidHeroMapper.cs index 1c33945fe2f..4c326bb94f5 100644 --- a/src/StrawberryShake/Client/test/Core.Tests/Integration/Mappers/DroidHeroMapper.cs +++ b/src/StrawberryShake/Client/test/Core.Tests/Integration/Mappers/DroidHeroMapper.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using CookieCrumble; namespace StrawberryShake.Integration.Mappers { diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs index eff7b11bd30..ac2a42c20e1 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs @@ -230,6 +230,7 @@ private static void MatchSnapshotAtPath(string content, string snapshotFile) if (!File.Exists(snapshotFile)) { + CheckStrictMode(); File.WriteAllText(snapshotFile, content); return; } @@ -249,6 +250,20 @@ private static void MatchSnapshotAtPath(string content, string snapshotFile) Assert.Fail($"Snapshot mismatch. Mismatch file written to {mismatchFile}"); } + private static void CheckStrictMode() + { + var value = Environment.GetEnvironmentVariable("COOKIE_CRUMBLE_STRICT_MODE"); + + if (string.Equals(value, "on", StringComparison.Ordinal) + || (bool.TryParse(value, out var b) && b)) + { + Assert.Fail( + "Strict mode is enabled and no snapshot has been found " + + "for the current test. Create a new snapshot locally and " + + "rerun your tests."); + } + } + private static ClientModel CreateClientModel( string[] sourceText, bool strictValidation, diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs index 679f0a7e2aa..d944f9a1c8b 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs @@ -226,6 +226,7 @@ private static void MatchSnapshotAtPath(string content, string snapshotFile) if (!File.Exists(snapshotFile)) { + CheckStrictMode(); File.WriteAllText(snapshotFile, content); return; } @@ -245,6 +246,20 @@ private static void MatchSnapshotAtPath(string content, string snapshotFile) Assert.Fail($"Snapshot mismatch. Mismatch file written to {mismatchFile}"); } + private static void CheckStrictMode() + { + var value = Environment.GetEnvironmentVariable("COOKIE_CRUMBLE_STRICT_MODE"); + + if (string.Equals(value, "on", StringComparison.Ordinal) + || (bool.TryParse(value, out var b) && b)) + { + Assert.Fail( + "Strict mode is enabled and no snapshot has been found " + + "for the current test. Create a new snapshot locally and " + + "rerun your tests."); + } + } + private static ClientModel CreateClientModel( string[] sourceText, bool strictValidation, From d13ff46844e30389fb9926d795a9b733520b8f73 Mon Sep 17 00:00:00 2001 From: Glen Date: Thu, 28 May 2026 18:34:21 +0200 Subject: [PATCH 3/3] Validate `testName` and `callerFilePath` in CreateIntegrationTest --- .../CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs | 10 ++++++++-- .../CodeGeneration.Razor.Tests/GeneratorTestHelper.cs | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs index ac2a42c20e1..8582a33dd75 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.CSharp.Tests/GeneratorTestHelper.cs @@ -195,7 +195,13 @@ public static AssertSettings CreateIntegrationTest( [CallerMemberName] string? testName = null, [CallerFilePath] string? callerFilePath = null) { - var folder = System.IO.Path.GetDirectoryName(callerFilePath)!; + ArgumentException.ThrowIfNullOrEmpty(testName); + ArgumentException.ThrowIfNullOrEmpty(callerFilePath); + + var folder = System.IO.Path.GetDirectoryName(callerFilePath) + ?? throw new ArgumentException( + $"Could not determine directory from caller file path '{callerFilePath}'.", + nameof(callerFilePath)); var testFile = System.IO.Path.Combine(folder, testName + "Test.cs"); var ns = "StrawberryShake.CodeGeneration.CSharp.Integration." + testName; @@ -210,7 +216,7 @@ public static AssertSettings CreateIntegrationTest( return new AssertSettings { - ClientName = testName! + "Client", + ClientName = testName + "Client", Namespace = ns, AccessModifier = accessModifier, StrictValidation = true, diff --git a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs index d944f9a1c8b..681b6e5b10b 100644 --- a/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs +++ b/src/StrawberryShake/CodeGeneration/test/CodeGeneration.Razor.Tests/GeneratorTestHelper.cs @@ -192,7 +192,13 @@ public static AssertSettings CreateIntegrationTest( [CallerMemberName] string? testName = null, [CallerFilePath] string? callerFilePath = null) { - var folder = System.IO.Path.GetDirectoryName(callerFilePath)!; + ArgumentException.ThrowIfNullOrEmpty(testName); + ArgumentException.ThrowIfNullOrEmpty(callerFilePath); + + var folder = System.IO.Path.GetDirectoryName(callerFilePath) + ?? throw new ArgumentException( + $"Could not determine directory from caller file path '{callerFilePath}'.", + nameof(callerFilePath)); var testFile = System.IO.Path.Combine(folder, testName + "Test.cs"); var ns = "StrawberryShake.CodeGeneration.CSharp.Integration." + testName; @@ -207,7 +213,7 @@ public static AssertSettings CreateIntegrationTest( return new AssertSettings { - ClientName = testName! + "Client", + ClientName = testName + "Client", Namespace = ns, StrictValidation = true, SnapshotFile = System.IO.Path.Combine(folder, testName + "Test.Client.cs"),