Skip to content

Commit e4d54b3

Browse files
committed
feat(scripts/test): add support for a couple more test naming/location conventions
1 parent 59cc9b6 commit e4d54b3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/config/jest.config.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,24 @@ const ignores = [
1212
'__mocks__',
1313
]
1414

15+
const toGlob = extensions => `*.+(${extensions.join('|')})`
16+
const testMatchExtensions = ['js', 'jsx', 'ts', 'tsx']
17+
const testMatchGlob = toGlob(testMatchExtensions)
18+
const testMatchSuffixGlob = toGlob(
19+
testMatchExtensions.map(extension => 'test.'.concat(extension)),
20+
)
21+
1522
const jestConfig = {
16-
roots: [fromRoot('src')],
23+
roots: [fromRoot('src'), fromRoot('test')],
1724
testEnvironment: ifAnyDep(['webpack', 'rollup', 'react'], 'jsdom', 'node'),
1825
testURL: 'http://localhost',
19-
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'],
20-
collectCoverageFrom: ['src/**/*.+(js|jsx|ts|tsx)'],
21-
testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'],
26+
moduleFileExtensions: testMatchExtensions.concat('json'),
27+
collectCoverageFrom: [`src/**/${testMatchGlob}`],
28+
testMatch: [
29+
`**/__tests__/**/${testMatchGlob}`,
30+
`test/**/${testMatchGlob}`,
31+
`**/${testMatchSuffixGlob}`,
32+
],
2233
testPathIgnorePatterns: [...ignores],
2334
coveragePathIgnorePatterns: [...ignores, 'src/(umd|cjs|esm)-entry.js$'],
2435
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],

0 commit comments

Comments
 (0)