Many of our test files have brackets in the filename, since they correspond to pages using dynamic routes in Next.js, i.e. “/blog/articles/[slug].spec.js”.
This is not an issue when running tests normally; however, when splitting tests with CircleCI’s parallelism feature, those tests fail to run. This is because the filenames are passed through to Jest with the brackets unescaped.
I’ve tried using string replacement on the env var I’m passing to the Jest command, but it does not seem to be working:
command: | TESTFILES=$(circleci tests glob "src/**/*.spec.js" | circleci tests split --split-by=timings | sed "s/\[/\\\[/g" | sed "s/\]/\\\]/g") npm run test:ci $TESTFILES
The string replacement just isn’t happening for some reason, so Jest is still being passed the unescaped filenames. I’m really at a loss for how to get this to work, and any help is appreciated!