Skip to content

Commit

Permalink
minor improvement
Browse files Browse the repository at this point in the history
Summary:
After an investigation of why does jest take up to 15 seconds to start running some tests there isn't a fix for the main issue, but a few improvements, specifically

* ~~Jest now uses swc to compile test code. I initially tried running ts-jest in compile only mode, then to use esbuild as we already use it but it modifies order of imports an puts jest mocks after imports which breaks tests. In the end I settled for swc which worked and got a reasonable improvement. Ideally we would run this agains all tsx files. We can do that once there won't be a need for a transformation of fb-stubs paths.~~
* Disable type checking as a part of test run
* Jest ignores files in /lib/ where we store compiled typescript
* Set max workers to 8. I have tried running tests locally and on devvm with 128 cpus and I found that having 8 workers is optimal. Not sure exactly why but this resulted in faster runs.
* Found a couple tests that leave hanging promises. Marked, not fixed.

As a result the full run went down from ~85s to ~65s on my mac studio measured with warm runs of `TZ=Pacific/Pohnpei node_modules/.bin/jest`

allow-large-files

Reviewed By: lblasa

Differential Revision: D60059552

fbshipit-source-id: 04fbcd03c8626c772c7fd446263c24d0fb3b7c71
  • Loading branch information
antonk52 authored and facebook-github-bot committed Jul 24, 2024
1 parent 8d86110 commit 240ff9d
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 35 deletions.
2 changes: 1 addition & 1 deletion desktop/babel-transformer/jestconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"transform": {
"^.+\\.tsx?$": "ts-jest"
"^.+\\.tsx?$": ["ts-jest", {"isolatedModules": true}]
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testPathIgnorePatterns": ["/node_modules/", "/lib/"],
Expand Down
2 changes: 1 addition & 1 deletion desktop/eslint-plugin-flipper/jestconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"transform": {
"^.+\\.tsx?$": "ts-jest"
"^.+\\.tsx?$": ["ts-jest", {"isolatedModules": true}]
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testPathIgnorePatterns": ["/node_modules/", "/lib/"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ const fakeExistingDevices = [

beforeEach(() => {
fakeSimctlBridge = {
getActiveDevices: jest.fn().mockImplementation(async () => fakeDevices),
getActiveDevices: jest.fn(async () => fakeDevices),
};
fakeIDBBridge = {
getActiveDevices: jest.fn().mockImplementation(async () => fakeDevices),
getActiveDevices: jest.fn(async () => fakeDevices),
};
fakeFlipperServer = {
getDevices: jest.fn().mockImplementation(() => fakeExistingDevices),
getDevices: jest.fn(() => fakeExistingDevices),
registerDevice: jest.fn(),
unregisterDevice: jest.fn(),
};
Expand Down Expand Up @@ -129,6 +129,8 @@ test('test queryDevices when simctl used', async () => {

expect(fakeFlipperServer.unregisterDevice).toBeCalledTimes(1);
expect(fakeFlipperServer.unregisterDevice).toBeCalledWith('plapatine');

// FIXME unregister devices, causes a hanging promise in jest
});

test('test queryDevices when idb used', async () => {
Expand All @@ -152,4 +154,6 @@ test('test queryDevices when idb used', async () => {

expect(fakeFlipperServer.unregisterDevice).toBeCalledTimes(1);
expect(fakeFlipperServer.unregisterDevice).toBeCalledWith('plapatine');

// FIXME unregister devices, causes a hanging promise in jest
});
10 changes: 7 additions & 3 deletions desktop/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,26 @@
* @format
*/

const os = require('os');

/** @type {import('jest').Config} */
module.exports = {
transform: {
'^.*__tests__(/|\\\\).*\\.tsx?$': 'ts-jest',
'^.*__tests?__(/|\\\\).*\\.tsx?$': ['ts-jest', {isolatedModules: true}],
'\\.(js|tsx?)$': '<rootDir>/scripts/jest-transform.js',
},
setupFiles: ['<rootDir>/scripts/jest-setup.tsx'],
setupFilesAfterEnv: ['<rootDir>/scripts/jest-setup-after.tsx'],
moduleNameMapper: {
'^flipper$': '<rootDir>/deprecated-exports/src',
'^flipper-plugin$': '<rootDir>/flipper-plugin/src',
'^flipper-(server-core|ui-core|frontend-core|common)$':
'<rootDir>/flipper-$1/src',
'^flipper-(server|common|ui)$': '<rootDir>/flipper-$1/src',
'^flipper-(pkg|pkg-lib|test-utils)$': '<rootDir>/$1/src',
'^.+\\.(css|scss)$': '<rootDir>/scripts/jest-css-stub.js',
},
modulePathIgnorePatterns: ['<rootDir>/.*/lib/'],
clearMocks: true,
maxWorkers: os.cpus().length > 10 ? 8 : '50%',
coverageReporters: [
'json-summary',
'lcov',
Expand Down
2 changes: 1 addition & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"prettier": "^3.2.2",
"pretty-format": "^29.7.0",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.0",
"ts-jest": "^29.2.3",
"ts-node": "^10.9.1",
"tsx": "^4.15.7",
"typescript": "^5.4.2"
Expand Down
2 changes: 1 addition & 1 deletion desktop/pkg-lib/jestconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"transform": {
"^.+\\.tsx?$": "ts-jest"
"^.+\\.tsx?$": ["ts-jest", {"isolatedModules": true}]
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testPathIgnorePatterns": ["/node_modules/", "/lib/"],
Expand Down
2 changes: 1 addition & 1 deletion desktop/pkg/jest.config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"transform": {
"^.+\\.tsx?$": "ts-jest"
"^.+\\.tsx?$": ["ts-jest", {"isolatedModules": true}]
},
"testEnvironment": "node",
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
Expand Down
2 changes: 1 addition & 1 deletion desktop/plugin-lib/jestconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"transform": {
"^.+\\.tsx?$": "ts-jest"
"^.+\\.tsx?$": ["ts-jest", {"isolatedModules": true}]
},
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"testPathIgnorePatterns": ["/node_modules/", "/lib/"],
Expand Down
2 changes: 1 addition & 1 deletion desktop/scripts/jest-setup-after.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Object.defineProperty(global, 'performance', {
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
Object.defineProperty(global, 'matchMedia', {
writable: true,
value: jest.fn().mockImplementation((query) => ({
value: jest.fn((query) => ({
matches: false,
media: query,
onchange: null,
Expand Down
57 changes: 35 additions & 22 deletions desktop/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5895,6 +5895,13 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

ejs@^3.1.10:
version "3.1.10"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.10.tgz#69ab8358b14e896f80cc39e62087b88500c3ac3b"
integrity sha512-UeJmFfOrAQS8OJWPZ4qtgHyWExa088/MtK5UEyoJGFH67cDEXkZSviOiKRCZ4Xij0zxI3JECgYs3oKx+AizQBA==
dependencies:
jake "^10.8.5"

ejs@^3.1.6:
version "3.1.7"
resolved "https://registry.yarnpkg.com/ejs/-/ejs-3.1.7.tgz#c544d9c7f715783dd92f0bddcf73a59e6962d006"
Expand Down Expand Up @@ -8639,24 +8646,24 @@ jest-util@^27.5.1:
graceful-fs "^4.2.9"
picomatch "^2.2.3"

jest-util@^29.0.0, jest-util@^29.5.0:
version "29.5.0"
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.5.0.tgz#24a4d3d92fc39ce90425311b23c27a6e0ef16b8f"
integrity sha512-RYMgG/MTadOr5t8KdhejfvUU82MxsCu5MF6KuDUHl+NuwzUt+Sm6jJWxTJVrDR1j5M/gJVCPKQEpWXY+yIQ6lQ==
jest-util@^29.0.0, jest-util@^29.7.0:
version "29.7.0"
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.7.0.tgz#23c2b62bfb22be82b44de98055802ff3710fc0bc"
integrity sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==
dependencies:
"@jest/types" "^29.5.0"
"@jest/types" "^29.6.3"
"@types/node" "*"
chalk "^4.0.0"
ci-info "^3.2.0"
graceful-fs "^4.2.9"
picomatch "^2.2.3"

jest-util@^29.7.0:
version "29.7.0"
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.7.0.tgz#23c2b62bfb22be82b44de98055802ff3710fc0bc"
integrity sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==
jest-util@^29.5.0:
version "29.5.0"
resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-29.5.0.tgz#24a4d3d92fc39ce90425311b23c27a6e0ef16b8f"
integrity sha512-RYMgG/MTadOr5t8KdhejfvUU82MxsCu5MF6KuDUHl+NuwzUt+Sm6jJWxTJVrDR1j5M/gJVCPKQEpWXY+yIQ6lQ==
dependencies:
"@jest/types" "^29.6.3"
"@jest/types" "^29.5.0"
"@types/node" "*"
chalk "^4.0.0"
ci-info "^3.2.0"
Expand Down Expand Up @@ -11814,13 +11821,6 @@ seek-bzip@^1.0.5:
dependencies:
commander "~2.8.1"

[email protected], semver@^7.3.2, semver@^7.3.5, semver@^7.3.7:
version "7.3.8"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798"
integrity sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==
dependencies:
lru-cache "^6.0.0"

semver@^5.5.0, semver@^5.5.1, semver@^5.6.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
Expand All @@ -11836,6 +11836,18 @@ semver@^6.3.1:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

semver@^7.3.2, semver@^7.3.5, semver@^7.3.7:
version "7.3.8"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798"
integrity sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==
dependencies:
lru-cache "^6.0.0"

semver@^7.5.3:
version "7.6.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==

semver@^7.5.4:
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
Expand Down Expand Up @@ -12651,18 +12663,19 @@ ts-easing@^0.2.0:
resolved "https://registry.yarnpkg.com/ts-easing/-/ts-easing-0.2.0.tgz#c8a8a35025105566588d87dbda05dd7fbfa5a4ec"
integrity sha512-Z86EW+fFFh/IFB1fqQ3/+7Zpf9t2ebOAxNI/V6Wo7r5gqiqtxmgTlQ1qbqQcjLKYeSHPTsEmvlJUDg/EuL0uHQ==

ts-jest@^29.1.0:
version "29.1.0"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.0.tgz#4a9db4104a49b76d2b368ea775b6c9535c603891"
integrity sha512-ZhNr7Z4PcYa+JjMl62ir+zPiNJfXJN6E8hSLnaUKhOgqcn8vb3e537cpkd0FuAfRK3sR1LSqM1MOhliXNgOFPA==
ts-jest@^29.2.3:
version "29.2.3"
resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.2.3.tgz#3d226ac36b8b820151a38f164414f9f6b412131f"
integrity sha512-yCcfVdiBFngVz9/keHin9EnsrQtQtEu3nRykNy9RVp+FiPFFbPJ3Sg6Qg4+TkmH0vMP5qsTKgXSsk80HRwvdgQ==
dependencies:
bs-logger "0.x"
ejs "^3.1.10"
fast-json-stable-stringify "2.x"
jest-util "^29.0.0"
json5 "^2.2.3"
lodash.memoize "4.x"
make-error "1.x"
semver "7.x"
semver "^7.5.3"
yargs-parser "^21.0.1"

ts-node@^10.9.1:
Expand Down

0 comments on commit 240ff9d

Please sign in to comment.