The project I'm working on has an npm script which runs Jest unit tests. It was written on a Mac, and I'm trying to make it cross-platform. The script looks like this:
"node --harmony node_modules/.bin/jest src/spec/ut"
The first thing I fixed is that the Jest binary doesn't run on Windows, so I changed it to this:
"node --harmony node_modules/jest/bin/jest.js src/spec/ut"
Now at least Jest runs, but it doesn't like the src/spec/ut part, which is the testPathPattern - i.e. telling it only to run tests which are within src/spec/ut
Most node commands on Windows seem happy with *nix-style directory separators, but this one doesn't, because the testPathPattern is treated as a regex, and / is not the same thing as \.
After some experimentation, I discovered that the Windows equivalent of the above is as follows:
"node --harmony node_modules/jest/bin/jest.js src\\\\\\\\\\\\\\\\spec\\\\\\\\\\\\\\\\ut"
(To save you counting, that's sixteen backslashes. I know.)
SO I ought to be able to make it cross-platform by doing something like:
"node --harmony node_modules/jest/bin/jest.js src(\\\\\\\\\\\\\\\\|/)spec(\\\\\\\\\\\\\\\\|/)ut"
(Although I just tried and... that doesn't parse as json)
But I'm trying to write JavaScript here, not Perl. And I can't help thinking that there must be a saner way of doing this.
Can anyone suggest a saner way of doing this?