-
Notifications
You must be signed in to change notification settings - Fork 103
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
test: metro-compat resolution tests #524
Conversation
|
Issue raised with metro: facebook/metro#1236 |
@RafikiTiki don't mind the enabled tests failing for now, it's expected without reworking implementation |
* fix: use metro defaults for getResolveOptions * fix: align conditonNames with @react-native/metro-config * fix: use platform extensions only when not using package exports * feat: setup environment for metro tests * refactor: use imported utils * refactor: use ts for non-imported files * refactor: move metro tests to a separate workspace package * chore: remove extra dev deps from repack, update lockfile * chore: remove changes from eslintrc in repack * chore: remove changes in repack package setup * fix: eslint setup * feat: add typing for ResolutionContext * refactor: use utils mock * chore: add enhanced-resolve for types * feat: setup resolve function in tests * chore: add @types/jest to metro-compat * feat: use imported utils module instead of own implementation * refactor: adjust resolve-error impl * feat: pass symlinks tests * feat: add platform-extensions-test * feat: add package-exports tests * fix: don't apply js plugins to ts files * refactor: use package json type from type-fest * refactor: obtain fileMap from createPackageAccessors instead * refactor: use separate fields for fileMaps * feat: add assets & browser-spec tests * refactor: skip assets tests * feat: support more package exports cases * feat: add a list of tests to skip * feat: add index-tests * refactor: cleanup resolve mock * refactor: use babel-jest directly, skip assets & index tests * refactor: cleanup jest setup * refactor: add 2 more tests to skip list * chore: exclude metro-compat from turbo test task * chore: revert changes to getResolveOptions in this PR * chore: cleanup in test script * chore: fix .prettierignore setup * chore: cleanup .eslintrc.js in metro-compat * chore: alter formatting and restore tests from upstream * chore: cleanup & add some utility scripts to metro-compat * fix: align to target getResolveOptions API * chore: rename to metro-compat-test * chore: add README.md for metro-compat-test * chore: update pnpm lockfile * fix: update scripts in root package.json to reflect name change
* fix: use metro defaults for getResolveOptions * fix: align conditonNames with @react-native/metro-config * fix: use platform extensions only when not using package exports * feat: setup environment for metro tests * refactor: use imported utils * refactor: use ts for non-imported files * refactor: move metro tests to a separate workspace package * chore: remove extra dev deps from repack, update lockfile * chore: remove changes from eslintrc in repack * chore: remove changes in repack package setup * fix: eslint setup * feat: add typing for ResolutionContext * refactor: use utils mock * chore: add enhanced-resolve for types * feat: setup resolve function in tests * chore: add @types/jest to metro-compat * feat: use imported utils module instead of own implementation * refactor: adjust resolve-error impl * feat: pass symlinks tests * feat: add platform-extensions-test * feat: add package-exports tests * fix: don't apply js plugins to ts files * refactor: use package json type from type-fest * refactor: obtain fileMap from createPackageAccessors instead * refactor: use separate fields for fileMaps * feat: add assets & browser-spec tests * refactor: skip assets tests * feat: support more package exports cases * feat: add a list of tests to skip * feat: add index-tests * refactor: cleanup resolve mock * refactor: use babel-jest directly, skip assets & index tests * refactor: cleanup jest setup * refactor: add 2 more tests to skip list * chore: exclude metro-compat from turbo test task * chore: revert changes to getResolveOptions in this PR * chore: cleanup in test script * chore: fix .prettierignore setup * chore: cleanup .eslintrc.js in metro-compat * chore: alter formatting and restore tests from upstream * chore: cleanup & add some utility scripts to metro-compat * fix: align to target getResolveOptions API * chore: rename to metro-compat-test * chore: add README.md for metro-compat-test * chore: update pnpm lockfile * fix: update scripts in root package.json to reflect name change
Summary
This PR introduces
metro-compat
package which houses tests suites designed for checking compatibility with parts ofmetro
.Right now, tests include resolver tests directly imported from
metro-resolver
from hereTest environment is modified to accommodate for how
enhanced-resolve
works. Basic principle is this: use unchanged tests and provide compatibleresolve
function for tests. While inmetro-resolver
everything happens via mocked methods for checking whether file exists, our tests create a fresh in-memory filesystem for each test to test resolution against, which yields more ensuring results.Some tests suite are skipped:
assets-test.js
- becauseenhanced-resolve
, like node resolution, returns only a single entry, it's impossible to support these test cases. We handle this differently usingAssetResolver
which provides you with first matching entry for development, but all scales are exposed to the runtimeindex-test.js
- this suite contains some basic tests & failure tests which we could include but most of it contains tests for unsupported features like:resolveRequest
- this is essentially a custom resolver or a plugin, it should be documented how to achieve similar functionality inRe.Pack
redirectModulePath
- this is equal toalias
field inenhanced-resolve
, if end user wants to do this dynamically, then custom resolver/plugin should be used for that - also needs to documenteddisableHierarchicalLookup
- can be achieved inenhanced-resolve
by usingmodules
- also needs to be documentedSome test cases are skipped (all come from
package-exports-test.js
):[nonstrict]
tests are skipped because we don't support fallback in form of legacy file resolutionenhanced-resolve
returns - this could be potentially fixed by trappingtoThrowErrorMatchingInlineSnapshot
calls and checking for existence of errors onlyTests will be excluded from CI for now until everything is aligned properly and some issues are brought up with metro team. Alignment of
getResolveOptions
will be done in a separate PR. Documentation will follow in a separate PR as well.Side-note: this PR also unveiled few issues with package exports implementation in
metro-resolver
which will be investigated more throughly and perhaps become more aligned in the future.Side-note 2: the way we skip tests without modyfing the test files is rather hacky, we trap
jest.describe
,jest.it
&jest.test
and we check if the test name matches, TBD whether there is a better way to do this.Checklist
metro-resolver
test suitemetro-compat