OpenSourceRaidGuild / babel-vite

babel preset and plugins that emulate Vite's non-standard functionality
MIT License
57 stars 12 forks source link

Add support for eager via the { eager: true } argument to import.meta.glob in Jest #51

Closed vctqs1 closed 8 months ago

vctqs1 commented 8 months ago

What:

Addresses https://github.com/OpenSourceRaidGuild/babel-vite/issues/42, and https://github.com/OpenSourceRaidGuild/babel-vite/pull/43#issuecomment-1869208565

Why: import.meta.globEager is deprecated, use import.meta.glob instead. But the previous method was use import declarative so it's make Jest failure at import * as glob__glob__

image

How: Change import statement to require as the implement stuffs in globEager


const modules = import.meta.globEager("./fixtures/**/*")

      ↓ ↓ ↓ ↓ ↓ ↓

const modules = {
  './fixtures/file1.ts': require('./fixtures/file1.ts'),
  './fixtures/file2.ts': require('./fixtures/file2.ts'),
  './fixtures/file3.ts': require('./fixtures/file3.ts')
}

then result is


const __glob__0_0 = require('./fixtures/file1.ts')
const __glob__0_1 = require('./fixtures/file2.ts')
const __glob__0_2 = require('./fixtures/file3.ts')
const modules = {
  './fixtures/file1.ts': __glob__0_0,
  './fixtures/file2.ts': __glob__0_1,
  './fixtures/file3.ts': __glob__0_2
}

Also tested-well in my own repo, and everything is fine

image

Checklist:

codecov[bot] commented 8 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (010d7e3) 100.00% compared to head (30b618b) 100.00%. Report is 5 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #51 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 4 4 Lines 130 129 -1 Branches 49 49 ========================================= - Hits 130 129 -1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

vctqs1 commented 8 months ago

@mpeyper @JacobMGEvans Hi, I did a fix here, could you two help to review it?

github-actions[bot] commented 8 months ago

:tada: This PR is included in version 1.1.2 :tada:

The release is available on npm package (@latest dist-tag)

Your semantic-release bot :package::rocket:

github-actions[bot] commented 8 months ago

:tada: This PR is included in version 1.1.1 :tada:

The release is available on npm package (@latest dist-tag)

Your semantic-release bot :package::rocket: