Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function findReporter( reporterName ) {
if ( !reporterName ) {
return JSReporters.TapReporter;
}
// First, check if the reporter is one of the standard js-reporters ones
const capitalizedName = utils.capitalize( reporterName );
const jsReporterName = `${capitalizedName}Reporter`;
if ( JSReporters[ jsReporterName ] ) {
return JSReporters[ jsReporterName ];
}
// Second, check if the reporter is an npm package
try {
return require( reporterName );
} catch ( e ) {
if ( e.code !== "MODULE_NOT_FOUND" ) {
QUnit.test( "correctly finds js-reporters reporter by name", function( assert ) {
const reporter = findReporter( "tap" );
assert.strictEqual( reporter, JSReporters.TapReporter );
} );