pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.68k stars 556 forks source link

Snapshot adds imported module's name that fails match with reference shapshot #819

Open kapitoshka438 opened 6 months ago

kapitoshka438 commented 6 months ago

Describe the bug Our project includes several application targets and test target for each of them for environments split purposes. The source code is common for all environments. We import application modules to their test modules through @testable import this way:

#if canImport(App_dev)
@testable import App_dev
#elseif canImport(App_test)
@testable import App_test
#elseif canImport(App_pre)
@testable import App_pre
#endif

So each test scheme imports a corresponding application target module.

However, generated snapshots put app target module name for their class names that make out snapshot tests fail. Is there a way to disable module names and avoid creating separate reference snapshots for each environment?

Error Message

test_mutate_whenGoToCatalog_withInitialState_shouldSucceed(): failed - Snapshot does not match reference.

ksDiff "/Users/EMiniakhmetov/ostin-ios-app/Ostin/Tests/Resources/Snapshots/Chat/ChatWebViewMutatorTests/ChatWebViewMutatorTests_test_mutate_whenGoToCatalog_withInitialState_shouldSucceed.1.txt" "/Users/EMiniakhmetov/Library/Developer/CoreSimulator/Devices/5797389E-3B79-4513-A77B-1DF77AF31459/data/Containers/Data/Application/EA522DB9-3AD6-47F2-962D-911EB705C061/tmp/ChatWebViewMutatorTests/ChatWebViewMutatorTests_test_mutate_whenGoToCatalog_withInitialState_shouldSucceed.1.txt"

@@ −1,1 +1,1 @@
−[ChatWebViewMutation.setRoutingTarget(Optional(ChatWebViewModuleState.ViewState.RoutingTarget.catalog)), ChatWebViewMutation.setRoutingTarget(nil)]
+[Ostin_test.ChatWebViewMutation.setRoutingTarget(Optional(Ostin_test.ChatWebViewModuleState.ViewState.RoutingTarget.catalog)), Ostin_test.ChatWebViewMutation.setRoutingTarget(nil)]

Environment