-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat(snapshot): support snapshotResolver and snapshotSerializers written in ESM #12014
base: main
Are you sure you want to change the base?
feat(snapshot): support snapshotResolver and snapshotSerializers written in ESM #12014
Conversation
f8aa171
to
2cab732
Compare
it('defining tests and hooks asynchronously throws', () => { | ||
const result = runJest('circus-declaration-errors', [ | ||
it('defining tests and hooks asynchronously throws', async () => { | ||
const result = await runJest('circus-declaration-errors', [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This runJest
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 put runtime.requireModule
into a async function.
From:
const esm = runtime.unstable_shouldLoadAsEsm(testPath);
if (esm) {
await runtime.unstable_importModule(testPath);
} else {
runtime.requireModule(testPath);
}
To:
const localRequire = async <T = unknown>(path: string): Promise<T> => {
const esm = runtime.unstable_shouldLoadAsEsm(path);
if (esm) {
return runtime.unstable_importModule(path) as any;
} else {
return runtime.requireModule(path);
}
};
await localRequire(testPath);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
runJest
spawns jest
in a shell, so it should not be affected by any internal changes in Jest
933e7ca
to
b961505
Compare
d19c3af
to
ddb4eeb
Compare
const evaluatedModule = await this.linkAndEvaluateModule(module); | ||
|
||
return evaluatedModule instanceof SourceTextModule | ||
? evaluatedModule.namespace.default |
There was a problem hiding this comment.
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 returns vm.SourceTextModule
as result.
There was a problem hiding this comment.
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 an unstable_importInternalModule
which essentially does what you do here (wait for evaluatedModule.status === 'evaluated'
, then fetch its default export).
Essentially faking an import()
call
There was a problem hiding this comment.
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 this localRequire
call to support ESM resolvers:
const custom: SnapshotResolver = await localRequire(
snapshotResolverPath,
true,
);
).default; | ||
const custom: SnapshotResolver = await localRequire( | ||
snapshotResolverPath, | ||
true, |
There was a problem hiding this comment.
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 support interopRequireDefault
here.
d65360d
to
d8033b6
Compare
d8033b6
to
f7eb057
Compare
@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! |
Main issue is that we load the resolver within the tests (#12014 (comment)), which means it's pretty much blocked by full ESM support |
Ah, I see, thank you for the update, we are re-considering our approach now. Cheers! |
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 |
It's been a year. Any updates? |
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. |
It's been another year. Any updates? |
Summary
Part of #11167.
See the discussion on the
snapshotResolver
andsnapshotSerializers
config: #11167 (comment) #11167 (comment)Test plan
Integration test added.