-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add --update and --watch options
- Loading branch information
Oleg Levshin
committed
Feb 20, 2020
1 parent
ef17eb8
commit cad21c4
Showing
5 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,9 @@ | |
}, | ||
"dependencies": { | ||
"chalk": "^3.0.0", | ||
"globby": "^11.0.0" | ||
"chokidar": "^3.3.1", | ||
"globby": "^11.0.0", | ||
"parse-gitignore": "^1.0.1" | ||
}, | ||
"author": "Andrey Sitnik <[email protected]>", | ||
"license": "MIT", | ||
|
@@ -61,5 +63,8 @@ | |
"CLI", | ||
"backtick" | ||
] | ||
}, | ||
"peerDependencies": { | ||
"jest": "^25.1.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
let { exec } = require('child_process') | ||
let { promisify } = require('util') | ||
let chalk = require('chalk') | ||
|
||
let showSnapshots = require('./show-snapshots') | ||
|
||
let execCommand = promisify(exec) | ||
|
||
module.exports = async function updateAndShowSnaphots (print, cwd, filter) { | ||
print(chalk.blue('Updating snapshots... \n')) | ||
|
||
await execCommand('"./node_modules/.bin/jest" -u', { | ||
cwd | ||
}) | ||
|
||
print(chalk.green('Snapshots updated! \n')) | ||
|
||
await showSnapshots(print, cwd, filter) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
let fs = require('fs') | ||
let chokidar = require('chokidar') | ||
let parseGitignore = require('parse-gitignore') | ||
|
||
let updateAndShowSnaphots = require('./update-and-show-snapshots') | ||
|
||
module.exports = async function watchAndShowSnaphots (print, cwd, filter) { | ||
let ignored = ['.git', 'node_modules'] | ||
|
||
if (fs.existsSync(`${ cwd }/.gitignore`)) { | ||
ignored = [...new Set([ | ||
...ignored, | ||
...parseGitignore(fs.readFileSync(`${ cwd }/.gitignore`)).map( | ||
p => /\/$/.test(p) ? p.replace(/\/$/, '') : p | ||
) | ||
])] | ||
} | ||
|
||
let watcher = chokidar.watch('**/*.js', { | ||
cwd, ignored | ||
}) | ||
|
||
return watcher | ||
.on('change', async () => { | ||
await updateAndShowSnaphots(print, cwd, filter) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters