Skip to content

Commit

Permalink
Ensure output dir exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Lanchares committed Feb 6, 2019
1 parent 630a2ee commit 4c505eb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,25 @@ const PixelDiff = require('pixel-diff')
const IMAGE_FORMAT = 'png'
const SCREENSHOT_EXTENSION = 'png'

const makeDir = util.promisify(fs.mkdir)
const globDir = util.promisify(glob)

function resolveScreenshotPath(dir, snapshotName) {
return path.resolve(dir, snapshotName)
}

async function ensureScreenshotsDir(dir) {
try {
await makeDir(path.resolve(dir))
} catch (error) {
if (error.code === 'EEXIST') {
return
}

throw error
}
}

async function getScreenshots(dir) {
return await globDir(`*.${SCREENSHOT_EXTENSION}`, { cwd: path.resolve(dir) })
}
Expand All @@ -39,6 +52,8 @@ async function compareSnapshot(
}

async function command({ referenceDir, testDir, outputDir, max }) {
await ensureScreenshotsDir(outputDir)

const snapshots = await getScreenshots(referenceDir)

console.log('Starting tests...\n')
Expand Down

0 comments on commit 4c505eb

Please sign in to comment.