-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This also enforces our strict 1:1 mapping from tests to the system under test.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const t = require('tap') | ||
|
||
// ensure that the coverage map maps all coverage | ||
const ignore = ['.git', '.github', '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 => /\.m?js$/.test(f)).map(f => folder + '/' + f)) | ||
for (const f of ent.filter(f => !ignore.includes(f) && !/\.m?js$/.test(f))) { | ||
if (statSync(folder + '/' + f).isDirectory()) | ||
find(folder + '/' + f, set, false) | ||
} | ||
if (!root) | ||
return | ||
return set.map(f => f.substr(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') | ||
}) | ||
} |