Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle error as string #74

Merged
merged 2 commits into from
Sep 26, 2023
Merged

Handle error as string #74

merged 2 commits into from
Sep 26, 2023

Conversation

vitalets
Copy link
Contributor

When tap-mocha-reporter is used with native Node.js test-runner output, it receives parsed test result as follows (note error field):

{
  ok: false,
  id: 1,
  name: 'should work',
  diag: {
    duration_ms: 2.382542,
    failureType: 'testCodeFailure',
    error: 'Expected values to be strictly equal:\n\n1 !== 2', // <-- error is string not object!
    code: 'ERR_ASSERTION',
    expected: 2,
    actual: 1,
    operator: 'strictEqual',
    stack: 'TestContext.<anonymous> (file:///Users/vitalets/projects/myproject/test/calc.test.ts:9:10)\n' +
      'Test.runInAsyncScope (node:async_hooks:204:9)\n' +
      'Test.run (node:internal/test_runner/test:543:25)\n' +
      'Test.start (node:internal/test_runner/test:464:17)\n' +
      'test (node:internal/test_runner/harness:129:18)\n' +
      'file:///Users/vitalets/projects/myproject/test/calc.test.ts:5:1\n' +
      'ModuleJob.run (node:internal/modules/esm/module_job:194:25)'
  },
  fullname: '/Users/vitalets/projects/myproject/test/calc.test.ts'
}

But reporter expects error to be an object not string. That's why output does not contain error message and stack (see #72).
This PR fixes the issue by taking error message and stack from diag object directly.

@wesleytodd
Copy link

I haven't tested this, but @isaacs if this is something you could merge it would be really great. Other than this, I am having great success with the node test runner.

@isaacs
Copy link
Member

isaacs commented Sep 26, 2023

This module is due for a major refactoring to pull these report styles into tap v18 as a plugin. I'll try to work through the backlog a bit today and tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants