Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New runner name #3

Merged
merged 6 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ jobs:
strategy:
matrix:
node-version:
- 10.x
- 12.x
- 14.x
- 16.x
- 18.x
Expand All @@ -18,6 +16,7 @@ jobs:
- ./jest/25
- ./jest/26
- ./jest/27
- ./jest/29
steps:
- uses: actions/checkout@v3
with:
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

## [Unreleased] - TBD

-

## [v3.2.2] (2024-07-14)

- Change runner name
- Add tests for Jest 29

## [v2.2.1] (2024-07-14)

- Added information about the currently running groups to environment variables.
- Updated dependencies to the latest versions.

## [v2.2.0] (2022-03-28)

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Downloads/week](https://img.shields.io/npm/dw/jest-runner-grouped-tests.svg)](https://www.npmjs.com/package/jest-runner-grouped-tests)
[![License](https://img.shields.io/npm/l/jest-runner-grouped-tests.svg)](https://github.com/saritvakrat/jest-runner-grouped-tests/blob/master/package.json)

A test runner that allows you to tag your tests and execute specific groups of tests with Jest.
A test runner that allows you to tag your tests and execute specific groups of tests with Jest. This runner is based on the original repository that was [archived](https://github.com/eugene-manuilov/jest-runner-groups)

## Installation

Expand Down Expand Up @@ -65,7 +65,7 @@ To make Jest use this runner, you need to update your Jest config and add `group
"dependencies": {
},
"jest": {
"runner": "groups"
"runner": "jest-runner-grouped-tests"
}
}
```
Expand All @@ -75,7 +75,7 @@ Or in the `jest.config.js` file:
```javascript
module.exports = {
...
runner: "groups"
runner: "jest-runner-grouped-tests"
};
```

Expand Down
30 changes: 26 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ const TestRunner = Object.prototype.hasOwnProperty.call( JestRunner, 'default' )

const ARG_PREFIX = '--group=';

class Group2Runner extends TestRunner {
class GroupsRunner extends TestRunner {

/**
* Parses command line arguments to identify groups to include and exclude
* @param args
* @return {{include: *[], exclude: *[]}}
*/
static getGroups( args ) {
const include = [];
const exclude = [];
Expand All @@ -30,6 +35,13 @@ class Group2Runner extends TestRunner {
};
}

/**
* Filters tests based on the specified groups.
* @param include
* @param exclude
* @param test
* @return {boolean}
*/
static filterTest( { include, exclude }, test ) {
let found = include.length === 0;

Expand All @@ -53,8 +65,18 @@ class Group2Runner extends TestRunner {
return found;
}

/**
* Overrides the default runTests method to filter tests based on groups before running them.
* @param tests
* @param watcher
* @param onStart
* @param onResult
* @param onFailure
* @param options
* @return {Promise<void>}
*/
runTests( tests, watcher, onStart, onResult, onFailure, options ) {
const groups = GroupRunner.getGroups( process.argv );
const groups = GroupsRunner.getGroups( process.argv );

groups.include.forEach( ( group ) => {
if ( groups.exclude.includes( group ) ) {
Expand All @@ -67,7 +89,7 @@ class Group2Runner extends TestRunner {

return super.runTests(
groups.include.length > 0 || groups.exclude.length > 0
? tests.filter( ( test ) => GroupRunner.filterTest( groups, test ) )
? tests.filter( ( test ) => GroupsRunner.filterTest( groups, test ) )
: tests,
watcher,
onStart,
Expand All @@ -79,4 +101,4 @@ class Group2Runner extends TestRunner {

}

module.exports = Group2Runner;
module.exports = GroupsRunner;
2 changes: 1 addition & 1 deletion jest/24/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"testMatch": [
"<rootDir>/tests/*.js"
],
"runner": "groups",
"runner": "jest-runner-grouped-tests",
"verbose": true
}
}
2 changes: 1 addition & 1 deletion jest/25/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"testMatch": [
"<rootDir>/tests/*.js"
],
"runner": "groups",
"runner": "jest-runner-grouped-tests",
"verbose": true
}
}
2 changes: 1 addition & 1 deletion jest/26/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"testMatch": [
"<rootDir>/tests/*.js"
],
"runner": "groups",
"runner": "jest-runner-grouped-tests",
"verbose": true
}
}
2 changes: 1 addition & 1 deletion jest/27/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"testMatch": [
"<rootDir>/tests/*.js"
],
"runner": "grouped-tests",
"runner": "jest-runner-grouped-tests",
"verbose": true
}
}
17 changes: 17 additions & 0 deletions jest/29/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"scripts": {
"test": "jest --group=valid"
},
"devDependencies": {
"jest": "^29.7.0",
"lodash": "^4.17.21"
},
"jest": {
"rootDir": "../..",
"testMatch": [
"<rootDir>/tests/*.js"
],
"runner": "jest-runner-grouped-tests",
"verbose": true
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jest-runner-grouped-tests",
"version": "2.2.1",
"version": "3.2.2",
"description": "Tag and run groups of tests with Jest",
"license": "MIT",
"author": "Eugene Manuilov <[email protected]>",
Expand Down
Loading