jest icon indicating copy to clipboard operation
jest copied to clipboard

feat(snapshot): support snapshotResolver and snapshotSerializers written in ESM

Open chentsulin opened this issue 4 years ago • 9 comments

Summary

Part of #11167.

See the discussion on the snapshotResolver and snapshotSerializers config: https://github.com/facebook/jest/issues/11167#issuecomment-953569252 https://github.com/facebook/jest/issues/11167#issuecomment-953585698

Test plan

Integration test added.

chentsulin avatar Oct 29 '21 08:10 chentsulin

@chentsulin I wonder if this could be finalized or if it is waiting for a re-review from @SimenB ?...

We need this here: https://github.com/Maxim-Mazurok/google-api-typings-generator/blob/062854a2021be2dd244855261a73f5172bf597c2/custom-resolver.cjs for the use-case of using one snapshot file per test.

Thank you!

Maxim-Mazurok avatar Sep 28 '22 11:09 Maxim-Mazurok

Main issue is that we load the resolver within the tests (https://github.com/facebook/jest/pull/12014#discussion_r739624598), which means it's pretty much blocked by full ESM support

SimenB avatar Sep 28 '22 11:09 SimenB

Ah, I see, thank you for the update, we are re-considering our approach now. Cheers!

Maxim-Mazurok avatar Sep 28 '22 12:09 Maxim-Mazurok

It might make sense to not load it within, but that means people who have written it in TS or something that requires transpilation will fail. So not sure which tradeoff is the best here

SimenB avatar Sep 28 '22 12:09 SimenB

It's been a year. Any updates?

Anutrix avatar Sep 21 '23 23:09 Anutrix

This PR is stale because it has been open 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Sep 21 '24 00:09 github-actions[bot]

It's been another year. Any updates?

Anutrix avatar Sep 22 '24 06:09 Anutrix

Could this PR be rebased so we can merge it for Jest 30?

cpojer avatar May 22 '25 08:05 cpojer

Following up my old comment - I think we can just load the resolver outside of the tests. That gives ESM support, and if people wanna write it in TS they can use https://nodejs.org/en/learn/typescript/run-natively

SimenB avatar May 27 '25 09:05 SimenB