Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
chentsulin wants to merge1 commit intojestjs:main
base:main
Choose a base branch
Loading
fromchentsulin:import-snapshotResolver-snapshotSerializers

Conversation

@chentsulin
Copy link
Contributor

@chentsulinchentsulin commentedOct 29, 2021
edited
Loading

Summary

Part of#11167.

See the discussion on thesnapshotResolver andsnapshotSerializers config:#11167 (comment)#11167 (comment)

Test plan

Integration test added.

Josh-Cena, Maxim-Mazurok, thernstig, and jerone reacted with thumbs up emoji
@chentsulinchentsulinforce-pushed theimport-snapshotResolver-snapshotSerializers branch fromf8aa171 to2cab732CompareOctober 30, 2021 03:56
it('defining tests and hooks asynchronously throws',()=>{
constresult=runJest('circus-declaration-errors',[
it('defining tests and hooks asynchronously throws',async()=>{
constresult=awaitrunJest('circus-declaration-errors',[
Copy link
ContributorAuthor

@chentsulinchentsulinOct 30, 2021
edited
Loading

Choose a reason for hiding this comment

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

ThisrunJest function actually doesn't return a promise, so we should find a way to test this kind of stuff.
This test got failed after I putruntime.requireModule into a async function.

From:

constesm=runtime.unstable_shouldLoadAsEsm(testPath);if(esm){awaitruntime.unstable_importModule(testPath);}else{runtime.requireModule(testPath);}

To:

constlocalRequire=async<T=unknown>(path:string):Promise<T>=>{constesm=runtime.unstable_shouldLoadAsEsm(path);if(esm){returnruntime.unstable_importModule(path)asany;}else{returnruntime.requireModule(path);}};awaitlocalRequire(testPath);

Copy link
Member

Choose a reason for hiding this comment

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

runJest spawnsjest in a shell, so it should not be affected by any internal changes in Jest

@chentsulinchentsulinforce-pushed theimport-snapshotResolver-snapshotSerializers branch 4 times, most recently from933e7ca tob961505CompareOctober 30, 2021 05:29
@chentsulinchentsulin marked this pull request as ready for reviewOctober 30, 2021 05:30
@chentsulinchentsulinforce-pushed theimport-snapshotResolver-snapshotSerializers branch 2 times, most recently fromd19c3af toddb4eebCompareOctober 30, 2021 08:07
constevaluatedModule=awaitthis.linkAndEvaluateModule(module);

returnevaluatedModuleinstanceofSourceTextModule
?evaluatedModule.namespace.default
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I have no clue what to do here, but I found this method sometimes returnsvm.SourceTextModule as result.

Copy link
Member

Choose a reason for hiding this comment

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

There is no "result" of executing a module. Do we need access to evaluated module? We haven't needed that before... We might need anunstable_importInternalModule which essentially does what you do here (wait forevaluatedModule.status === 'evaluated', then fetch its default export).

Essentially faking animport() call

Copy link
ContributorAuthor

@chentsulinchentsulinNov 3, 2021
edited
Loading

Choose a reason for hiding this comment

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

If i didn't get it wrong, the result is used by thislocalRequire call to support ESM resolvers:

constcustom:SnapshotResolver=awaitlocalRequire(snapshotResolverPath,true,);

).default;
constcustom:SnapshotResolver=awaitlocalRequire(
snapshotResolverPath,
true,
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Add a boolean parameter to localRequire to supportinteropRequireDefault here.

@chentsulinchentsulinforce-pushed theimport-snapshotResolver-snapshotSerializers branch 2 times, most recently fromd65360d tod8033b6CompareOctober 30, 2021 14:18
@chentsulinchentsulinforce-pushed theimport-snapshotResolver-snapshotSerializers branch fromd8033b6 tof7eb057CompareNovember 3, 2021 03:19
@Maxim-Mazurok
Copy link
Contributor

@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!

@SimenB
Copy link
Member

Main issue is that we load the resolverwithin the tests (#12014 (comment)), which means it's pretty much blocked by full ESM support

@Maxim-Mazurok
Copy link
Contributor

Maxim-Mazurok commentedSep 28, 2022
edited
Loading

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

@SimenB
Copy link
Member

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

@Anutrix
Copy link

It's been a year. Any updates?

@github-actions
Copy link

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.

@Anutrix
Copy link

It's been another year. Any updates?

@cpojer
Copy link
Member

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

lin72h reacted with thumbs up emoji

@SimenB
Copy link
Member

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 usehttps://nodejs.org/en/learn/typescript/run-natively

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@SimenBSimenBSimenB left review comments

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@chentsulin@Maxim-Mazurok@SimenB@Anutrix@cpojer@facebook-github-bot

[8]ページ先頭

©2009-2025 Movatter.jp