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

test: fix toSaveImageSnapshot error

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