-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.mocharc.js
More file actions
60 lines (56 loc) · 1.86 KB
/
.mocharc.js
File metadata and controls
60 lines (56 loc) · 1.86 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const { readdirSync, statSync } = require('fs')
const { dirname, resolve } = require('path')
const [, , scopesArg, ...scopes] = process.argv
if (scopesArg !== '--scope') {
scopes.length = 0
}
const manifest = require('./.tsconfig.builder.json').include.filter((file) => file.endsWith('index.ts'))
function findPaths(dir) {
const subDirs = readdirSync(dir)
return subDirs
.filter((subDir) => subDir !== 'src' && subDir !== 'node_modules' && subDir !== '.yarn-cache')
.map((subDir) => `${dir}/${subDir}`)
.filter((subDir) => statSync(subDir).isDirectory())
.reduce((result, subDir) => {
result.push(subDir)
result.push(...findPaths(subDir))
return result
}, [])
}
const paths = manifest
.filter((path) => {
if (!scopes.length) {
return true
}
return scopes.some((scope) => path.startsWith(`packages/${scope}/`))
})
.reduce((result, file) => {
const dir = dirname(file)
result.push(dir, ...findPaths(resolve(__dirname, dir)))
return result
}, [])
const barrels = paths.map((path) => `${path}/index.ts`)
const unitSpec = paths.map((path) => `${path}/src/**/*.spec.ts`)
const intSpec = paths.map((path) => `${path}/src/**/*.int-spec.ts`)
const spec = [...barrels, ...unitSpec, ...intSpec]
// suppress "Cannot find any files matching pattern" warnings from mocha startup
console.__ogWarn = console.warn
console.warn = (msg, ...args) => {
if (msg.includes('Cannot find any files matching pattern')) {
return
}
console.__ogWarn.call(console, msg, ...args)
}
module.exports = {
extension: 'ts',
ignore: ['.out', '.build', 'dist'],
watchIgnore: ['.out', '.build', 'dist'],
require: [
'tsconfig-paths/register',
resolve(__dirname, './test/ts-node.js'),
'ts-custom-error-shim',
resolve(__dirname, './test/mocha.config'),
],
file: [resolve(__dirname, 'test/sandbox.ts'), ...manifest],
spec,
}