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: createRequire option and disable esm for jest #7476

Merged
merged 18 commits into from
Jun 11, 2020
Merged

feat: createRequire option and disable esm for jest #7476

merged 18 commits into from
Jun 11, 2020

Conversation

clarkdo
Copy link
Member

@clarkdo clarkdo commented Jun 7, 2020

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

esm disabled by default

As esm package has been incompatible since jest 25, this PR disables esm for jest environments by default to prevent regression happening when testing nuxt with jest. You may need to make changes to your project after this PR:

jest config:

    "transform": {
      "^.+\\.js$": "babel-jest"
    },

babel config:

module.exports = function (api) {
  if (api.env('test')) {
    return {
      plugins: ['@babel/plugin-transform-modules-commonjs']
    }
  }
  return {}
}

createRequire option

Meanwhile, we have started working on jiti project for stable esm/typescript runtime support. You can try it by setting createRequire: 'jiti' inside nuxt.config.

Also, it is possible to use this option to keep using esm with jest < 25 or provide a custom factory function. Setting value to false or unsupported value, makes nuxt using native require (via create-require)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

@clarkdo clarkdo requested a review from pi0 June 7, 2020 21:15
@clarkdo clarkdo force-pushed the esm-jest branch 3 times, most recently from 459904a to dea3986 Compare June 7, 2020 21:34
@codecov-commenter
Copy link

codecov-commenter commented Jun 7, 2020

Codecov Report

Merging #7476 into dev will increase coverage by 0.02%.
The diff coverage is 80.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##              dev    #7476      +/-   ##
==========================================
+ Coverage   70.16%   70.18%   +0.02%     
==========================================
  Files          88       88              
  Lines        3717     3733      +16     
  Branches     1008     1015       +7     
==========================================
+ Hits         2608     2620      +12     
- Misses        901      905       +4     
  Partials      208      208              
Flag Coverage Δ
#unittests 70.18% <80.00%> (+0.02%) ⬆️
Impacted Files Coverage Δ
packages/config/src/config/_common.js 100.00% <ø> (ø)
packages/config/src/options.js 95.23% <66.66%> (-1.57%) ⬇️
packages/config/src/load.js 77.90% <100.00%> (+0.79%) ⬆️
packages/core/src/resolver.js 97.36% <100.00%> (+0.03%) ⬆️

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 87f1a8d...0ade4dc. Read the comment docs.

@clarkdo
Copy link
Member Author

clarkdo commented Jun 8, 2020

@pi0 Feel free to merge or close if we're gonna remove esm.

@pi0
Copy link
Member

pi0 commented Jun 8, 2020

@clarkdo PR is good we should remove esm more carefully. I was just thinking to provide an option instead of disabling using jest detection (it is kinda breaking change too) Can make changes in same PR :)

@pi0 pi0 changed the title fix(test): not use esm in jest feat: createRequire option and deprecate esm for jest Jun 10, 2020
packages/config/src/load.js Outdated Show resolved Hide resolved
packages/config/src/load.js Outdated Show resolved Hide resolved
@pi0 pi0 changed the title feat: createRequire option and deprecate esm for jest feat: createRequire option and disable esm for jest Jun 11, 2020
@pi0 pi0 assigned clarkdo and pi0 Jun 11, 2020
@pi0 pi0 merged commit db65c2e into dev Jun 11, 2020
@pi0 pi0 deleted the esm-jest branch June 11, 2020 13:59
@pi0 pi0 mentioned this pull request Jun 12, 2020
@danielroe danielroe added the 2.x label Jan 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants