Skip to content

Commit

Permalink
Fix handling of windows paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jackjocross committed Jun 3, 2019
1 parent ed745fc commit e5d41a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
4 changes: 2 additions & 2 deletions __tests__/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down Expand Up @@ -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',
Expand Down
11 changes: 4 additions & 7 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e5d41a8

Please sign in to comment.