Hugh McCamphill
Yes, I see that :) But it's still a question for me where and how do you expose jestExpect to already use in this block? I am lacking infrastructure understanding for that purpose
To use jestExpect instead of the expect exposed by detox I have to import it explicitly.
Also I see the issue with toMatchImage not available in the methods scope after been extended to.
import { configureToMatchImageSnapshot } from 'jest-image-snapshot';
import fs from 'fs';
import path from 'path';
import kebabCase from 'lodash.kebabcase';
import jestExpect from 'expect'
const toMatchImage = configureToMatchImageSnapshot({
comparisonMethod: 'ssim', failureThreshold: 0.002, failureThresholdType: 'percent'
});
jestExpect.extend({ toMatchImage });
jestExpect.extend({
async toMatchImageSnapshot(screenName) {
const platform = device.getPlatform();
const deviceName = device.name.split(' ').slice(1).join('');
const deviceType = JSON.parse(deviceName).type.replace(',','');
const SNAPSHOTS_DIR = `__image_snapshots__/${platform}/${deviceType}`;
const { testPath, currentTestName } = this;
const customSnapshotsDir = path.join(path.dirname(testPath), SNAPSHOTS_DIR);
const customSnapshotIdentifier = kebabCase(`${path.basename(testPath)}-${currentTestName}-${screenName}`)
const tempPath = await device.takeScreenshot(screenName);
const image = fs.readFileSync(tempPath);
jestExpect(image).toMatchImage({ customSnapshotIdentifier, customSnapshotsDir });
~~~~~~~~~~~
return { pass: true }
},
});
global.jestExpect = jestExpect