-
Notifications
You must be signed in to change notification settings - Fork 472
/
map.js
57 lines (52 loc) · 1.33 KB
/
map.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const t = require('tap')
// ensure that the coverage map maps all coverage
const ignore = [
'.git',
'.github',
'.commitlintrc.js',
'.eslintrc.js',
'node_modules',
'coverage',
'tap-snapshots',
'test',
'fixtures',
]
const { statSync, readdirSync } = require('fs')
const find = (folder, set = [], root = true) => {
const ent = readdirSync(folder)
set.push(
...ent
.filter((f) => !ignore.includes(f) && /\.m?js$/.test(f))
.map((f) => folder + '/' + f)
)
for (const e of ent.filter(
(f) => !ignore.includes(f) && !/\.m?js$/.test(f)
)) {
if (statSync(folder + '/' + e).isDirectory()) {
find(folder + '/' + e, set, false)
}
}
if (!root) {
return
}
return set
.map((f) => f.slice(folder.length + 1).replace(/\\/g, '/'))
.sort((a, b) => a.localeCompare(b))
}
const { resolve } = require('path')
const root = resolve(__dirname, '..')
const sut = find(root)
const tests = find(root + '/test')
t.strictSame(sut, tests, 'test files should match system files')
const map = require('../map.js')
for (const testFile of tests) {
t.test(testFile, (t) => {
t.plan(1)
// cast to an array, since map() can return a string or array
const systemFiles = [].concat(map(testFile))
t.ok(
systemFiles.some((sys) => sut.includes(sys)),
'test covers a file'
)
})
}