Skip to content

Commit

Permalink
refactor: log screenshot paths and add unit test (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Jul 26, 2024
1 parent a4e5301 commit f5107b3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions comparadise-utils/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from '../jest.config';

export default config;
3 changes: 2 additions & 1 deletion comparadise-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"scripts": {
"build": "tsup",
"postbuild": "echo \"require('./dist/match-screenshot');\" > commands.js",
"prepack": "bun run build"
"prepack": "bun run build",
"test": "jest"
}
}
1 change: 1 addition & 0 deletions comparadise-utils/screenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { createImageFileName } from './files';
*/
export function baseExists(path: string) {
const fileName = createImageFileName(path, 'base');
console.log('Checking if base image exists at:', fileName);
const exists = fs.existsSync(fileName);

if (!exists) {
Expand Down
15 changes: 15 additions & 0 deletions comparadise-utils/test/screenshots.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { baseExists } from '../screenshots';
import { existsSync } from 'fs';
import { expect } from '@jest/globals';

jest.mock('fs');

describe('screenshots', () => {
it('should take a screenshot', () => {
(existsSync as jest.Mock).mockReturnValue(true);
const path = 'path/to/file';
const result = baseExists(path);
expect(result).toBe(true);
expect(existsSync).toHaveBeenCalledWith(`${path}/base.png`);
});
});
2 changes: 1 addition & 1 deletion comparadise-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["cypress"]
"types": ["cypress", "jest"]
},
"include": ["./**/*", "../reset.d.ts"]
}

0 comments on commit f5107b3

Please sign in to comment.