From cd1823b8ba9d619599d5023a05c70ebcccc1fbf2 Mon Sep 17 00:00:00 2001 From: Katie Byers Date: Fri, 29 Apr 2022 13:17:07 -0700 Subject: [PATCH] add script to ensure types files exist --- packages/gatsby/package.json | 4 ++-- packages/gatsby/scripts/pretest.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 packages/gatsby/scripts/pretest.ts diff --git a/packages/gatsby/package.json b/packages/gatsby/package.json index 5fc7e5e08402..8b02e542af23 100644 --- a/packages/gatsby/package.json +++ b/packages/gatsby/package.json @@ -59,8 +59,8 @@ "lint": "run-s lint:prettier lint:eslint", "lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish", "lint:prettier": "prettier --check \"{src,test,scripts}/**/*.ts\"", - "test": "jest", - "test:watch": "jest --watch" + "test": "yarn ts-node scripts/pretest.ts && yarn jest", + "test:watch": "yarn ts-node scripts/pretest.ts && yarn jest --watch" }, "volta": { "extends": "../../package.json" diff --git a/packages/gatsby/scripts/pretest.ts b/packages/gatsby/scripts/pretest.ts new file mode 100644 index 000000000000..834301f7c38a --- /dev/null +++ b/packages/gatsby/scripts/pretest.ts @@ -0,0 +1,14 @@ +import { execSync } from 'child_process'; +import * as fs from 'fs'; + +function ensurePluginTypes(): void { + if (!fs.existsSync('gatsby-browser.d.ts') || !fs.existsSync('gatsby-node.d.ts')) { + // eslint-disable-next-line no-console + console.warn( + '\nWARNING: Missing types for gatsby plugin files. Types will be created before running gatsby tests.', + ); + execSync('yarn build:plugin'); + } +} + +ensurePluginTypes();