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(jest-config): add support for preset written in ESM #11200

Merged
merged 1 commit into from
Mar 15, 2021
Merged

feat(jest-config): add support for preset written in ESM #11200

merged 1 commit into from
Mar 15, 2021

Conversation

ahnpnl
Copy link
Contributor

@ahnpnl ahnpnl commented Mar 14, 2021

Summary

Related to #11167

  • Add .cjs, .mjs to the supported extensions for preset as well as logic to load them, with .mjs for ESM preset and .cjs for CommonJS preset
  • Clean up some unused mocks in normalize.test.ts as well as fix some ts type errors.

Test plan

Added unit tests for happy path
Added e2e tests

@ahnpnl
Copy link
Contributor Author

ahnpnl commented Mar 14, 2021

I could only make unit test for happy path. I couldn't make unit test for validating these cases

  • Throw error if.mjs preset contains module.exports
// jest-preset.mjs
module.exports = {
}
  • Throw error if .js preset containsexport default
// jest-preset.js
export default {
}

@codecov-io
Copy link

Codecov Report

Merging #11200 (00ffa95) into master (33c3b07) will decrease coverage by 0.02%.
The diff coverage is 30.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11200      +/-   ##
==========================================
- Coverage   64.29%   64.26%   -0.03%     
==========================================
  Files         308      308              
  Lines       13484    13490       +6     
  Branches     3287     3288       +1     
==========================================
+ Hits         8669     8670       +1     
- Misses       4106     4111       +5     
  Partials      709      709              
Impacted Files Coverage Δ
packages/jest-config/src/normalize.ts 76.74% <30.00%> (-1.21%) ⬇️
packages/jest-config/src/utils.ts 77.58% <0.00%> (+1.72%) ⬆️

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 33c3b07...00ffa95. Read the comment docs.

docs/Configuration.md Outdated Show resolved Hide resolved
@SimenB
Copy link
Member

SimenB commented Mar 15, 2021

  • Throw error if .js preset containsexport default

that's valid if package.json has type: 'module'

@ahnpnl
Copy link
Contributor Author

ahnpnl commented Mar 15, 2021

  • Throw error if .js preset containsexport default

that's valid if package.json has type: 'module'

Thanks !, I've added this case to e2e, not sure how to make it with unit tests.

docs/Configuration.md Outdated Show resolved Hide resolved
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!

e2e/__tests__/presets.test.ts Outdated Show resolved Hide resolved
e2e/__tests__/presets.test.ts Outdated Show resolved Hide resolved
@ahnpnl ahnpnl marked this pull request as ready for review March 15, 2021 13:16
@SimenB SimenB merged commit 75e94cc into jestjs:master Mar 15, 2021
@ahnpnl ahnpnl deleted the preset-esm branch March 15, 2021 14:10
@SimenB
Copy link
Member

SimenB commented Mar 25, 2021

@ahnpnl running yarn clean-all will delete the stuff from node_modules added for the tests here. Would you be able to take a look? 🙂

@ahnpnl
Copy link
Contributor Author

ahnpnl commented Mar 25, 2021

Sure!

@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 10, 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