Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix approve command with custom fileNameFormatter #532

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/runner/src/commands/approve/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ const getConfig = require('../../config');

const isPNG = (file) => file.substr(-4) === '.png';

function getFiles(dir, subdir = '') {
const parentDir = path.resolve(dir, subdir);
const files = fs.readdirSync(parentDir);

return files.flatMap((file) => {
const res = path.resolve(parentDir, file);
const filePath = path.join(subdir, file);
return fs.statSync(res).isDirectory() ? getFiles(dir, filePath) : filePath;
})
}

function approve(args) {
const config = getConfig();
const { outputDir, differenceDir, referenceDir, diffOnly } = parseOptions(
Expand All @@ -17,7 +28,7 @@ function approve(args) {

// If diff only is active, only copy over the files that were changed
const inputDir = diffOnly ? differenceDir : outputDir;
const files = fs.readdirSync(inputDir).filter(isPNG);
const files = getFiles(inputDir).filter(isPNG);

if (!files.length) {
die(
Expand Down