Skip to content

Commit 6db5349

Browse files
committed
refactor: move test match configuration into common helper
1 parent c8c4028 commit 6db5349

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

src/config/helpers/build-eslint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const {
33
} = require('eslint-config-airbnb-typescript/lib/shared')
44

55
const {hasAnyDep} = require('../../utils')
6-
const {testMatch} = require('../jest.config')
6+
const {testMatch} = require('../helpers/test-match')
77

88
const withBaseConfig = base => variant =>
99
require.resolve(base + (variant ? `/${variant}` : ''))

src/config/helpers/test-match.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const toGlob = extensions => `*.+(${extensions.join('|')})`
2+
3+
const testMatchExtensions = ['js', 'jsx', 'ts', 'tsx']
4+
const testMatchGlob = toGlob(testMatchExtensions)
5+
const testMatchSuffixGlob = toGlob(
6+
testMatchExtensions.map(extension => 'test.'.concat(extension)),
7+
)
8+
9+
const testMatch = [
10+
`**/__tests__/**/${testMatchGlob}`,
11+
`test/**/${testMatchGlob}`,
12+
`test/**/${testMatchSuffixGlob}`,
13+
`e2e/**/${testMatchSuffixGlob}`,
14+
`**/${testMatchSuffixGlob}`,
15+
]
16+
17+
module.exports = {
18+
testMatchExtensions,
19+
testMatchGlob,
20+
testMatchSuffixGlob,
21+
testMatch,
22+
}

src/config/jest.config.js

+7-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ const {jsWithTs: preset} = require('ts-jest/presets')
44

55
const {ifAnyDep, hasAnyDep, hasFile, fromRoot} = require('../utils')
66

7+
const {
8+
testMatch,
9+
testMatchGlob,
10+
testMatchExtensions,
11+
} = require('./helpers/test-match')
12+
713
const ignores = [
814
'/node_modules/',
915
'/__fixtures__/',
@@ -13,27 +19,14 @@ const ignores = [
1319
'__mocks__',
1420
]
1521

16-
const toGlob = extensions => `*.+(${extensions.join('|')})`
17-
const testMatchExtensions = ['js', 'jsx', 'ts', 'tsx']
18-
const testMatchGlob = toGlob(testMatchExtensions)
19-
const testMatchSuffixGlob = toGlob(
20-
testMatchExtensions.map(extension => 'test.'.concat(extension)),
21-
)
22-
2322
/** @type JestConfig */
2423
const jestConfig = {
2524
roots: [fromRoot('.')],
2625
testEnvironment: ifAnyDep(['webpack', 'rollup', 'react'], 'jsdom', 'node'),
2726
testURL: 'http://localhost',
2827
moduleFileExtensions: testMatchExtensions.concat('json'),
2928
collectCoverageFrom: [`**/${testMatchGlob}`],
30-
testMatch: [
31-
`**/__tests__/**/${testMatchGlob}`,
32-
`test/**/${testMatchGlob}`,
33-
`test/**/${testMatchSuffixGlob}`,
34-
`e2e/**/${testMatchSuffixGlob}`,
35-
`**/${testMatchSuffixGlob}`,
36-
],
29+
testMatch,
3730
testPathIgnorePatterns: [...ignores, '<rootDir>/dist'],
3831
coveragePathIgnorePatterns: [
3932
...ignores,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {}

0 commit comments

Comments
 (0)