How to exclude certain files from circleci test globbing?

I want to be able to exclude certain files from the tests globbing when splitting tests.

This CircleCI blog post A guide to test splitting | CircleCI says:

If your setup is different, is an extremely helpful tool to experiment with globbing patterns like brace expansion.

According to that site I should be able to glob with a pattern like this:

`circleci tests glob '**/!(*IntegrationTest).java'`

…and end up with all the .java files that do not end in, however in all cases this command is returning an empty string.

Is this syntax not supported? If not, what’s the recommended way to exclude certain files?

Hi @Ramblurr,

Thanks for reaching out about this, great question!

While that tool referenced is helpful, we unfortunately don’t support all of the features outlined there – including the ability to exclude specific patterns. These are the patterns you can match on.

With the above said, you should be able to use find instead to accomplish what you are looking to do, something like this should work:

find -name '*.java' -not -name '*IntegrationTest*.java' | sed 's/.\///'

You may need to adjust it slightly, but from my testing seemed to accomplish what you need:

circleci@:~/project$ circleci tests glob '**/*.java'
circleci@:~/project$ find -name '*.java' -not -name '*IntegrationTest*.java' | sed 's/.\///'

I hope the above helps!

Hey there, I believe there’s an easier way.

Here’s how we ignore folders/files from the circle ci command line:

TESTFILES=$(circleci tests glob "tests/**/*.test.ts" "tests/**/*.test.js" | sed '/folder\/subfolder/d' | sed '/folder\/file\.ts/d' | circleci tests split --split-by=timings)
            yarn test $TESTFILES --ci --reporters=default --reporters=jest-junit

What do you think?

1 Like