From 719dd6534045b14c23868512712f7e57ebc0d059 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Wed, 6 Feb 2019 08:49:00 -0800 Subject: [PATCH] Warn when console.error is used in tests Summary: It's a bit hacky but apparently the recommended solution: https://stackoverflow.com/questions/28615293/is-there-a-jest-config-that-will-fail-tests-on-console-warn This will bail when a call to `console.error` is used in a test. If you *need to* use console.error in a test, then mock it. This will likely not pass yet, but let's fix all failures and then land it. Reviewed By: danielbuechele Differential Revision: D13898383 fbshipit-source-id: 0ca222a07433a9a311dc6bdf0d264342a59208be --- package.json | 5 ++++- static/globalTestSetup.js | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 static/globalTestSetup.js diff --git a/package.json b/package.json index 981d80f1c..4aaa26e5e 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,10 @@ "jest": { "transform": { "\\.(js)$": "/static/transforms/index.js" - } + }, + "setupFiles": [ + "/static/globalTestSetup.js" + ] }, "devDependencies": { "@jest-runner/electron": "^0.1.0", diff --git a/static/globalTestSetup.js b/static/globalTestSetup.js new file mode 100644 index 000000000..ae8a72c84 --- /dev/null +++ b/static/globalTestSetup.js @@ -0,0 +1,14 @@ +/** + * Copyright 2018-present Facebook. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * @format + */ +const defaultConsoleError = console.error; + +console.error = function(message) { + defaultConsoleError( + 'console.error used in a test. This will be an error in the near future.', + ); + defaultConsoleError.apply(console, arguments); +};