Skip to content
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: support config files exporting (async) functions #10001

Merged
merged 4 commits into from
May 9, 2020

Conversation

hisco
Copy link
Contributor

@hisco hisco commented May 7, 2020

Summary

Original #8357 was too old, created this PR to start fresh.
At that time jest cli required the dynamic config module synchronously, that PR enabled loading jest config module async.
It appears that the code in master already have these or similar changes that allows async loading.
All that is missing is documentation

Test plan

No tests needed as all of the changes are already in master, only changed docs

@SimenB
Copy link
Member

SimenB commented May 7, 2020

We wait for the import, we don't invoke the function provided and wait for it to complete.

This is the implementation for the feature:

diff --git i/packages/jest-config/src/index.ts w/packages/jest-config/src/index.ts
index 68d6b5ddf5..de88d4423c 100644
--- i/packages/jest-config/src/index.ts
+++ w/packages/jest-config/src/index.ts
@@ -41,7 +41,9 @@ export async function readConfig(
   parentConfigPath?: Config.Path | null,
   projectIndex: number = Infinity,
 ): Promise<ReadConfig> {
-  let rawOptions;
+  let rawOptions:
+    | Config.InitialOptions
+    | (() => Config.InitialOptions | Promise<Config.InitialOptions>);
   let configPath = null;
 
   if (typeof packageRootOrConfig !== 'string') {
@@ -82,6 +84,10 @@ export async function readConfig(
     rawOptions = await readConfigFileAndSetRootDir(configPath);
   }
 
+  if (typeof rawOptions === 'function') {
+    rawOptions = await rawOptions();
+  }
+
   const {options, hasDeprecationWarnings} = normalize(
     rawOptions,
     argv,

In addition to that we'll need a test. Wanna give it a go? 🙂

@codecov-io
Copy link

Codecov Report

Merging #10001 into master will increase coverage by 0.22%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10001      +/-   ##
==========================================
+ Coverage   63.92%   64.15%   +0.22%     
==========================================
  Files         293      293              
  Lines       12496    12498       +2     
  Branches     3083     3084       +1     
==========================================
+ Hits         7988     8018      +30     
+ Misses       3863     3830      -33     
- Partials      645      650       +5     
Impacted Files Coverage Δ
packages/jest-config/src/index.ts 53.52% <50.00%> (+41.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0a4e4a1...96b1c85. Read the comment docs.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Thanks! Can you update the changelog as well?

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

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

Thanks!

@SimenB SimenB changed the title Updated doc to support async config load feat: support config files exporting (async) functions May 9, 2020
@SimenB SimenB merged commit 8294bab into jestjs:master May 9, 2020
jeysal added a commit to jeysal/jest that referenced this pull request May 25, 2020
…esolve-outside

* upstream/master: (106 commits)
  docs: fix jest-diff example (jestjs#10067)
  Cleanup `displayName` type (jestjs#10049)
  docs: correct confusing filename in `enableAutomock` example (jestjs#10055)
  chore: minor optimize getTransformer (jestjs#10050)
  chore: fix TestUtils.ts to match the types (jestjs#10034)
  Minor test name typo fix (jestjs#10033)
  chore: upgrade to typescript 3.9 (jestjs#10031)
  feat: CLI argument to filter tests by projects (jestjs#8612)
  chore: bump `istanbul-lib-instrument` (jestjs#10009)
  feat: support config files exporting (`async`) `function`s (jestjs#10001)
  fix: add missing haste-map dep to jest-snapshot (jestjs#10008)
  🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉 (jestjs#10000)
  Fix typo in dependency warning (jestjs#10006)
  chore: add missing comma (jestjs#9999)
  fix: Control no diff message color with diff options (jestjs#9997)
  fix(jest-jasmine2): fix Error message (jestjs#9990)
  docs: fix jest-object ids for docusaurs (jestjs#9994)
  docs: fix Configuration, JestPlatform and JestObjectAPI docs for 26 (jestjs#9985)
  Add migration notes for breaking changes (jestjs#9978)
  chore: fix date and heading in blog post (jestjs#9977)
  ...
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants