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

test-runner: Assert stack trace is stripped when used within test #48840

Closed
Ethan-Arrowood opened this issue Jul 19, 2023 · 5 comments
Closed

Comments

@Ethan-Arrowood
Copy link
Contributor

Version

20.3.1

Platform

Darwin Ethans-MBP 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun 8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64

Subsystem

test-runner

What steps will reproduce the bug?

Clone: https://github.com/Ethan-Arrowood/node-test-runner-assert-stack-trace-issue

Run: npm run expected

Then: npm run actual

See difference.

Expected:

❯ npm run expected

> expected
> node expected.js

AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:

0 !== 1

    at err (file:///Users/ethanarrowood/Documents/github/node-test-runner-assert-stack-trace/expected.js:5:16)
    at file:///Users/ethanarrowood/Documents/github/node-test-runner-assert-stack-trace/expected.js:11:9
    at ModuleJob.run (node:internal/modules/esm/module_job:192:25)
    at async DefaultModuleLoader.import (node:internal/modules/esm/loader:246:24)
    at async loadESM (node:internal/process/esm_loader:40:7)
    at async handleMainPromise (node:internal/modules/run_main:66:12)

Actual:

❯ npm run actual

> actual
> node --test --test-reporter=./reporter.cjs test.js

Error [ERR_TEST_FAILURE]: Expected values to be strictly equal:

0 !== 1

How often does it reproduce? Is there a required condition?

Any assert failure within a test block causes issue.

What is the expected behavior? Why is that the expected behavior?

I expect to get the complete stack trace from assert in my test reporter

What do you see instead?

Incomplete stack trace

Additional information

No response

@Ethan-Arrowood
Copy link
Contributor Author

Also happens with

describe('tests', () => {
    it('should fail', () => {
        assert.strictEqual(0, 1);
    })
})

@Ethan-Arrowood
Copy link
Contributor Author

I think it might be this line:

hideInternalStackFrames(this);

causing the problem

@Ethan-Arrowood
Copy link
Contributor Author

But also, this may not be a bug and is instead working as intended. I've noticed that the original error is available as error.cause. This solves the original issue; albeit a little confusing. Maybe all that is necessary is a documentation update.

@cjihrig
Copy link
Contributor

cjihrig commented Jul 19, 2023

The ERR_TEST_FAILURE error type is mostly a wrapper that the test runner uses. The built in reporter unwraps it here. Your reporter should probably do something similar.

Changing the error type to unwrap it in core would be a breaking change at this point (but could technically still be done). I think the docs are wrong too, as they currently state:

The error thrown by the test.

But this appears to be the wrapped error.

@Ethan-Arrowood
Copy link
Contributor Author

Yeah sounds good. I'm at the same conclusion now myself after tinkering with it in core a bit. I will send a docs update to close out this issue

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

2 participants