You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When creating a custom reporter, the test.result.errors[index].stack and test.result.errors[index].stackStr consist of some ANSI color codes (possibly to show color when logged in the console). However, this affects all other custom reporters that do not want to log to the console, for instance, the one I shared in the link above.
When using the GithubReporter from GithubReporter.ts, when expect failed in a test with .not.toBeCalled(), there were ANSI characters in the stack trace, whereas when the expect failed in a test with expect(a).toBe(b) there were no ANSI color codes in the stack trace.
P.S. this is reproducible only on the sample-test branch of the repository, because there is a regex to filter out ANSI codes from the stack trace on the main branch.
Test file that has ANSI colors in stack trace when there's an error:
import{beforeEach,describe,expect,test,vi}from'vitest';letsum: ()=>void;describe('Given sum() exists',()=>{beforeEach(()=>{sum=vi.fn();});describe('When sum() is called',()=>{beforeEach(()=>{sum();});test('sum() should be called',()=>{expect(sum).toBeCalled();});test('sum() should not be called',()=>{expect(sum).not.toBeCalled();});});});
Test file that does not have ANSI colors in the stack trace when there's an error:
import{beforeEach,describe,expect,test}from'vitest';importsumfrom'./sum';functionsum(a: number,b: number){returna+b;}letval: number;describe('Given sum() was called',()=>{describe('When the arguments are 1 and 1',()=>{beforeEach(()=>{val=sum(1,1);});// Passing testtest('Then the sum should be 2',()=>{expect(val).toBe(2);});// Failing testtest('Then the sum should be 3',()=>{expect(val).toBe(3);});});});
What is weird is that both of these actually show colors when these errors are logged in the console. I'm not sure if that's the vitest reporter, because seemingly, the colors (or colorful error messages, as in the image below) are not there in the stack trace logged in sum.test.ts.
Seems like we need to add more checks for displaying colors. I removed picocolors in #2828 (which will probably be extracted into its own PR), and we can do that there.
Describe the bug
When creating a custom reporter, the
test.result.errors[index].stack
andtest.result.errors[index].stackStr
consist of some ANSI color codes (possibly to show color when logged in the console). However, this affects all other custom reporters that do not want to log to the console, for instance, the one I shared in the link above.Reproduction
TLDR;
Check out this PR.
Reproduction
When using the
GithubReporter
from GithubReporter.ts, when expect failed in a test with.not.toBeCalled()
, there were ANSI characters in the stack trace, whereas when the expect failed in a test withexpect(a).toBe(b)
there were no ANSI color codes in the stack trace.P.S. this is reproducible only on the
sample-test
branch of the repository, because there is a regex to filter out ANSI codes from the stack trace on themain
branch.Test file that has ANSI colors in stack trace when there's an error:
Test file that does not have ANSI colors in the stack trace when there's an error:
What is weird is that both of these actually show colors when these errors are logged in the console. I'm not sure if that's the vitest reporter, because seemingly, the colors (or colorful error messages, as in the image below) are not there in the stack trace logged in
sum.test.ts
.System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: