diff --git a/CHANGELOG.md b/CHANGELOG.md index 89263d939ddc..577612471a8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ ([#5353](https://github.com/facebook/jest/pull/5353)) * `[expect]` Support class instances in `.toHaveProperty()` matcher. ([#5367](https://github.com/facebook/jest/pull/5367)) +* `[jest-cli]` Fix npm update command for snapshot summary. + ([#5376](https://github.com/facebook/jest/pull/5376)) ## jest 22.1.4 diff --git a/packages/jest-cli/src/reporters/summary_reporter.js b/packages/jest-cli/src/reporters/summary_reporter.js index 73df2aa69a45..2cadb37eed43 100644 --- a/packages/jest-cli/src/reporters/summary_reporter.js +++ b/packages/jest-cli/src/reporters/summary_reporter.js @@ -129,11 +129,10 @@ export default class SummaryReporter extends BaseReporter { let updateCommand; const event = process.env.npm_lifecycle_event; const prefix = NPM_EVENTS.has(event) ? '' : 'run '; - const client = + const isYarn = typeof process.env.npm_config_user_agent === 'string' && - process.env.npm_config_user_agent.match('yarn') !== null - ? 'yarn' - : 'npm'; + process.env.npm_config_user_agent.match('yarn') !== null; + const client = isYarn ? 'yarn' : 'npm'; const scriptUsesJest = typeof process.env.npm_lifecycle_script === 'string' && process.env.npm_lifecycle_script.indexOf('jest') !== -1; @@ -141,7 +140,11 @@ export default class SummaryReporter extends BaseReporter { if (globalConfig.watch) { updateCommand = 'press `u`'; } else if (event && scriptUsesJest) { - updateCommand = `run \`${client + ' ' + prefix + event} -u\``; + updateCommand = `run \`${client + + ' ' + + prefix + + event + + (isYarn ? '' : ' --')} -u\``; } else { updateCommand = 're-run jest with `-u`'; }