diff --git a/borp.js b/borp.js index ff27f37..ac3ebc9 100755 --- a/borp.js +++ b/borp.js @@ -90,9 +90,7 @@ try { const reporters = { ...Reporters, - gh: githubReporter, - /* eslint new-cap: "off" */ - spec: new Reporters.spec() + gh: githubReporter } // If we're running in a GitHub action, adds the gh reporter @@ -103,10 +101,8 @@ try { for (const input of args.values.reporter) { const [name, dest] = input.split(':') - const reporter = reporters[name] - if (!reporter) { - throw new Error(`Unknown reporter: ${name}`) - } + const Ctor = reporters[name] || await import(name).then((m) => m.default || m) + const reporter = Object.getOwnPropertyDescriptor(Ctor.prototype, 'constructor') ? new Ctor() : Ctor let output = process.stdout if (dest) { output = createWriteStream(dest) diff --git a/package.json b/package.json index 18bda5c..0afbe95 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "license": "MIT", "devDependencies": { "@matteo.collina/tspl": "^0.1.0", + "@reporters/silent": "^1.2.4", "@types/node": "^20.10.0", "desm": "^1.3.0", "snazzy": "^9.0.0", diff --git a/test/cli.test.js b/test/cli.test.js index 1c5c4a6..362c1f9 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -60,3 +60,18 @@ test('disable ts and run no tests', async () => { strictEqual(stdout.indexOf('tests 0') >= 0, true) }) + +test('reporter from node_modules', async () => { + const cwd = join(import.meta.url, '..', 'fixtures', 'ts-esm2') + await rm(path.join(cwd, 'dist'), { recursive: true, force: true }) + const { stdout } = await execa('node', [ + borp, + '--reporter=spec', + '--reporter=@reporters/silent', + '--no-typescript' + ], { + cwd + }) + + strictEqual(stdout.indexOf('tests 0') >= 0, true) +})