Browse Source

ref(dx): Detect bad test runs (#77796)

To avoid confusion detect when people try to run jest directly and hint
for them to use `yarn test` instead of jest directly.
Evan Purkhiser 5 months ago
parent
commit
fe7a2837b9
2 changed files with 10 additions and 0 deletions
  1. 7 0
      jest.config.ts
  2. 3 0
      scripts/test.js

+ 7 - 0
jest.config.ts

@@ -15,8 +15,15 @@ const {
   GITHUB_PR_REF,
   GITHUB_RUN_ID,
   GITHUB_RUN_ATTEMPT,
+  USING_YARN_TEST,
 } = process.env;
 
+if (USING_YARN_TEST === undefined) {
+  // eslint-disable-next-line no-console
+  console.error('Do not run `jest` directly, use `yarn test` instead!');
+  process.exit();
+}
+
 const IS_MASTER_BRANCH = GITHUB_PR_REF === 'refs/heads/master';
 
 const BALANCE_RESULTS_PATH = path.resolve(

+ 3 - 0
scripts/test.js

@@ -6,6 +6,9 @@ process.env.NODE_ENV = 'test';
 process.env.PUBLIC_URL = '';
 process.env.TZ = 'America/New_York';
 
+// Marker to indicate that we've correctly ran with `yarn test`.
+process.env.USING_YARN_TEST = true;
+
 // Makes the script crash on unhandled rejections instead of silently
 // ignoring them. In the future, promise rejections that are not handled will
 // terminate the Node.js process with a non-zero exit code.