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();