Configure jest to automatically pick changes in typescript modules without need to compile them using tsc
Summary: Right now, if you are changing something in one of the modules, e.g. in "flipper-plugin", you'll need to compile the changed module using `tsc` before running tests, otherwise `jest` won't pick up the changes. `yarn test` has a step to run `tsc` before tests, however when tests are started simply by `jest` command, e.g. by VSCode plugin, then `tsc` is not automatically called before tests. This diff makes things easier by configuring `jest` to automatically transpile imported modules. This means simply running `jest` command will automatically pick up and automatically transpile all the changes. Reviewed By: passy Differential Revision: D28310318 fbshipit-source-id: 77e9b91daa59a46ce64b1b70eb9a998d7b72de00
This commit is contained in:
committed by
Facebook GitHub Bot
parent
28fd8da615
commit
32f276b499
@@ -22,4 +22,5 @@ module.exports = {
|
||||
coverageReporters: ['json-summary', 'lcov', 'html'],
|
||||
testMatch: ['**/**.(node|spec).(js|jsx|ts|tsx)'],
|
||||
testEnvironment: 'jest-environment-jsdom-sixteen',
|
||||
resolver: '<rootDir>/jest.resolver.js',
|
||||
};
|
||||
|
||||
23
desktop/jest.resolver.js
Normal file
23
desktop/jest.resolver.js
Normal file
@@ -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,
|
||||
};
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user