提交 27451e69 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test: fix toSaveImageSnapshot error

上级 6ce2b6f3
...@@ -71,7 +71,7 @@ function toSaveSnapshot(received, { ...@@ -71,7 +71,7 @@ function toSaveSnapshot(received, {
let pass = true; let pass = true;
try { try {
checkSnapshotDir(snapshotDir); checkSnapshotDir(path.dirname(filePath));
fs.writeFileSync(filePath, received); fs.writeFileSync(filePath, received);
writeTestCaseToSnapshotFile(testPath.replace(`${_rootDir}/`, ""), filePath); writeTestCaseToSnapshotFile(testPath.replace(`${_rootDir}/`, ""), filePath);
} catch (e) { } catch (e) {
...@@ -108,7 +108,7 @@ function toSaveImageSnapshot( ...@@ -108,7 +108,7 @@ function toSaveImageSnapshot(
SNAPSHOTS_DIR, SNAPSHOTS_DIR,
}); });
const _fileName = createFileName({ const _fileName = createFileName({
fileName: customSnapshotIdentifier ? customSnapshotIdentifier() : "", fileName: customSnapshotIdentifier ? `${customSnapshotIdentifier()}.png` : "",
testPath, testPath,
currentTestName, currentTestName,
fileType: "png", fileType: "png",
...@@ -118,7 +118,7 @@ function toSaveImageSnapshot( ...@@ -118,7 +118,7 @@ function toSaveImageSnapshot(
let pass = true; let pass = true;
try { try {
checkSnapshotDir(snapshotDir); checkSnapshotDir(path.dirname(filePath));
fs.writeFileSync(filePath, Buffer.from(received, "base64")); fs.writeFileSync(filePath, Buffer.from(received, "base64"));
writeTestCaseToSnapshotFile(testPath.replace(`${_rootDir}/`, ""), filePath); writeTestCaseToSnapshotFile(testPath.replace(`${_rootDir}/`, ""), filePath);
} catch (e) { } catch (e) {
......
...@@ -41,7 +41,7 @@ describe('toSaveSnapshot & toSaveImageSnapshot template', () => { ...@@ -41,7 +41,7 @@ describe('toSaveSnapshot & toSaveImageSnapshot template', () => {
expect(img1).toSaveImageSnapshot({ expect(img1).toSaveImageSnapshot({
customSnapshotsDir: './customDir/__image_snapshots__', customSnapshotsDir: './customDir/__image_snapshots__',
customSnapshotIdentifier() { customSnapshotIdentifier() {
return 'test-toSaveImageSnapshot-2-1.png'; return 'test-toSaveImageSnapshot-2-1';
}, },
}) })
...@@ -53,7 +53,7 @@ describe('toSaveSnapshot & toSaveImageSnapshot template', () => { ...@@ -53,7 +53,7 @@ describe('toSaveSnapshot & toSaveImageSnapshot template', () => {
const img3 = await program.screenshot(); const img3 = await program.screenshot();
expect(img3).toSaveImageSnapshot({ expect(img3).toSaveImageSnapshot({
customSnapshotIdentifier() { customSnapshotIdentifier() {
return 'test-toSaveImageSnapshot-2-3.png'; return 'test-toSaveImageSnapshot-2-3';
}, },
}) })
}) })
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册