Skip to content

Instantly share code, notes, and snippets.

@austinamorusoyardstick
Created July 1, 2025 19:13
Show Gist options
  • Select an option

  • Save austinamorusoyardstick/12d19c8c952ac5ec28fbc44b5fa592c9 to your computer and use it in GitHub Desktop.

Select an option

Save austinamorusoyardstick/12d19c8c952ac5ec28fbc44b5fa592c9 to your computer and use it in GitHub Desktop.
Webstorm Jest 30 testPathPattern to testPathPatterns patch

Files:

  • scripts/jest-cli/bin/jest.js
  • scripts/jest-cli/package.json

Webstorm Run Configuration:

Jest Package:

  • scripts/jest-cli/bin/jest.js
#!/usr/bin/env node
const { spawn } = require('child_process');
/**
* This script acts as a wrapper for the Jest CLI.
* Its primary purpose is to map the deprecated `--testPathPattern` argument,
* often used by older tools or IDEs, to the modern `--testPathPatterns` argument.
*
* It passes all other arguments and environment variables through to Jest untouched.
*/
// 1. Get all command-line arguments passed to this script, excluding 'node' and the script path.
const originalArgs = process.argv.slice(2);
// 2. Map the arguments, replacing the deprecated pattern with the new one.
// This handles both `--testPathPattern <value>` and `--testPathPattern=<value>`.
const mappedArgs = originalArgs.map((arg) => {
if (arg.startsWith('--testPathPattern=')) {
return arg.replace('--testPathPattern=', '--testPathPatterns=');
}
if (arg === '--testPathPattern') {
return '--testPathPatterns';
}
return arg;
});
try {
// 3. Execute the actual 'jest' command with the modified arguments.
// 'spawn' is used to create a new process.
const jestProcess = spawn('node_modules/jest/bin/jest.js', mappedArgs, {
// The 'env' is inherited from the current process by default, but being
// explicit ensures all environment variables are passed through.
env: process.env,
// This ensures that the output (stdout, stderr) and input (stdin) of the
// Jest process are connected to the terminal, making it fully interactive.
// This is crucial for colors, progress bars, and watch mode.
stdio: 'inherit',
});
// 4. Listen for the Jest process to exit. When it does, exit this
// wrapper script with the same exit code. This is vital for CI/CD pipelines.
jestProcess.on('close', (code) => {
process.exit(code);
});
// 5. Handle errors that might occur when trying to spawn the process,
// such as if the 'jest' command is not found in the system's PATH.
jestProcess.on('error', (err) => {
console.error('Failed to start the Jest process:', err);
process.exit(1);
});
} catch (error) {
console.error('An error occurred within the Jest wrapper script:', error);
process.exit(1);
}
{
"name": "jest-thirty-webstorm-patch",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": ""
}
<component name="ProjectRunConfigurationManager">
<configuration default="true" type="JavaScriptTestRunnerJest">
<config-file value="$PROJECT_DIR$/config/jest/jest.config.js" />
<node-interpreter value="project" />
<node-options value="--no-deprecation" />
<jest-package value="$PROJECT_DIR$/scripts/jest-cli" />
<jest-options value="--watch" />
<scope-kind value="ALL" />
<method v="2" />
</configuration>
</component>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment