-
Notifications
You must be signed in to change notification settings - Fork 20
/
snapshotResolve.js
43 lines (40 loc) · 1.66 KB
/
snapshotResolve.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
const fs = require('fs');
module.exports = {
resolveSnapshotPath: (testPath, snapshotExtension) => {
let snapshotFilePath = '';
if (testPath.endsWith('.ts')) {
snapshotFilePath = testPath.slice(0, -3).concat('.js').concat(snapshotExtension);
} else if (testPath.indexOf('/esm/') != -1) {
snapshotFilePath = testPath.replace('/esm/', '/src/').concat(snapshotExtension);
} else if (testPath.indexOf('/cjs/') != -1) {
snapshotFilePath = testPath.replace('/cjs/', '/src/').concat(snapshotExtension);
}
snapshotFilePath = snapshotFilePath.replace('/src/', '/src/test/snapshots/');
// console.log(`snapshotFilePath out = ${snapshotFilePath}`);
return snapshotFilePath;
},
// resolves from snapshot to test path
resolveTestPath: (snapshotFilePath, snapshotExtension) => {
let testFilePath = snapshotFilePath.replace('/test/snapshots/', '/');
testFilePath = testFilePath.substring(
0,
testFilePath.indexOf(snapshotExtension)
);
testFilePath = testFilePath.replace('.js', '.ts');
if (!fs.existsSync(testFilePath)) {
const defaultPath = testFilePath;
testFilePath = testFilePath.replace('.ts', '.js');
testFilePath = testFilePath.replace('/src/', '/cjs/');
if (!fs.existsSync(testFilePath)) {
testFilePath = testFilePath.replace('/cjs/', '/esm/');
if (!fs.existsSync(testFilePath)) {
testFilePath = defaultPath;
}
}
}
return testFilePath;
},
// Example test path, used for preflight consistency check of the implementation above
testPathForConsistencyCheck:
'/home/sandeepc/work/ForgeRock/sources/frodo-lib/src/ops/IdmOps.test.ts',
};