diff --git a/lib/utils/index.js b/lib/utils/index.js index c4ff4c15..ec69d968 100644 --- a/lib/utils/index.js +++ b/lib/utils/index.js @@ -1,19 +1,28 @@ 'use strict' -const { readdirSync } = require('fs') -const { basename } = require('path') - -const files = readdirSync(__dirname).filter(f => f.endsWith('.test.js') === false) -for (const file of files) { - if (file === 'index.js') continue - - 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('') - - module.exports[snakeName] = require(`./${kebabName}.js`) +module.exports = { + buildSafeSonicBoom: require('./build-safe-sonic-boom.js'), + createDate: require('./create-date.js'), + deleteLogProperty: require('./delete-log-property.js'), + filterLog: require('./filter-log.js'), + formatTime: require('./format-time.js'), + getPropertyValue: require('./get-property-value.js'), + handleCustomLevelsNamesOpts: require('./handle-custom-levels-names-opts.js'), + handleCustomLevelsOpts: require('./handle-custom-levels-opts.js'), + interpretConditionals: require('./interpret-conditionals.js'), + isObject: require('./is-object.js'), + isValidDate: require('./is-valid-date.js'), + joinLinesWithIndentation: require('./join-lines-with-indentation.js'), + noop: require('./noop.js'), + parseFactoryOptions: require('./parse-factory-options.js'), + prettifyErrorLog: require('./prettify-error-log.js'), + prettifyError: require('./prettify-error.js'), + prettifyLevel: require('./prettify-level.js'), + prettifyMessage: require('./prettify-message.js'), + prettifyMetadata: require('./prettify-metadata.js'), + prettifyObject: require('./prettify-object.js'), + prettifyTime: require('./prettify-time.js'), + splitPropertyKey: require('./split-property-key.js') } // The remainder of this file consists of jsdoc blocks that are difficult to diff --git a/lib/utils/index.test.js b/lib/utils/index.test.js new file mode 100644 index 00000000..4cd5a117 --- /dev/null +++ b/lib/utils/index.test.js @@ -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') + } +)