Skip to content

Commit 4c505eb

Browse files
author
Eduardo Lanchares
committed
Ensure output dir exists
1 parent 630a2ee commit 4c505eb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

commands/test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,25 @@ const PixelDiff = require('pixel-diff')
77
const IMAGE_FORMAT = 'png'
88
const SCREENSHOT_EXTENSION = 'png'
99

10+
const makeDir = util.promisify(fs.mkdir)
1011
const globDir = util.promisify(glob)
1112

1213
function resolveScreenshotPath(dir, snapshotName) {
1314
return path.resolve(dir, snapshotName)
1415
}
1516

17+
async function ensureScreenshotsDir(dir) {
18+
try {
19+
await makeDir(path.resolve(dir))
20+
} catch (error) {
21+
if (error.code === 'EEXIST') {
22+
return
23+
}
24+
25+
throw error
26+
}
27+
}
28+
1629
async function getScreenshots(dir) {
1730
return await globDir(`*.${SCREENSHOT_EXTENSION}`, { cwd: path.resolve(dir) })
1831
}
@@ -39,6 +52,8 @@ async function compareSnapshot(
3952
}
4053

4154
async function command({ referenceDir, testDir, outputDir, max }) {
55+
await ensureScreenshotsDir(outputDir)
56+
4257
const snapshots = await getScreenshots(referenceDir)
4358

4459
console.log('Starting tests...\n')

0 commit comments

Comments
 (0)