jest-setup.js 933 字节
Newer Older
1 2 3 4 5 6 7 8
const path = require('path');
const {
	configureToMatchImageSnapshot
} = require('jest-image-snapshot');

const hbuilderx_version = process.env.HX_Version
const uniTestPlatformInfo = process.env.uniTestPlatformInfo ? process.env.uniTestPlatformInfo.replace(/\s/g,'_') : ''
const folderName = `__image_snapshots__/${hbuilderx_version}/__${uniTestPlatformInfo}__`
9 10 11 12 13 14 15
let environment = 'official'
if(hbuilderx_version.includes('dev')){
  environment = 'dev'
}else if(hbuilderx_version.includes('alpha')){
  environment = 'alpha'
}
const baseFolderName = `__image_snapshots__/base/${environment}/__${uniTestPlatformInfo}__`
16 17 18 19 20 21

expect.extend({
	toMatchImageSnapshot: configureToMatchImageSnapshot({
		customSnapshotIdentifier(args) {
			return args.currentTestName.replace(/\//g, '-').replace(' ', '-');
		},
22
		customSnapshotsDir: path.join(__dirname, baseFolderName),
23 24
		customDiffDir: path.join(__dirname, `${folderName}/`, 'diff'),
	}),
25
});