forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-snapshot.js
79 lines (70 loc) · 2.27 KB
/
test-snapshot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
const includes = require('lodash/includes');
const exec = require('shell-utils').exec;
const android = includes(process.argv, '--android');
const release = includes(process.argv, '--release');
const BRANCH = process.env.BRANCH;
const RECORD = process.env.RECORD === 'true';
function run() {
if (android) {
runAndroidSnapshotTests();
} else {
runIosSnapshotTests();
}
}
function runAndroidSnapshotTests() {}
function runIosSnapshotTests() {
exec.execSync('npm run build');
exec.execSync('npm run pod-install');
testTarget(RECORD ? 'SnapshotRecordTests' : 'SnapshotTests', 'iPhone 11', '13.7');
}
function testTarget(scheme, device, OS = 'latest') {
const conf = release ? `Release` : `Debug`;
exec.execSync(`cd ./playground/ios &&
RCT_NO_LAUNCH_PACKAGER=true
xcodebuild build build-for-testing
-scheme "${scheme}"
-workspace playground.xcworkspace
-sdk iphonesimulator
-configuration ${conf}
-derivedDataPath ./DerivedData/playground
-quiet
-UseModernBuildSystem=YES
ONLY_ACTIVE_ARCH=YES`);
try {
exec.execSync(`cd ./playground/ios &&
RCT_NO_LAUNCH_PACKAGER=true
xcodebuild test-without-building
-scheme "${scheme}"
-workspace playground.xcworkspace
-sdk iphonesimulator
-configuration ${conf}
-destination 'platform=iOS Simulator,name=${device},OS=${OS}'
-derivedDataPath ./DerivedData/playground
ONLY_ACTIVE_ARCH=YES`);
} catch (error) {
if (!RECORD) {
throw 'Snapshot tests failed';
}
} finally {
if (RECORD) {
pushSnapshots();
}
}
}
function pushSnapshots() {
setupGit();
exec.execSync(`git checkout ${BRANCH}`);
exec.execSync(`git add ./playground/ios/SnapshotTests/ReferenceImages_64`);
exec.execSync(`git commit -m "Update snapshots [ci skip]"`);
exec.execSync(`git push deploy ${BRANCH}`);
}
function setupGit() {
exec.execSyncSilent(`git config --global push.default simple`);
exec.execSyncSilent(`git config --global user.email "${process.env.GIT_EMAIL}"`);
exec.execSyncSilent(`git config --global user.name "${process.env.GIT_USER}"`);
const remoteUrl = new RegExp(`https?://(\\S+)`).exec(exec.execSyncRead(`git remote -v`))[1];
exec.execSyncSilent(
`git remote add deploy "https://${process.env.GIT_USER}:${process.env.GIT_TOKEN}@${remoteUrl}"`
);
}
run();