Browse Source

Fix snapshot tests in CI (#6156)

* Add snapshot tests job to PR's and master build.
* Add record option to snapshot tests job.
* Archive failing snapshot tests as artifacts.

Co-authored-by: wixmobile <mobile1@wix.com>
Co-authored-by: Guy Carmeli <guyca@users.noreply.github.com>
Yogev Ben David 4 years ago
parent
commit
1f887c87cd
No account linked to committer's email address
17 changed files with 165 additions and 18 deletions
  1. 3
    0
      playground/.gitignore
  2. 3
    3
      playground/ios/Podfile.lock
  3. BIN
      playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_opaque_background_push@2x.png
  4. BIN
      playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_tansparent_background_push@2x.png
  5. BIN
      playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_title_change_pop@2x.png
  6. BIN
      playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_title_change_push@2x.png
  7. BIN
      playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_title_font_pop@2x.png
  8. BIN
      playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_title_font_push@2x.png
  9. BIN
      playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_translucent_background_pop@2x.png
  10. BIN
      playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_translucent_background_push@2x.png
  11. BIN
      playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_translucent_background_root@2x.png
  12. BIN
      playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_visibility_push@2x.png
  13. 3
    2
      playground/ios/SnapshotTests/StackOptionsTest.m
  14. 2
    2
      playground/ios/playground.xcodeproj/project.pbxproj
  15. 109
    0
      playground/ios/playground.xcodeproj/xcshareddata/xcschemes/SnapshotRecordTests.xcscheme
  16. 5
    0
      playground/ios/playground.xcodeproj/xcshareddata/xcschemes/SnapshotTests.xcscheme
  17. 40
    11
      scripts/test-snapshot.js

+ 3
- 0
playground/.gitignore View File

@@ -209,3 +209,6 @@ buck-out/
209 209
 \.buckd/
210 210
 android/app/libs
211 211
 android/keystores/debug.keystore
212
+
213
+# Snapshot tests diffs
214
+ios/SnapshotTests/FailureDiffs/

+ 3
- 3
playground/ios/Podfile.lock View File

@@ -221,7 +221,7 @@ PODS:
221 221
     - ReactCommon/jscallinvoker (= 0.61.5)
222 222
   - ReactNativeKeyboardTrackingView (5.6.1):
223 223
     - React
224
-  - ReactNativeNavigation (6.3.1):
224
+  - ReactNativeNavigation (6.4.0):
225 225
     - React
226 226
     - React-RCTImage
227 227
     - React-RCTText
@@ -352,9 +352,9 @@ SPEC CHECKSUMS:
352 352
   React-RCTVibration: a49a1f42bf8f5acf1c3e297097517c6b3af377ad
353 353
   ReactCommon: 198c7c8d3591f975e5431bec1b0b3b581aa1c5dd
354 354
   ReactNativeKeyboardTrackingView: a240a6a0dba852bb107109a7ec7e98b884055977
355
-  ReactNativeNavigation: d9bb71088ef37aa6af58f3172f890a1ae08861d6
355
+  ReactNativeNavigation: 667586f6924fbd09512e2933fe70497db914b758
356 356
   Yoga: f2a7cd4280bfe2cca5a7aed98ba0eb3d1310f18b
357 357
 
358
-PODFILE CHECKSUM: 480983e790dd4e9f99b1673fbb65606d9fe8ce71
358
+PODFILE CHECKSUM: 51b8040756c3fb06cf4c6437b0a7c683703c2b03
359 359
 
360 360
 COCOAPODS: 1.9.1

BIN
playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_opaque_background_push@2x.png View File


BIN
playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_tansparent_background_push@2x.png View File


BIN
playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_title_change_pop@2x.png View File


BIN
playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_title_change_push@2x.png View File


BIN
playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_title_font_pop@2x.png View File


BIN
playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_title_font_push@2x.png View File


BIN
playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_translucent_background_pop@2x.png View File


BIN
playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_translucent_background_push@2x.png View File


BIN
playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_translucent_background_root@2x.png View File


BIN
playground/ios/SnapshotTests/ReferenceImages_64/StackOptionsTest/testStack_topBar_visibility_push@2x.png View File


+ 3
- 2
playground/ios/SnapshotTests/StackOptionsTest.m View File

@@ -16,8 +16,9 @@
16 16
 	_commandsHandler = [CommandsHandlerCreator createWithWindow:_window];
17 17
 	self.usesDrawViewHierarchyInRect = YES;
18 18
 	
19
-//	Uncomment next line to record new snapshots
20
-//	self.recordMode = YES;
19
+	if (NSProcessInfo.processInfo.environment[@"RECORD_SNAPSHOTS"]) {
20
+		self.recordMode = YES;
21
+	}
21 22
 }
22 23
 
23 24
 - (void)tearDown {

+ 2
- 2
playground/ios/playground.xcodeproj/project.pbxproj View File

@@ -1091,7 +1091,7 @@
1091 1091
 				DEBUG_INFORMATION_FORMAT = dwarf;
1092 1092
 				GCC_C_LANGUAGE_STANDARD = gnu11;
1093 1093
 				INFOPLIST_FILE = SnapshotTests/Info.plist;
1094
-				IPHONEOS_DEPLOYMENT_TARGET = 13.2;
1094
+				IPHONEOS_DEPLOYMENT_TARGET = 13.0;
1095 1095
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
1096 1096
 				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
1097 1097
 				MTL_FAST_MATH = YES;
@@ -1118,7 +1118,7 @@
1118 1118
 				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
1119 1119
 				GCC_C_LANGUAGE_STANDARD = gnu11;
1120 1120
 				INFOPLIST_FILE = SnapshotTests/Info.plist;
1121
-				IPHONEOS_DEPLOYMENT_TARGET = 13.2;
1121
+				IPHONEOS_DEPLOYMENT_TARGET = 13.0;
1122 1122
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
1123 1123
 				MTL_FAST_MATH = YES;
1124 1124
 				PRODUCT_BUNDLE_IDENTIFIER = rn.SnapshotTests;

+ 109
- 0
playground/ios/playground.xcodeproj/xcshareddata/xcschemes/SnapshotRecordTests.xcscheme View File

@@ -0,0 +1,109 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<Scheme
3
+   LastUpgradeVersion = "1120"
4
+   version = "1.3">
5
+   <BuildAction
6
+      parallelizeBuildables = "YES"
7
+      buildImplicitDependencies = "YES">
8
+   </BuildAction>
9
+   <TestAction
10
+      buildConfiguration = "Debug"
11
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
12
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13
+      shouldUseLaunchSchemeArgsEnv = "NO">
14
+      <MacroExpansion>
15
+         <BuildableReference
16
+            BuildableIdentifier = "primary"
17
+            BlueprintIdentifier = "507C80D92429111F00F765F7"
18
+            BuildableName = "SnapshotTests.xctest"
19
+            BlueprintName = "SnapshotTests"
20
+            ReferencedContainer = "container:playground.xcodeproj">
21
+         </BuildableReference>
22
+      </MacroExpansion>
23
+      <EnvironmentVariables>
24
+         <EnvironmentVariable
25
+            key = "FB_REFERENCE_IMAGE_DIR"
26
+            value = "$(SOURCE_ROOT)/SnapshotTests/ReferenceImages"
27
+            isEnabled = "YES">
28
+         </EnvironmentVariable>
29
+         <EnvironmentVariable
30
+            key = "RECORD_SNAPSHOTS"
31
+            value = "YES"
32
+            isEnabled = "YES">
33
+         </EnvironmentVariable>
34
+         <EnvironmentVariable
35
+            key = "IMAGE_DIFF_DIR"
36
+            value = "$(SOURCE_ROOT)/SnapshotTests/FailureDiffs"
37
+            isEnabled = "YES">
38
+         </EnvironmentVariable>
39
+         <EnvironmentVariable
40
+            key = "TEST_ENABLED"
41
+            value = "YES"
42
+            isEnabled = "YES">
43
+         </EnvironmentVariable>
44
+      </EnvironmentVariables>
45
+      <Testables>
46
+         <TestableReference
47
+            skipped = "NO">
48
+            <BuildableReference
49
+               BuildableIdentifier = "primary"
50
+               BlueprintIdentifier = "507C80D92429111F00F765F7"
51
+               BuildableName = "SnapshotTests.xctest"
52
+               BlueprintName = "SnapshotTests"
53
+               ReferencedContainer = "container:playground.xcodeproj">
54
+            </BuildableReference>
55
+         </TestableReference>
56
+      </Testables>
57
+   </TestAction>
58
+   <LaunchAction
59
+      buildConfiguration = "Debug"
60
+      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
61
+      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
62
+      launchStyle = "0"
63
+      useCustomWorkingDirectory = "NO"
64
+      ignoresPersistentStateOnLaunch = "NO"
65
+      debugDocumentVersioning = "YES"
66
+      debugServiceExtension = "internal"
67
+      allowLocationSimulation = "YES">
68
+      <BuildableProductRunnable
69
+         runnableDebuggingMode = "0">
70
+         <BuildableReference
71
+            BuildableIdentifier = "primary"
72
+            BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
73
+            BuildableName = "playground.app"
74
+            BlueprintName = "playground"
75
+            ReferencedContainer = "container:playground.xcodeproj">
76
+         </BuildableReference>
77
+      </BuildableProductRunnable>
78
+      <EnvironmentVariables>
79
+         <EnvironmentVariable
80
+            key = "RECORD_SNAPSHOT_TESTS"
81
+            value = ""
82
+            isEnabled = "YES">
83
+         </EnvironmentVariable>
84
+      </EnvironmentVariables>
85
+   </LaunchAction>
86
+   <ProfileAction
87
+      buildConfiguration = "Release"
88
+      shouldUseLaunchSchemeArgsEnv = "YES"
89
+      savedToolIdentifier = ""
90
+      useCustomWorkingDirectory = "NO"
91
+      debugDocumentVersioning = "YES">
92
+      <MacroExpansion>
93
+         <BuildableReference
94
+            BuildableIdentifier = "primary"
95
+            BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
96
+            BuildableName = "playground.app"
97
+            BlueprintName = "playground"
98
+            ReferencedContainer = "container:playground.xcodeproj">
99
+         </BuildableReference>
100
+      </MacroExpansion>
101
+   </ProfileAction>
102
+   <AnalyzeAction
103
+      buildConfiguration = "Debug">
104
+   </AnalyzeAction>
105
+   <ArchiveAction
106
+      buildConfiguration = "Release"
107
+      revealArchiveInOrganizer = "YES">
108
+   </ArchiveAction>
109
+</Scheme>

+ 5
- 0
playground/ios/playground.xcodeproj/xcshareddata/xcschemes/SnapshotTests.xcscheme View File

@@ -26,6 +26,11 @@
26 26
             value = "$(SOURCE_ROOT)/SnapshotTests/ReferenceImages"
27 27
             isEnabled = "YES">
28 28
          </EnvironmentVariable>
29
+         <EnvironmentVariable
30
+            key = "IMAGE_DIFF_DIR"
31
+            value = "$(SOURCE_ROOT)/SnapshotTests/FailureDiffs"
32
+            isEnabled = "YES">
33
+         </EnvironmentVariable>
29 34
          <EnvironmentVariable
30 35
             key = "TEST_ENABLED"
31 36
             value = "YES"

+ 40
- 11
scripts/test-snapshot.js View File

@@ -3,6 +3,8 @@ const exec = require('shell-utils').exec;
3 3
 
4 4
 const android = includes(process.argv, '--android');
5 5
 const release = includes(process.argv, '--release');
6
+const BRANCH = process.env.BRANCH;
7
+const RECORD = process.env.RECORD === 'true';
6 8
 
7 9
 function run() {
8 10
   if (android) {
@@ -19,7 +21,7 @@ function runAndroidSnapshotTests() {
19 21
 function runIosSnapshotTests() {
20 22
   exec.execSync('npm run build');
21 23
   exec.execSync('npm run pod-install');
22
-  testTarget('SnapshotTests', 'iPhone 11');
24
+  testTarget(RECORD ? 'SnapshotRecordTests' : 'SnapshotTests', 'iPhone 11', '13.0');
23 25
 }
24 26
 
25 27
 function testTarget(scheme, device, OS = 'latest') {
@@ -36,16 +38,43 @@ function testTarget(scheme, device, OS = 'latest') {
36 38
   -UseModernBuildSystem=NO
37 39
   ONLY_ACTIVE_ARCH=YES`);
38 40
 
39
-  exec.execSync(`cd ./playground/ios &&
40
-  RCT_NO_LAUNCH_PACKAGER=true
41
-  xcodebuild test-without-building
42
-  -scheme "${scheme}"
43
-  -workspace playground.xcworkspace
44
-  -sdk iphonesimulator
45
-  -configuration ${conf}
46
-  -destination 'platform=iOS Simulator,name=${device},OS=${OS}'
47
-  -derivedDataPath ./DerivedData/playground
48
-  ONLY_ACTIVE_ARCH=YES`);
41
+  try {
42
+    exec.execSync(`cd ./playground/ios &&
43
+    RCT_NO_LAUNCH_PACKAGER=true
44
+    xcodebuild test-without-building
45
+    -scheme "${scheme}"
46
+    -workspace playground.xcworkspace
47
+    -sdk iphonesimulator
48
+    -configuration ${conf}
49
+    -destination 'platform=iOS Simulator,name=${device},OS=${OS}'
50
+    -derivedDataPath ./DerivedData/playground
51
+    ONLY_ACTIVE_ARCH=YES`);
52
+  } catch (error) {
53
+    if (!RECORD) {
54
+      throw 'Snapshot tests failed';
55
+    }
56
+  }
57
+  finally {
58
+    if (RECORD) {
59
+      pushSnapshots();
60
+    }
61
+  }
62
+}
63
+
64
+function pushSnapshots() {
65
+  setupGit();
66
+  exec.execSync(`git checkout ${BRANCH}`);
67
+  exec.execSync(`git add ./playground/ios/SnapshotTests/ReferenceImages_64`);
68
+  exec.execSync(`git commit -m "Update snapshots [ci skip]"`);
69
+  exec.execSync(`git push deploy ${BRANCH}`);
70
+}
71
+
72
+function setupGit() {
73
+  exec.execSyncSilent(`git config --global push.default simple`);
74
+  exec.execSyncSilent(`git config --global user.email "${process.env.GIT_EMAIL}"`);
75
+  exec.execSyncSilent(`git config --global user.name "${process.env.GIT_USER}"`);
76
+  const remoteUrl = new RegExp(`https?://(\\S+)`).exec(exec.execSyncRead(`git remote -v`))[1];
77
+  exec.execSyncSilent(`git remote add deploy "https://${process.env.GIT_USER}:${process.env.GIT_TOKEN}@${remoteUrl}"`);
49 78
 }
50 79
 
51 80
 run();