Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Dec 20, 2022
1 parent 2751e68 commit 9bb6248
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/test_runner/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async function getReportersMap(reporters, destinations) {
const destination = kBuiltinDestinations.get(destinations[i]) ?? createWriteStream(destinations[i]);

// Load the test reporter passed to --test-reporter
let reporterPath = kBuiltinReporters.get(name) ?? name;
const reporterPath = kBuiltinReporters.get(name) ?? name;
const { esmLoader } = require('internal/process/esm_loader');
const { pathToFileURL } = require('internal/url');
const file = isAbsolute(reporterPath) ? pathToFileURL(reporterPath).href : reporterPath;
Expand Down
8 changes: 8 additions & 0 deletions test/fixtures/test-runner/node_modules/r-esm/index.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/fixtures/test-runner/node_modules/r-esm/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test/fixtures/test-runner/node_modules/r/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/fixtures/test-runner/node_modules/r/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions test/parallel/test-runner-reporters.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,22 @@ describe('node:test reporters', { concurrency: true }, () => {
assert.strictEqual(child.stdout.toString(), `${filename} {"test:start":5,"test:pass":2,"test:fail":3,"test:plan":3,"test:diagnostic":7}`);
});
});

it('should support a custom reporter from node_modules', async () => {
const child = spawnSync(process.execPath,
['--test', '--test-reporter', 'r', 'reporters.js'],
{ cwd: fixtures.path('test-runner') });
assert.strictEqual(child.stderr.toString(), '');
assert.strictEqual(child.stdout.toString(),
'package: r{"test:start":5,"test:pass":2,"test:fail":3,"test:plan":3,"test:diagnostic":7}');
});

it('should support a custom ESM reporter from node_modules', async () => {
const child = spawnSync(process.execPath,
['--test', '--test-reporter', 'r-esm', 'reporters.js'],
{ cwd: fixtures.path('test-runner') });
assert.strictEqual(child.stderr.toString(), '');
assert.strictEqual(child.stdout.toString(),
'package: r-esm{"test:start":5,"test:pass":2,"test:fail":3,"test:plan":3,"test:diagnostic":7}');
});
});

0 comments on commit 9bb6248

Please sign in to comment.