-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Manually require and export all util scripts
* Fixes #466 Signed-off-by: Marvin A. Ruder <signed@mruder.dev>
- Loading branch information
1 parent
9fb7330
commit 8ee55cc
Showing
2 changed files
with
60 additions
and
14 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
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,37 @@ | ||
'use strict' | ||
|
||
const tap = require('tap') | ||
const index = require('./index.js') | ||
const { readdirSync } = require('fs') | ||
const { basename } = require('path') | ||
|
||
tap.test( | ||
'index exports exactly all non-test files excluding itself', | ||
async t => { | ||
// Read all files in the `util` directory | ||
const files = readdirSync(__dirname) | ||
|
||
for (const file of files) { | ||
const kebabName = basename(file, '.js') | ||
const snakeName = kebabName.split('-').map((part, idx) => { | ||
if (idx === 0) return part | ||
return part[0].toUpperCase() + part.slice(1) | ||
}).join('') | ||
|
||
if (file.endsWith('.test.js') === false && file !== 'index.js') { | ||
// We expect all files to be exported except… | ||
t.ok(index[snakeName], `exports ${snakeName}`) | ||
} else { | ||
// …test files and the index file itself – those must not be exported | ||
t.notOk(index[snakeName], `does not export ${snakeName}`) | ||
} | ||
|
||
// Remove the exported file from the index object | ||
delete index[snakeName] | ||
} | ||
|
||
// Now the index is expected to be empty, as nothing else should be | ||
// exported from it | ||
t.same(index, {}, 'does not export anything else') | ||
} | ||
) |