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

Add --update and --watch options #4

Merged
merged 9 commits into from
Feb 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 2 additions & 5 deletions update-and-show-snapshots.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
let { spawn } = require('child_process')
let chalk = require('chalk')

let showSnapshots = require('./show-snapshots')

async function updateAndShowSnaphots (print, cwd, filter) {
print(chalk.blue('\nUpdating snapshots... \n'))

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

spawned.on('exit', async () => {
spawned.on('exit', () => {
print('\n')
await showSnapshots(print, cwd, filter)
showSnapshots(print, cwd, filter)
})
}

Expand Down
7 changes: 5 additions & 2 deletions watch-and-show-snapshots.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
let fs = require('fs')
let path = require('path')
let chokidar = require('chokidar')
let parseGitignore = require('parse-gitignore')

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

let rootPath = path.dirname(require.main.filename)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require.main.filename will point to /path/to/the/project/node_modules/.bin/print-snapshots.

I think we need pkg-up to find package.json and be sure about the root of the project.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems, I need to sleep a little :-)


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

if (fs.existsSync(`${ cwd }/.gitignore`)) {
if (fs.existsSync(`${ rootPath }/.gitignore`)) {
ignored = [...new Set([
...ignored,
...parseGitignore(fs.readFileSync(`${ cwd }/.gitignore`)).map(
...parseGitignore(fs.readFileSync(`${ rootPath }/.gitignore`)).map(
p => /\/$/.test(p) ? p.replace(/\/$/, '') : p
)
])]
Expand Down