Open BenWoodworth opened 2 years ago
This is what I'm going with for now (instead of a regex) after finding how you get the groups with jest-docblock:
import * as fs from "fs";
import * as docblock from "jest-docblock";
// Based on https://github.com/eugene-manuilov/jest-runner-groups/blob/3c9d3cf4cb3e595bdea733100f2bdc8d64f871d7/index.js#L36-L51
function getJestRunnerGroups(file: string): Array<string> {
const parsed = docblock.parse(fs.readFileSync(file, "utf8"));
if (!parsed.group) return [];
const groups = Array.isArray(parsed.group) ? parsed.group : [parsed.group];
return groups.filter((group) => typeof group === 'string')
}
@BenWoodworth may I ask what groups you use?
I'm just curious because at the moment I'm defining the testing setup for a large project and I'm torn between multiple jest config files (own config for each group) and this jest-runner-groups package.
Since I only consider one group per file (xxxx.unit.test.ts
for unit tests and xxxx.component.test.ts
for component tests) I tend to rather use multiple configs with different filename regex. However I'm wondering if I oversee some benefits of defining multiple groups per file.
Is there a way to list all the test files that don't have a runner
@group
? My team wants to add a git hook that makes sure every test in our project has at least one group (in case we forget to add a group to a new test file, since we want each to have at least one).Right now I've got a script using
jest --listTests
to list the test files, and regex parsing each for/*...@group XXX...*/
at the top of the file. If there's a better way I'd love to know! :)