Jest does not run tests with brackets in filename when using parallelism

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!

:wave: Hi @pjaws,

Your sed substitution patterns are definitely valid.

Could you try breaking down the command into smaller ones, so we can check the output at each stage:

circleci tests glob "src/**/*.spec.js" > tests_list.txt
cat tests_list.txt

SPLIT_LIST=$(circleci tests split --split-by=timings tests_list.txt)

TESTS_TO_RUN=$(echo $SPLIT_LIST | sed "s/\[/\\\[/g" | sed "s/\]/\\\]/g")