Skip to content

Commit 6088070

Browse files
committedMay 8, 2020
add a test for the coverage map
This also enforces our strict 1:1 mapping from tests to the system under test.
1 parent bcab95a commit 6088070

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
 

‎test/map.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const t = require('tap')
2+
3+
// ensure that the coverage map maps all coverage
4+
const ignore = ['.git', '.github', 'node_modules', 'coverage', 'tap-snapshots', 'test', 'fixtures']
5+
const {statSync, readdirSync} = require('fs')
6+
const find = (folder, set = [], root = true) => {
7+
const ent = readdirSync(folder)
8+
set.push(...ent.filter(f => /\.m?js$/.test(f)).map(f => folder + '/' + f))
9+
for (const f of ent.filter(f => !ignore.includes(f) && !/\.m?js$/.test(f))) {
10+
if (statSync(folder + '/' + f).isDirectory())
11+
find(folder + '/' + f, set, false)
12+
}
13+
if (!root)
14+
return
15+
return set.map(f => f.substr(folder.length + 1)
16+
.replace(/\\/g, '/'))
17+
.sort((a, b) => a.localeCompare(b))
18+
}
19+
20+
const {resolve} = require('path')
21+
const root = resolve(__dirname, '..')
22+
23+
const sut = find(root)
24+
const tests = find(root + '/test')
25+
t.strictSame(sut, tests, 'test files should match system files')
26+
const map = require('../map.js')
27+
28+
for (const testFile of tests) {
29+
t.test(testFile, t => {
30+
t.plan(1)
31+
// cast to an array, since map() can return a string or array
32+
const systemFiles = [].concat(map(testFile))
33+
t.ok(systemFiles.some(sys => sut.includes(sys)), 'test covers a file')
34+
})
35+
}

0 commit comments

Comments
 (0)
Please sign in to comment.