From 5db782082074ef858534be9a0ab0094c3e7a5fee Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Thu, 30 Apr 2020 06:30:04 -0700 Subject: [PATCH] Add support for Jest runner Summary: This diff adds compatibility with https://marketplace.visualstudio.com/items?itemName=Orta.vscode-jest and makes sure the `yarn jest` command works without further arguments by defaulting to the unit test setup. This makes tests runnable from VSCode, highlights which tests passed, and show errors inline (and coverage as well if desired), and will report failing tests in the problems panel. {F235815220} The debugger can be started right from the code pane as well by clicking the tiny 'debug' {F235815208} Currently set up the defaults to not start tests after startup, as it can be CPU hogging, so simply run the command CMD+SHIFT+P 'start jest runner' instead. Reviewed By: passy Differential Revision: D21325241 fbshipit-source-id: 7b87297a710a18bbac394110dc2006218ccc7d86 --- .vscode/settings.json | 7 ++++++- desktop/.vscode/settings.json | 7 ++++++- desktop/jest.config.js | 26 ++++++++++++++++++++++++++ desktop/package.json | 30 +++++------------------------- 4 files changed, 43 insertions(+), 27 deletions(-) create mode 100644 desktop/jest.config.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 511ad9e5f..8bb3f1673 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,5 +26,10 @@ }, "[javascriptreact]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" - } + }, + "jest.autoEnable": false, + "jest.enableInlineErrorMessages": true, + "jest.runAllTestsFirst": false, + "jest.pathToConfig": "desktop/jest.config.js", + "jest.pathToJest": "desktop/node_modules/.bin/jest" } diff --git a/desktop/.vscode/settings.json b/desktop/.vscode/settings.json index 511ad9e5f..8c1cc5e03 100644 --- a/desktop/.vscode/settings.json +++ b/desktop/.vscode/settings.json @@ -26,5 +26,10 @@ }, "[javascriptreact]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" - } + }, + "jest.autoEnable": false, + "jest.enableInlineErrorMessages": true, + "jest.runAllTestsFirst": false, + "jest.pathToConfig": "jest.config.js", + "jest.pathToJest": "node_modules/.bin/jest" } diff --git a/desktop/jest.config.js b/desktop/jest.config.js new file mode 100644 index 000000000..1f5d2bafd --- /dev/null +++ b/desktop/jest.config.js @@ -0,0 +1,26 @@ +/** + * 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 = { + transform: { + '^.*__tests__/.*\\.tsx?$': 'ts-jest', + '\\.(js|tsx?)$': '/scripts/jest-transform.js', + }, + setupFiles: ['/scripts/jest-setup.js'], + moduleNameMapper: { + '^flipper$': '/app/src', + '^flipper-doctor$': '/doctor/src', + '^flipper-pkg$': '/pkg/src', + '^flipper-pkg-lib$': '/pkg-lib/src', + }, + clearMocks: true, + coverageReporters: ['json-summary', 'lcov', 'html'], + testMatch: ['**/**.node.(js|jsx|ts|tsx)'], + testEnvironment: 'jest-environment-jsdom-sixteen', +}; diff --git a/desktop/package.json b/desktop/package.json index 47cec159b..bbffa96f8 100644 --- a/desktop/package.json +++ b/desktop/package.json @@ -91,27 +91,6 @@ "ws": "7.2.3", "kind-of": "6.0.3" }, - "jest": { - "transform": { - "^.*__tests__/.*\\.tsx?$": "ts-jest", - "\\.(js|tsx?)$": "/scripts/jest-transform.js" - }, - "setupFiles": [ - "/scripts/jest-setup.js" - ], - "moduleNameMapper": { - "^flipper$": "/app/src", - "^flipper-doctor$": "/doctor/src", - "^flipper-pkg$": "/pkg/src", - "^flipper-pkg-lib$": "/pkg-lib/src" - }, - "clearMocks": true, - "coverageReporters": [ - "json-summary", - "lcov", - "html" - ] - }, "devDependencies": { "@babel/code-frame": "^7.8.3", "@jest-runner/electron": "^2.0.2", @@ -241,10 +220,11 @@ "build-headless": "cross-env NODE_ENV=production ./ts-node scripts/build-headless.ts $@", "open-dist": "open ../dist/mac/Flipper.app --args --launcher=false --inspect=9229", "fix": "eslint . --fix --ext .js,.ts,.tsx", - "test": "yarn build:pkg && jest --env=jest-environment-jsdom-sixteen --testPathPattern=\"node\\.(js|ts|tsx)$\" --no-cache", - "test:debug": "yarn build:pkg && node --inspect node_modules/.bin/jest --runInBand --env=jest-environment-jsdom-sixteen", - "test-electron": "yarn build:pkg && jest --env=jest-environment-jsdom-sixteen --testPathPattern=\"electron\\.(js|ts|tsx)$\" --testEnvironment=@jest-runner/electron/environment --runner=@jest-runner/electron --no-cache", - "test-with-device": "yarn build:pkg && USE_ELECTRON_STUBS=1 jest --env=jest-environment-jsdom-sixteen --testPathPattern=\"device\\.(js|ts|tsx)$\" --detectOpenHandles --no-cache", + "pretest": "yarn build:pkg", + "test": "jest", + "test:debug": "yarn build:pkg && node --inspect node_modules/.bin/jest --runInBand", + "test-electron": "yarn build:pkg && jest --testMatch=\"**/**.electron\\.(js|jsx|ts|tsx)\" --testEnvironment=@jest-runner/electron/environment --runner=@jest-runner/electron", + "test-with-device": "yarn build:pkg && USE_ELECTRON_STUBS=1 jest --testMatch=\"**/**.device\\.(js|jsx|ts|tsx)\" --detectOpenHandles", "test-e2e": "cd e2e && yarn test", "lint:tsc": "tsc --noemit", "lint:eslint": "eslint . --ext .js,.ts,.tsx",