Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit ad4593c

Browse files
committed
update jest task to properly handle test matching
1 parent de79678 commit ad4593c

File tree

4 files changed

+10
-24
lines changed

4 files changed

+10
-24
lines changed

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -231,32 +231,29 @@ the `babel.config.json` file to parse the code.
231231
#### Jest
232232

233233
This task runs Jest on the JavaScript files using our Jest configurations. Add a
234-
`jest.config.js` file in the working repository and extend one of the configurations.
234+
`jest.config.js` file in the working repository and extend the jest configuration.
235235
Add a `displayName` and `testMatch` to tell Jest what to look for:
236236

237237
```
238238
var sharedConfig = require( '@the-events-calendar/product-taskmaster/config/jest.config.js' );
239+
var pkg = require( './package.json' );
239240
240241
module.exports = {
241242
...sharedConfig,
242243
displayName: 'common',
243-
testMatch: [
244-
'**/__tests__/**/*.js',
245-
],
244+
testMatch: pkg._filePath.jest.map( ( path ) => `<rootDir>/${ path }` ),
246245
};
247246
```
248247

249-
To run Jest, you'll need to provide file path array in the `package.json` to tell gulp where to look.
250-
An example might look like:
248+
Add file path array to the `package.json` to tell Jest what to test. An example might look like:
251249

252250
```
253251
"_filePath": {
254252
"jest": [
255-
"src/modules"
253+
"src/modules/**/__tests__/**/*.js"
256254
]
257255
}
258256
```
259257

260-
This tells gulp to look in the `src/modules` folder. We are not specifying the files here, the
261-
`jest.config.js` file we set up above does that. Multiple file paths and test matches can be set up,
262-
allowing each file path to be tested against each of the test matches.
258+
The `testMatch` can be input manually without relying on `package.json`. This just keeps all
259+
file paths in one place.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@the-events-calendar/product-taskmaster",
33
"description": "This is a collection of The Events Calendar product Gulp tasks",
4-
"version": "2.1.0",
4+
"version": "2.1.1",
55
"repository": "git@github.com:the-events-calendar/product-taskmaster.git",
66
"main": "index.js",
77
"engines": {

tasks/jest.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@ module.exports = function( gulp, pkg ) {
44
var jest = require( 'gulp-jest' ).default;
55

66
var task = function() {
7-
// Check if package.json has file path array for jest.
8-
if (
9-
! pkg._filePath ||
10-
! pkg._filePath.jest ||
11-
! Array.isArray( pkg._filePath.jest )
12-
) {
13-
console.error( 'package.json must contain a file path array under _filePath.jest' );
14-
process.exit(-1);
15-
}
16-
17-
return gulp.src( pkg._filePath.jest )
18-
.pipe( jest() );
7+
return gulp.src( './' ).pipe( jest() );
198
};
209

2110
gulp.task( 'jest', task );

0 commit comments

Comments
 (0)