Jest: Snapshot Update Command Incorrect

Created on 6 Jan 2017  Â·  20Comments  Â·  Source: facebook/jest

Do you want to request a feature or report a bug?

bug

What is the current behavior?

I run jest with this weird command:

npm start test.server

When I do that and it encounters a snapshot error it returns the following:

Snapshot Summary
 › 2 obsolete snapshots found, run with `npm start -- -u` to remove them.

That is not the correct command.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

...

What is the expected behavior?

I expect it to provide the correct instructions to update the snapshots:

npm start test.server -- -u

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

  • jest 18.10
  • npm 3 or yarn depending on my mood
  • mac os 10.11 (el capitan)
Enhancement Help Wanted

Most helpful comment

Makes sense. Thank you for explaining. Perhaps ya'll could have a GitHub saved reply to explain this so it doesn't discourage potential contributors.

All 20 comments

I can work on repro steps and everything and try to solve this for you at some point, just wanted to log that it was an issue.

We use npm_lifecycle_event to determine that, so I guess npm's issue tracker would be more proper place to put this?

Thanks @thymikee I'm not convinced jest is doing the right thing here in using npm_lifecycle_event, because in this case you'd want to include additional commands, not just the first one. Anyway, not a huge deal, but might be nice to look into sometime.

Yeah, I don't think npm is giving us all the information we need to print the accurate version of this.

Why was this issue closed? @xjamundx even said he's willing to work on it. Any reason to close the issue over that? It's pretty disheartening to folks (maybe not @xjamundx who has thick skin) when their issues are closed so quickly like this... Maybe I'm misunderstanding...

@kentcdodds hm, I didn't thought it could be disheartening, sorry if you felt this way @xjamundx!

So... while writing this response I realised that I misread the npm start thus my logic was flawed.

Reopening this.
@xjamundx if you feel like working on fixing this, if possible, I'm glad to help.

@kentcdodds Jest is operating under extremely limited resources. We simply cannot keep up on issues. We'd like to keep our bug tracker useful and we aggressively (sometimes too aggressively) close issues if we believe that the team cannot or will not resolve them within the next 3 months or so. We are always happy to keep the discussion going and reopen issues if necessary.

For this issue in particular, I agree it is an odd setup but if npm isn't giving us the necessary information, we'd probably have to do something hacky to get to the real command. I'd also like to call out that we don't print yarn test -u yet because we have no code to detect yarn yet.

Makes sense. Thank you for explaining. Perhaps ya'll could have a GitHub saved reply to explain this so it doesn't discourage potential contributors.

@xjamundx is there any particular reason why are you using npm start test.server command? npm start is intended to just run start script. npm run test.server should be used instead and in this scenario, Jest works correctly.
There's no clean way to detect your variant right now.

This is a common pattern with nps

Ah! Gotcha! I'll take a look in the afternoon. Thanks Kent

Thanks!

@kentcdodds after taking a look at nps, it appears that npm start test.server -- -u won't work at all here. In order to make it work, jest would have to say npm start "test.server -u" instead.

Yes, this was changed in recent versions of nps.

Note that this works with yarn now but still misses envars:

Do we need the whole command? Is there much lost by saying:

Inspect your code changes or run again with -u to update them

This phrasing should be accurate for all cases now and in the future

@rickhanlonii I'm on board this message should be universal. We can leverage terminal utils and just point to use !! -u! 😉

Inspect your code changes or run again with -u to update them. Protip: !! -u will run previous command with -u flag.

Hello,

In my issue, -u flag didn't change anything. Still snapshot isn't updated and I need manually to delete it to allow Jest create new one. I'm working with project generated from vue-cli, template webpack. So I'm running unit tests by npm run unit. Command npm run unit -u didn't change snapshots. What else, it also causes an error. Log below:

0 info it worked if it ends with ok
1 verbose cli [ '/home/marcinlesek/.nvm/versions/node/v8.9.4/bin/node',
1 verbose cli   '/home/marcinlesek/.nvm/versions/node/v8.9.4/bin/npm',
1 verbose cli   'run',
1 verbose cli   'unit' ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ 'preunit', 'unit', 'postunit' ]
5 info lifecycle [email protected]~preunit: [email protected]
6 info lifecycle [email protected]~unit: [email protected]
7 verbose lifecycle [email protected]~unit: unsafe-perm in lifecycle true
8 verbose lifecycle [email protected]~unit: PATH: /home/marcinlesek/.nvm/versions/node/v8.9.4/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/marcinlesek/Projekty/trader-spa/node_modules/.bin:/home/marcinlesek/.sdkman/candidates/springboot/current/bin:/home/marcinlesek/.sdkman/candidates/grails/current/bin:/home/marcinlesek/.sdkman/candidates/gradle/current/bin:/home/marcinlesek/.nvm/versions/node/v8.9.4/bin:/home/marcinlesek/bin:/home/marcinlesek/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
9 verbose lifecycle [email protected]~unit: CWD: /home/marcinlesek/Projekty/trader-spa
10 silly lifecycle [email protected]~unit: Args: [ '-c', 'jest --config test/unit/jest.conf.js' ]
11 silly lifecycle [email protected]~unit: Returned: code: 1  signal: null
12 info lifecycle [email protected]~unit: Failed to exec unit script
13 verbose stack Error: [email protected] unit: `jest --config test/unit/jest.conf.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/home/marcinlesek/.nvm/versions/node/v8.9.4/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (/home/marcinlesek/.nvm/versions/node/v8.9.4/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid [email protected]
15 verbose cwd /home/marcinlesek/Projekty/trader-spa
16 verbose Linux 4.4.0-112-generic
17 verbose argv "/home/marcinlesek/.nvm/versions/node/v8.9.4/bin/node" "/home/marcinlesek/.nvm/versions/node/v8.9.4/bin/npm" "run" "unit"
18 verbose node v8.9.4
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error [email protected] unit: `jest --config test/unit/jest.conf.js`
22 error Exit status 1
23 error Failed at the [email protected] unit script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Some one could help with this issue?

Thanks in advance!

Best,
Marcin

Does running npm run unit -- -u help?

Firstly, thanks for fast response @thymikee. Yes, this command works fine. I think it will be nice move to fix it later to be just -u. :smile:

@marcinlesek the extra -- is a limitation of npm, it's the only way to pass args through

If you use yarn you could run:

yarn unit -u

Was this page helpful?
0 / 5 - 0 ratings