Skip to content

Commit cd61215

Browse files
author
greweb
committed
Fix Jest snapshot generation for platform-specific directories
- Add snapshotResolver to jest.config.js for platform-specific snapshots - Create snapshot-resolver.js to separate iOS and Android snapshots - iOS snapshots: e2e/snapshots/reference/ios/ - Android snapshots: e2e/snapshots/reference/android/ - Remove duplicate snapshots to force regeneration with new structure - Fix root cause: Jest was generating snapshots in wrong directories
1 parent 25c41d0 commit cd61215

20 files changed

+66
-0
lines changed

example/e2e/jest.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ module.exports = {
2121
bail: false, // Continue running tests even if some fail
2222
collectCoverage: false, // E2E tests don't need code coverage
2323
setupFilesAfterEnv: ['<rootDir>/e2e/setup.js'],
24+
// Configure snapshots to be platform-specific
25+
snapshotResolver: '<rootDir>/e2e/snapshot-resolver.js',
2426
};

example/e2e/snapshot-resolver.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Jest Snapshot Resolver for Platform-Specific Snapshots
3+
*
4+
* This resolver ensures that snapshots are generated in platform-specific directories:
5+
* - iOS: e2e/snapshots/reference/ios/
6+
* - Android: e2e/snapshots/reference/android/
7+
*/
8+
9+
const path = require('path');
10+
11+
// Get the platform from environment variables or Detox configuration
12+
function getPlatform() {
13+
// Check if we're running in CI
14+
if (process.env.CI) {
15+
// In CI, we can determine platform from the job name or environment
16+
if (process.env.GITHUB_JOB && process.env.GITHUB_JOB.includes('iOS')) {
17+
return 'ios';
18+
}
19+
if (process.env.GITHUB_JOB && process.env.GITHUB_JOB.includes('Android')) {
20+
return 'android';
21+
}
22+
}
23+
24+
// Check Detox configuration
25+
if (process.env.DETOX_CONFIGURATION) {
26+
if (process.env.DETOX_CONFIGURATION.includes('ios')) {
27+
return 'ios';
28+
}
29+
if (process.env.DETOX_CONFIGURATION.includes('android')) {
30+
return 'android';
31+
}
32+
}
33+
34+
// Default to ios for local development
35+
return 'ios';
36+
}
37+
38+
module.exports = {
39+
// Resolve the path for snapshot files
40+
resolveSnapshotPath: (testPath, snapshotExtension) => {
41+
const platform = getPlatform();
42+
const testDir = path.dirname(testPath);
43+
const testFileName = path.basename(testPath, path.extname(testPath));
44+
45+
// Create platform-specific snapshot path
46+
const snapshotDir = path.join(testDir, 'snapshots', 'reference', platform);
47+
return path.join(snapshotDir, `${testFileName}${snapshotExtension}`);
48+
},
49+
50+
// Resolve the path for test files
51+
resolveTestPath: (snapshotPath, snapshotExtension) => {
52+
const testDir = path.dirname(snapshotPath);
53+
const snapshotFileName = path.basename(snapshotPath, snapshotExtension);
54+
55+
// Go up from snapshots/reference/platform to find the test file
56+
const e2eDir = path.dirname(path.dirname(path.dirname(testDir)));
57+
return path.join(e2eDir, 'tests', `${snapshotFileName}.test.js`);
58+
},
59+
60+
// Test if a path is a snapshot file
61+
testPathForConsistencyCheck: (path) => {
62+
return path.includes('snapshots') && path.endsWith('.snap');
63+
},
64+
};
-283 KB
Binary file not shown.
-261 KB
Binary file not shown.
-333 KB
Binary file not shown.
-230 KB
Binary file not shown.
-287 KB
Binary file not shown.
-265 KB
Binary file not shown.
Binary file not shown.
-595 KB
Binary file not shown.

0 commit comments

Comments
 (0)