From e5d41a821ab20b187206b55ce1c3ad6525412953 Mon Sep 17 00:00:00 2001 From: jack Date: Mon, 3 Jun 2019 18:05:15 -0400 Subject: [PATCH 1/2] Fix handling of windows paths --- __tests__/plugin.test.js | 4 ++-- src/plugin.js | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/__tests__/plugin.test.js b/__tests__/plugin.test.js index ddb40c7..3de88ca 100644 --- a/__tests__/plugin.test.js +++ b/__tests__/plugin.test.js @@ -7,8 +7,8 @@ import { diffImageToSnapshot } from 'jest-image-snapshot/src/diff-snapshot'; import { - matchImageSnapshotPlugin, matchImageSnapshotOptions, + matchImageSnapshotPlugin, } from '../src/plugin'; jest.mock('jest-image-snapshot/src/diff-snapshot', () => ({ @@ -42,7 +42,7 @@ describe('plugin', () => { path: '/cypress/snapshots/path/to/__diff_output__/cheese.diff.png', }); expect(diffImageToSnapshot).toHaveBeenCalledWith({ - snapshotsDir: '/cypress/snapshots/path/to/', + snapshotsDir: '/cypress/snapshots/path/to', diffDir: '/cypress/snapshots/path/to/__diff_output__', updateSnapshot: true, receivedImageBuffer: 'cheese', diff --git a/src/plugin.js b/src/plugin.js index 307640e..8e66493 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -69,14 +69,11 @@ export function matchImageSnapshotPlugin({ path: screenshotPath }) { const receivedImageBuffer = fs.readFileSync(screenshotPath); fs.removeSync(screenshotPath); - const screenshotFileName = screenshotPath.slice( - screenshotPath.lastIndexOf(path.sep) + 1 + const { dir: screenshotDir, name: snapshotIdentifier } = path.parse( + screenshotPath ); - const screenshotDir = screenshotPath.replace(screenshotFileName, ''); - const relativePath = screenshotDir.match( - new RegExp(`${screenshotsFolder}(.*)`) - )[1]; - const snapshotIdentifier = screenshotFileName.replace('.png', ''); + + const relativePath = path.relative(screenshotsFolder, screenshotDir); const snapshotsDir = customSnapshotsDir ? path.join(process.cwd(), customSnapshotsDir, relativePath) : path.join(screenshotsFolder, '..', 'snapshots', relativePath); From 215eb0ff6846a418489009913c5329c93614db4b Mon Sep 17 00:00:00 2001 From: jack Date: Mon, 3 Jun 2019 18:10:12 -0400 Subject: [PATCH 2/2] v3.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f7ee0c4..dd66e24 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cypress-image-snapshot", - "version": "3.1.0", + "version": "3.1.1", "description": "Cypress bindings for jest-image-snapshot.", "repository": "https://github.com/palmerhq/cypress-image-snapshot", "author": "Jack Cross ",