Skip to content

fix(gatsby): Add script to ensure types files exist when testing #5020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions packages/gatsby/scripts/pretest.ts
Original file line number Diff line number Diff line change
@@ -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();