Skip to content

Commit f18a938

Browse files
authored
fix(gatsby): Add script to ensure types files exist when testing (#5020)
This adds a check to the beginning of the gatsby tests which makes sure that the necessary types files exist and creates them before starting the tests if they don't. Note: These files are not the normal files built by `yarn build:types` but additional ones made necessary by the structure gatsby plugins are required to have. See #4928.
1 parent e16a699 commit f18a938

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/gatsby/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
"lint": "run-s lint:prettier lint:eslint",
6060
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
6161
"lint:prettier": "prettier --check \"{src,test,scripts}/**/*.ts\"",
62-
"test": "jest",
63-
"test:watch": "jest --watch"
62+
"test": "yarn ts-node scripts/pretest.ts && yarn jest",
63+
"test:watch": "yarn ts-node scripts/pretest.ts && yarn jest --watch"
6464
},
6565
"volta": {
6666
"extends": "../../package.json"

packages/gatsby/scripts/pretest.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { execSync } from 'child_process';
2+
import * as fs from 'fs';
3+
4+
function ensurePluginTypes(): void {
5+
if (!fs.existsSync('gatsby-browser.d.ts') || !fs.existsSync('gatsby-node.d.ts')) {
6+
// eslint-disable-next-line no-console
7+
console.warn(
8+
'\nWARNING: Missing types for gatsby plugin files. Types will be created before running gatsby tests.',
9+
);
10+
execSync('yarn build:plugin');
11+
}
12+
}
13+
14+
ensurePluginTypes();

0 commit comments

Comments
 (0)