What is the proper way to escape quotes and slashes when running a Jest test with --collectCoverageFrom from Powershell via npm scripts?
Update as of Powershell version 7.2.1:
The triple-backslash doesn't seem to be necessary anymore; the syntax in this answer's previous version is no longer working for me. But the following works:
npm t "--" ExampleComponent --collectCoverageFrom="'[\""**/ExampleComponent.tsx\""]'"
Jest echoes back the same as before as mentioned below with this syntax.
Previous version:
I have found a version that works:
npm t "--" ExampleComponent --collectCoverageFrom="'[\\\""**/ExampleComponent.tsx\\\""]'"
The command seems to be running as expected, calculating coverage for the specified file only.
Jest echoes back the command as:
jest "ExampleComponent" "--collectCoverageFrom='[\"**/ExampleComponent.tsx\"]'"
The processed version has backslashes before the double-quotes since the entire argument is already wrapped in double-quotes. I also had to change the backslash back to a forward slash.
Thanks to @mklement0 for his input in the question's comments.