eugene-manuilov / jest-runner-groups Goto Github PK
View Code? Open in Web Editor NEWA custom runner that allows to tag test files and run groups of tests with Jest.
License: MIT License
A custom runner that allows to tag test files and run groups of tests with Jest.
License: MIT License
Running NODE_ENV=test jest --group utils --watchAll
yields. I tried various variations like jest --group utils
, but all yield the same.
jest --group utils
โ Unrecognized CLI Parameter:
Unrecognized option "group".
CLI Options Documentation:
https://jestjs.io/docs/en/cli.html
Commit: https://github.com/UnlyEd/next-right-now/pull/91/files
jest.config.js
:
// This config cannot be used alongside package.json:jest, all Jest config must be centralised in this file - See https://github.com/facebook/jest/issues/10123#issuecomment-638796267
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
globals: {
// XXX we must specify a custom tsconfig for tests because we need the typescript transform
// to transform jsx into js rather than leaving it jsx such as the next build requires. you
// can see this setting in tsconfig.jest.json -> "jsx": "react"
// See https://github.com/vercel/next.js/issues/8663
'ts-jest': {
tsConfig: 'tsconfig.jest.json',
},
},
modulePathIgnorePatterns: [
'cypress',
],
runner: 'groups', // Allow to use jest-runner-groups - See https://github.com/eugene-manuilov/jest-runner-groups#update-jest-config
setupFilesAfterEnv: [
'jest-extended', // See https://github.com/jest-community/jest-extended
'./jest.setup.js',
'./jest.extends.ts',
],
};
To reproduce:
git clone https://github.com/UnlyEd/next-right-now.git nrn-quick-start
cd nrn-quick-start && git checkout test-groups
yarn test:group:utils
TypeError: this._config.extraGlobals is not iterable
at Runtime.constructInjectedModuleParameters (../../node_modules/jest-runtime/build/index.js:1759:23)
Jest 24.9.0
I have a test file with two describe blocks, each of these blocks are under different groups. When i run tests for a specific group, its running all the tests in the file even the ones which arent in that group..
Hey, thanks for making this great package! I just tried it out and it works great --- but my console coverage stats are not working correctly when I use jest-runner-groups.
Here's my output when before using the "groups" runner:
$ npm run test
[...]
-----------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------|---------|----------|---------|---------|-------------------
All files | 97.37 | 61.9 | 100 | 97.14 |
src | 100 | 50 | 100 | 100 |
db.ts | 100 | 50 | 100 | 100 | 13,14,26,27
src/entity | 100 | 100 | 100 | 100 |
Recording.ts | 100 | 100 | 100 | 100 |
Session.ts | 100 | 100 | 100 | 100 |
TimeOfDay.ts | 100 | 100 | 100 | 100 |
src/radiotools | 93.94 | 69.23 | 100 | 93.94 |
radiostatus.ts | 93.94 | 69.23 | 100 | 93.94 | 47,48
-----------------|---------|----------|---------|---------|-------------------
After I add runner: "groups",
to my jest.config, the output is like this:
$npm run test
[...]
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
I love the group runner, but I don't want to loose my instant feedback on coverage.
This is my jest config.
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
// runner: "groups",
roots: [
'<rootDir>/src'
],
testMatch: [
'**/__tests__/**/*.+(ts|tsx|js)',
'**/?(*.)+(spec|test).+(ts|tsx|js)'
],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest'
},
collectCoverage: true,
// coverageReporters: ['html'],
globals: {
'ts-jest': {
tsConfig: {
importHelpers: true,
downlevelIteration: true,
esModuleInterop: true,
}
}
}
};
and this the relevant part from the package.json:
"test": "npx jest --coverage --passWithNoTests",
"unit": "npx jest --coverage --passWithNoTests --group=unit",
"integration": "npx jest --coverage --passWithNoTests --group=integration",
Is this by design, or can I set it up in a different way to keep my stats visible? Thanks!
In case it helps anyone, I started getting this linting error when I Introduced jest-runner-groups
into a project already using TSDoc:
error tsdoc-undefined-tag: The TSDoc tag "@group" is not defined in this configuration tsdoc/syntax
which I fixed by creating the following tsdoc.json
file (which I placed alongside my tsconfig.json
file):
{
"$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
"extends": ["@microsoft/api-extractor/extends/tsdoc-base.json"],
"supportForTags": {
"@group": true
},
"tagDefinitions": [
{
"tagName": "@group",
"syntaxKind": "block",
"allowMultiple": true
}
]
}
Hello,
I have upgraded my project to jest 25.5.0 and I found that if I try to use jest-runner-groups I get:
Do not import `@jest/globals` outside of the Jest test environment
I think it was introduced with this change in jest: jestjs/jest@e21468d
You can reproduce with this test using jest 25.5+:
jest.disableAutomock()
test('fml', () => {
expect(true).toBeTruthy()
})
If I downgrade to jest 25.4.0 or disable jest-runner-groups the tests run as expected.
I have no idea what's going on here to offer PR sorry.
Having a weird issue that just started on my macbook. We've been using this runner for some time with our node projects but recently when I merged a local git project from master, and did an npm update, when I try to run a group of tests:
jest --config ./jest.config.unit.js --collectCoverage --collectCoverageFrom="src/**/*.js" --coverageReporters clover json lcov text text-summary cobertura --coverageDirectory="./coverage" --group=ut --reporters=default --reporters=jest-junit --watchAll=false --verbose --runInBand --forceExit --detectOpenHandles"
I'm just seeing results:
Test Suites: 0 of 9 total
Tests: 0 total
Snapshots: 0 total
Time: 0.456 s, estimated 2 s
Ran all test suites.
The test files include:
/**
So it seems to not recognize the group attribute in the test files perhaps? If I remove the runner: 'groups' from jest.config.unit.js-module.exports json the tests run fine:
Test Suites: 9 passed, 9 total
Tests: 54 passed, 54 total
Snapshots: 0 total
Time: 3.801 s, estimated 44 s
Ran all test suites.
Really stumped; can't find anything online to help. I've tried re-installing the runner and played around with things ... no luck ... And my team mates don't have this issue when they pull my branch. Any thoughts?
Thanks,
Paul
By default, jest fails if no tests were found. But when we use runner: 'groups'
the process exits with status 0 which is unexpected and may lead to situations when we don't notice that something doesn't work, e.g. like #42 :
> test() { jest --group=$1 --verbose=false --runInBand --logHeapUsage --detectOpenHandles; }; test "unit"
Test Suites: 0 of 74 total
Tests: 0 total
Snapshots: 0 total
Time: 0.179 s, estimated 576 s
Ran all test suites.
Process finished with exit code 0
The problem is reproducible in jest-runner-groups v2.2.0 and Node.js v14.18.2
Description: I wish to generate the reports of test file executions pass/fail at the end of each group execution. But when I tagged multiple files with @group=xyz, It is executing the file which sends report first and then executing the remaining files later.
Since report file executes at first, all the numbers(pass/fail/total tests) are 0 because by then no test file is executed. Later other test files in the group are executing and numbers are not matching
We are using jest-runner-groups
to run integration test and we love it but we run in a little trouble.
As jest is forked from jasmine it inherited a not so fun behavior: it anything in beforeEach or beforeAll fails jest will continue to run the tests.
This behavior is fixed in the new runner that jest will use in the future (jest-circus), so I am looking for a way to use jest-runner-groups
and using jest-circus at the same time, with a specific opt-in.
Are you open to discuss the feature? I could prepare a PR in this case.
How should I group the individual test cases within a single describe block such that I can test a singular test case instead of testing every single test case within a describe block.
Hi ๐ Thank you for an excellent plugin that solves a real problem for many folks.
I have a question about whether it's possible to tell (at a test file level) what group was specified when the command was given. The kind of problem I am attempting to solve is as follows:
yarn jest --group 'FeatureA'
/**
* @group FeatureA
* @group FeatureB
**/
describe('Test for Feature', function() {
const username = group === 'FeatureA' ? 'featureAUser' : 'featureBUser'; <-- this part
});
In short, a test file may be shared between two or more groups that follow the same steps in order to reduce duplication in the test code. However, the test user to be used differ depending on the group selected.
Thanks and I appreciate any reply or pointers!
Is it possible to run tests that are not in a group (eg to save having to group lots of tests as @group unit
), or to not run tests from a certain group (eg to not run those in @group integration
?)
Our project has a lot of test suites. To avoid modifying all of them, we want to run specific tests separately "in band" while the rest can run in parallel. To accomplish this, I annotated a couple files with @group solo
but all other files were not tagged at all.
I then ran this which seemed to work:
npx jest --group=solo --coverage=false --maxWorkers='1'
Only the specific tagged test suites were executed as desired. However, I then tried running this:
npx jest --group=-solo --coverage=true
I would have expected this to run all tests that are not tagged with "solo". Instead, everything was run including the tests with @group solo
in them.
Thanks for the contribution.
Help me realize the added-value: one could just a tag to the describe block:
describe('Some description #any-tag')
And then grep for this tag using the built-in -t flag:
jest -t any-tag
What added value does this repo bring over the example above?
Can I set several dockblock per file?
I mean, I have file with several describes and I want to define each describe in different group.
Can I do it?
Currently I have 2 describes in one file:
* @group sanity
*/
describe("Sanity", () => {});
/**
* @group regression
*/
describe("Regression", () => {});```
If i'm running `--group=sanity`
it's still runs regression tests as well.
Is there a way to just run the coverage only within the group?
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! :)
Hi,
I can see there isn't an option to override groups.
I think if different groups is declared in "describe" level and in "it" level, the most inner one should be the relevant.
For example:
/**
* @group regression
*/
describe(This is the describe level, () => {
/**
* @group sanity
*/
it("This "it" has group different from the describe", async () => {
});
it("This "it" gets the group from the describe", async () => {
});
});
Now, in case we would like to run only regression we will use the command:
npm run COMMAND -- --group=regression --> Here "sanity" group won't run
In case we would like to run only regression we will use the command:
npm run COMMAND -- --group=sanity --> Here "sanity" group won't run
I know it's can be done by using the exclude, but I believe this way is better.
WDYT?
Hi ,
I have a custom runner for jest which invokes the jest commands using the jest-cli.run() method . I would like to tag my tests using the jest-runner-groups , however when i pass the --group command to jest cli i get the error : Unrecognized option "group" . Is there a way around this ? Would be really useful to run group of tests that can be invoked from the command line
Added runner-groups to my project which having Playwright + Jest.
Giving error as follows:
[email protected] test /Users/dilshani/Tech/projects/dashboard-ui
> jest --detectOpenHandles --group=ci
FAIL src/specs/[Negative]login.ci.test.ts
โ Test suite failed to run
TypeError: Cannot read property 'logger' of undefined
at BrowserType.connect (node_modules/playwright/lib/client/browserType.js:90:31)
at getBrowserPerProcess (node_modules/jest-playwright-preset/lib/PlaywrightEnvironment.js:31:31)
at PlaywrightEnvironment.setup (node_modules/jest-playwright-preset/lib/PlaywrightEnvironment.js:90:48)
Test Suites: 1 failed, 1 of 2 total
Tests: 0 total
Snapshots: 0 total
Time: 0.445 s, estimated 28 s
Ran all test suites.
npm ERR! Test failed. See above for more details.
Dependencies:
"devDependencies": {
"@types/jest": "^26.0.19",
"jest": "^26.6.3",
"jest-junit": "^12.0.0",
"jest-playwright-preset": "^1.4.3",
"jest-runner-groups": "^2.0.1",
"playwright": "^1.7.1",
"ts-jest": "^26.4.4",
"typescript": "^4.1.3"
}
I have tests in a group split between multiple files. I have some fixture setup I want to run once for the whole group. I tried adding a Jest global setup and checking the value of process.env.JEST_GROUP_NAME
but the env var didn't exist. I'm guessing the env var gets set after the global setup. Is there a way to run a setup once per group?
I'm not sure when this problem cropped up but I suspect it was after I did some package updates in a project.
Previously working tests were showing a Type Error with the message being the title of this issue.
Jest defaults the value of extraGlobals
to undefined
and so to resolve the errors I had to add the extraGlobals
parameter to my Jest config and make it equal and empty array.
The given line number for the error was: node_modules/jest-runner-groups/node_modules/jest-runtime/build/index.js:1759:23
where you use the spread operator on this._config.extraGlobals
, at least in my particular environment which is Node.js V12.15.0 and npm V6.14.5.
I guess the desired behavior is that the code should check that config variable's value for undefined
before trying to spread the variable.
Thanks for the great package and great work!
If run
npm run test -- --group=IntegrationTests --ci --testResultsProcessor="jest-junit" --coverageReporters=cobertura --coverage
in a dir without a group IntegrationTests but has jest tests with no grouping all the tests without a grouping are ran. If i run the above command in a dir that has Integration Test group in it, it will ran and no other tests are ran.
Seems these guys have experiences the issue too
nrwl/nx#9873
This may be strange request, but is it possible for the test file to know which group is running?
I've got a fairly unique use case where my library supports multiple react renderers (dom
, native
and server
). Most tests are applicable to all the renderers but some have different functionality for the server
renderer. I'm looking for a way to run the same test against a subset of the renderers but only import the one for the test group being run (I'm happy to run it separately for each group) as the imports have side effects so I don't want to import them all and loop over them in the test file.
Is that something that jest-runner-groups
supports or would consider supporting if it's even possible? It's ok if it's not.
I'm using create-react-app which doesn't allow specifying the test runner in config. However, the guys there suggested I could use the CLI option to specify the test runner. I have tried adding --testRunner="jest-runner-groups"
but this gives an error:
TypeError: Class constructor GroupRunner cannot be invoked without 'new'
I am using TypeScript. I can see that your GroupRunner is inheriting from jest-runner's TestRunner class but according to the jest documentation (https://jestjs.io/docs/en/configuration), a test runner should be a function with a certain signature so I'm confused how the 2 concepts fit together.
Would it be possible to use the file extension to group tests instead of a block comment ?
For example
sometest.unit.spec.ts
sometest.integration.spec.ts
I do this currently because it easier to identify the files without having to open them, but it looks a little redundant to have both the file name and the block comment.
Multiple groups in the same spec file would not work. But at least for me, that's not a problem.
I can't see to make it work with jest-playwright-preset
Can we please have diff test groups per file.
Like be able to define groups at different levels within the same file. Even if its at the describe level that would be good
test.test.ts
/**
* @group integration
*/
describe(()=>{})
/**
* @group unit
*/
describe(()=>{})
I have a jest setup file which contains a group of actions to run in beforeEach():
global.beforeEach(async () => {
console.log("Hello World")
});
In my tests file I have several tests from different groups(sanity/regression etc')
The groups defined in test level and not in describe level.
When running one of the groups, the global.beforeEach() is running for the other group as well.
My expectation is that global.beforeEach
will run only for the relevant group.
Is there a way to do it?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.