Skip to content

Commit

Permalink
fix: Apply review notes ai#2
Browse files Browse the repository at this point in the history
  • Loading branch information
LordotU committed Feb 20, 2020
1 parent 1cd5934 commit 59983d2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 28 deletions.
27 changes: 7 additions & 20 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,19 @@ async function run () {

if (arg === '--version') {
showVersion(print)
return
}

if (arg === '--help') {
} else if (arg === '--help') {
showHelp(print)
return
}

if (arg === '--update') {
} else if (arg === '--update') {
await updateAndShowSnaphots(print, cwd, filter)
return
}

if (arg === '--watch') {
(await watchAndShowSnaphots(print, cwd, filter))
.on('error', err => error(err.stack || err))
return
}

if (arg.startsWith('--')) {
} else if (arg === '--watch') {
await watchAndShowSnaphots(print, error, cwd, filter)
} else if (arg.startsWith('--')) {
error(`Unknown argument ${ arg }\n`)
showHelp(print)
process.exit(1)
} else {
await showSnapshots(print, cwd, arg)
}

await showSnapshots(print, cwd, arg)
}

run().catch(e => {
Expand Down
5 changes: 2 additions & 3 deletions update-and-show-snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ let showSnapshots = require('./show-snapshots')
async function updateAndShowSnaphots (print, cwd, filter) {
print(chalk.blue('\nUpdating snapshots... \n'))

let spawned = spawn('npx', ['jest', '-u'], {
let spawned = spawn('npx', ['jest', '--no-install', '-u'], {
cwd, stdio: 'inherit'
})

spawned.on('exit', async () => {
print(chalk.green('\nSnapshots updated! \n'))

print('\n')
await showSnapshots(print, cwd, filter)
})
}
Expand Down
9 changes: 4 additions & 5 deletions watch-and-show-snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let parseGitignore = require('parse-gitignore')

let updateAndShowSnaphots = require('./update-and-show-snapshots')

async function watchAndShowSnaphots (print, cwd, filter) {
async function watchAndShowSnaphots (print, error, cwd, filter) {
let ignored = ['.git', 'node_modules']

if (fs.existsSync(`${ cwd }/.gitignore`)) {
Expand All @@ -20,10 +20,9 @@ async function watchAndShowSnaphots (print, cwd, filter) {
cwd, ignored
})

return watcher
.on('change', async () => {
await updateAndShowSnaphots(print, cwd, filter)
})
watcher
.on('change', () => updateAndShowSnaphots(print, cwd, filter))
.on('error', err => error(err.stack || err))
}

module.exports = watchAndShowSnaphots

0 comments on commit 59983d2

Please sign in to comment.