/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
test/unit/scripts/resolver.js
57 строк
2 KB
Marco Ciampini
Jest: Update to v30 (breaking) (#80767)
28 июл 2026, 18:32
Не верифицирован
28 июл 2026, 18:32
0af03a5
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. const nodePath = require( 'node:path' ); module.exports = ( request, options ) => { // Jest 30's resolver enforces package exports before applying packageFilter. // Resolve workspace source imports explicitly so unit-test mocks keep using source files. const sourceImport = request.match( /^@wordpress\/([^/]+)\/src\/(.+)$/ ); if ( sourceImport ) { const [ , packageName, sourcePath ] = sourceImport; return options.defaultResolver( nodePath.join( options.rootDir, 'packages', packageName, 'src', sourcePath ), options ); } // Call the defaultResolver, so we leverage its cache, error handling, etc. return options.defaultResolver( request, { ...options, // Use packageFilter to process parsed `package.json` before the resolution (see https://www.npmjs.com/package/resolve#resolveid-opts-cb) packageFilter: ( pkg ) => { /* * jest-environment-jsdom 28+ tries to use browser exports instead * of default exports for these packages. Stripping the exports * map forces Jest to fall back to the CommonJS `main` entry. * * `uuid` is matched here to handle nested v8 copies (e.g. * `@actions/core`'s) that still ship a CJS `main`. uuid v14 is * ESM-only with no `main`, so the `pkg.main` guard below skips it * and lets Babel transform the ESM build via * `transformIgnorePatterns`. */ if ( pkg.name === 'uuid' || pkg.name === 'react-colorful' || pkg.name === 'expect' || pkg.name === 'nanoid' || pkg.name?.startsWith( '@wordpress/' ) ) { if ( pkg.main ) { delete pkg.exports; delete pkg.module; } } return pkg; }, } ); };