diff --git a/jest-setup.js b/jest-setup.js index 499a5798249524c3024780d5a15cf775ce9f7e9d..325958292289f146677ef705658e350726bb5c8b 100644 --- a/jest-setup.js +++ b/jest-setup.js @@ -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) { diff --git a/pages/toSaveSnapshot-toSaveImageSnapshot-template.test.js b/pages/toSaveSnapshot-toSaveImageSnapshot-template.test.js index 06b47bcf432b6e652c633e95705d4df6d619dda9..bfd7db8ce36a853b0080d65789801b290fec616b 100644 --- a/pages/toSaveSnapshot-toSaveImageSnapshot-template.test.js +++ b/pages/toSaveSnapshot-toSaveImageSnapshot-template.test.js @@ -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 +});