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

Report on the test.rejects failure not working #278

Open
KLarpen opened this issue Dec 17, 2023 · 3 comments
Open

Report on the test.rejects failure not working #278

KLarpen opened this issue Dec 17, 2023 · 3 comments

Comments

@KLarpen
Copy link

KLarpen commented Dec 17, 2023

Is your feature request related to a problem? Please describe.

I had encounter an issue when trying to look intended test fail results of Impress. Way to reproduce:

  1. Open impress folder in terminal.
  2. Open editor with file test/procedure.js
  3. In the assertion at lines 137-140 of the test metatests.testAsync('lib/procedure timeout'
  await test.rejects(
    async () => procedure.invoke({}, { waitTime: 150 }),
    new Error('Timeout of 100ms reached'),
  );

change the value of waitTime to 50. So the assertion must failed due to test configuration.
4. Run npm t
5. Instead of failed test report there is an error from reporting logic of metatest package itself (more specifically from one of its dependency tap-mocha-reporter)

Node v20.9.0 (v8 11.3.244.8-node.16):
Certificate request self-signature ok
subject=CN = localhost
lib/application ..................................... 21/21
lib/deps .............................................. 8/8
lib/procedure ....................................... 24/24
lib/procedure validate ................................ 4/4
schemas/contracts ..................................... 1/1
lib/api load ........................................ 22/22
lib/place ........................................... 18/18
schemas/config ........................................ 4/4
lib/bus ............................................. 11/11
lib/cert .............................................. 4/4
lib/code ............................................ 11/11
lib/procedure timeout ../node_modules/tap-mocha-reporter/lib/runner.js:293
    return stack.trim().split('\n').map(function (line) {
                 ^

TypeError: stack.trim is not a function
    at reviveStack (/node_modules/tap-mocha-reporter/lib/runner.js:293:18)
    at getError (/node_modules/tap-mocha-reporter/lib/runner.js:332:87)
    at emitTest (/node_modules/tap-mocha-reporter/lib/runner.js:280:17)
    at Parser.<anonymous> (/node_modules/tap-mocha-reporter/lib/runner.js:219:5)
    at Parser.emit (node:events:514:28)
    at Parser.emit (node:domain:488:12)
    at Parser.emit (/node_modules/minipass/index.js:483:23)
    at Parser.emitAssert (/node_modules/tap-parser/index.js:864:10)
    at Parser.emitResult (/node_modules/tap-parser/index.js:733:10)
    at Parser.plan (/node_modules/tap-parser/index.js:417:10)
  1. The error not only failing the report but breaking execution of subsequent test cases, e.g. 'lib/procedure validate async'.

Describe the solution you'd like

Introduce better reporters instead of tap-mocha-reporter as it was described in #265

Describe alternatives you've considered

Please propose temporary workaround. I had tried to investigate function reviveStack in /node_modules/tap-mocha-reporter/lib/runner.js:293 by adding console.debug({ stack, stackFile: stack.file }). It seems that contract of stack that the function receives has been changed and even not stable to rely on: two internal subsequent calls resulting in string and object

{
  stack: 'async ImperativeTest.func (/test/procedure.js:137:3)\n',
  stackFile: undefined
}
{
  stack: { file: '/test/procedure.js' },
  stackFile: '/test/procedure.js'
}

Unfortunately still had not found the temporary solution.

Additional context

OS: macOS 14.1.2
Node: 20.9.0, 18.18.2
Impress: 3.0.13
Metatests: 0.8.2

@KLarpen
Copy link
Author

KLarpen commented Dec 17, 2023

I had found temporary workaround.

  1. Open file /node_modules/tap-mocha-reporter/lib/runner.js
  2. Locate function reviveStack at line 286
  function reviveStack (stack) {
    if (!stack)
      return null

    return stack.trim().split('\n').map(function (line) {
      return '    at ' + line
    }).join('\n')
  }
  1. Change to
  function reviveStack (stack) {
    if (!stack)
      return null

    // TypeError: stack.trim is not a function
    // return stack.trim().split('\n').map(function (line) {
    //   return '    at ' + line
    // }).join('\n')
    // Workaround
    return stack.toString();
  }

Result of running npm t with the same setup as described above

Node v20.9.0 (v8 11.3.244.8-node.16):
Certificate request self-signature ok
subject=CN = localhost
lib/application ..................................... 21/21
lib/deps .............................................. 8/8
lib/procedure ....................................... 24/24
lib/procedure validate ................................ 4/4
schemas/contracts ..................................... 1/1
lib/api load ........................................ 22/22
lib/place ........................................... 18/18
schemas/config ........................................ 4/4
lib/bus ............................................. 11/11
lib/cert .............................................. 4/4
lib/code ............................................ 11/11
lib/static load ..................................... 11/11
lib/procedure timeout ................................. 0/2
  not ok rejects
    --- wanted                  
    +++ found                   
    -[null]                     
    +"success"                  
    message: expected to be rejected, but was resolved
    severity: fail
    type: rejects
    at:
      file: /test/procedure.js
    stack: >
      async ImperativeTest.func
      (/test/procedure.js:137:3)
  
  not ok fail
    --- wanted                  
    +++ found                   
    -[null]                     
    +"success"                  
    message: Promise rejection
    severity: fail
    type: fail
    at:
      file: /test/procedure.js
    stack: ""

lib/procedure validate async .......................... 4/4
FAILED test 14
Failed 1/15 tests, 93.33% okay

@tshemsedinov
Copy link
Member

FYI @lundibundi

@lundibundi
Copy link
Member

lundibundi commented Dec 22, 2023

Fix in tapjs/tap-mocha-reporter#79.

We can downgrade to tap-mocha-reporter@5.0.3 if that will be an issue for long.

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

No branches or pull requests

3 participants