forked from bluebeel/now-builders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.js
38 lines (32 loc) · 1.04 KB
/
jest.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const { execSync } = require('child_process');
const { relative } = require('path');
const branch = execSync('git branch | grep "*" | cut -d " " -f2')
.toString()
.trim();
console.log(`Running tests on branch "${branch}"`);
const gitPath = branch === 'master' ? 'HEAD~1' : 'origin/canary...HEAD';
const diff = execSync(`git diff ${gitPath} --name-only`).toString();
const changed = diff
.split('\n')
.filter(item => Boolean(item) && item.includes('packages/'))
.map(item => relative('packages', item).split('/')[0]);
const matches = Array.from(new Set(changed));
if (matches.length === 0) {
matches.push('now-node');
console.log(`No packages changed, defaulting to ${matches[0]}`);
} else {
console.log('The following packages have changed:');
console.log(matches.join('\n'));
}
const testMatch = matches.map(
item => `**/${item}/**/?(*.)+(spec|test).[jt]s?(x)`,
);
module.exports = {
testEnvironment: 'node',
testMatch,
collectCoverageFrom: [
'packages/(!test)/**/*.{js,jsx}',
'!**/node_modules/**',
'!**/test/**',
],
};