Hari Reddy
Hari Reddy

Reputation: 369

How do I configure playwright-jest to exclude a Test Suite (spec) file for a run?

I have a playwright-jest setup with multiple spec files (test suites). I need to skip one of them, but it needs to stay in the same directory of its repo (moving it is not an option).

The default script under package.json is "test": "jest -c jest.config.js" and I know we may run it with npm run test TestSuiteName.spec.ts for individual suites, and without a file name - npm run test, it runs the entire Test Plan - but - how can I exclude just 1 (or a few) and run the rest of it all?

I have tried to find config flags for it but without luck. What's worked so far is describe.skip() for that particular file, and that's mostly what I could come up so far as a decent workaround. However, I don't want to be making changes to the code before every run.

I was hoping to see if anyone has a better way to do it? Regex maybe? Or perhaps through jest.config with an option flag?

Upvotes: 2

Views: 3818

Answers (1)

Hari Reddy
Hari Reddy

Reputation: 369

Okay, so I found out a regex solution to my problem. It still seems a little less than ideal, but this is better than to add skip() in my opinion.

Apparently jest makes this pretty easy with just an extra argument to be added with the run command. This argument is treated as a regular expression to match against the Test Suite files in the folder structure.

Providing a pattern as a cli argument, is a way for it to pick only the files matching that regex and executing them -

jest "my.*(complex)?pattern"

I had to define a pattern to exclude a string in the file name. Since I wanted to exclude a file with "BVT" text in the file name, adding this to the package.json scripts, worked in my case -

"excludeBVT": "jest \"^((?!BVT).)*$\" -c jest.config.js"

Upvotes: 2

Related Questions