diff --git a/desktop/jest.config.js b/desktop/jest.config.js index da53db036..9cfd95007 100644 --- a/desktop/jest.config.js +++ b/desktop/jest.config.js @@ -22,4 +22,5 @@ module.exports = { coverageReporters: ['json-summary', 'lcov', 'html'], testMatch: ['**/**.(node|spec).(js|jsx|ts|tsx)'], testEnvironment: 'jest-environment-jsdom-sixteen', + resolver: '/jest.resolver.js', }; diff --git a/desktop/jest.resolver.js b/desktop/jest.resolver.js new file mode 100644 index 000000000..998b5481f --- /dev/null +++ b/desktop/jest.resolver.js @@ -0,0 +1,23 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ + +module.exports = (request, 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) => { + return { + ...pkg, + // Alter the value of `main` before resolving the package, so jest to try different entry points in the specified order. + main: pkg.flipperBundlerEntry || pkg.main, + }; + }, + }); +};