Is there a way to turn off syntax highlighting in testing-library

358 Views Asked by At

I am using @testing-library/vue and run the tests within a build step of Sublime Text. The error output uses prettyDom and isn't very legible in the output window:

Example Output in Build Results window:

     TestingLibraryElementError: Unable to find a label with the text of: /val1/

[36m<div[39m
  [33mclass[39m=[32m"Cell"[39m
  [33mdata-v-1cdb88a0[39m=[32m""[39m
  [33mstyle[39m=[32m"width: 40%;"[39m
[36m>[39m
  [36m<div[39m
    [33mclass[39m=[32m"Label"[39m
    [33mdata-v-1cdb88a0[39m=[32m""[39m
  [36m>[39m
    [0mTest Cat #1[0m
  [36m</div>[39m
  [36m<div[39m
    [33mattrs[39m=[32m"[object Object]"[39m
    [33mdata-v-088d7313[39m=[32m""[39m
    [33mdata-v-1cdb88a0[39m=[32m""[39m
    [33mform[39m=[32m"[object Object]"[39m
    [33mon[39m=[32m"[object Object]"[39m
    [33mprops[39m=[32m"[object Object]"[39m

Is there a way to turn off the syntax highlighting with an environment variable like you can to extend the output length?

4

There are 4 best solutions below

0
On BEST ANSWER

The apparent answer is to get Sublime Text to display the colors in the build window by using the ANSIescape plugin:

https://forum.sublimetext.com/t/ansi-color-codes-in-build-output/11296/16 https://packagecontrol.io/packages/ANSIescape

0
On

You can set the COLORS environment variable to false to turn off colourisation. See https://testing-library.com/docs/dom-testing-library/api-debugging/

Although your question relates to the build results window in Sublime, this is a common problem in other places where the colour codes make it hard to see the actual debug output (in my case a Jenkins console output when tests fail).

1
On

prettyDOM takes the same options as pretty-format. One of those options is "highlight". In pretty-format it seems to be false by default, but in prettyDOM I found it's true by default. You can disable it like this:

prettyDOM(myDom, undefined, {highlight: false})
1
On

Syntax highlighting is handled by the editor displaying the text.

In Sublime Text you can effectively remove – turn off if you like – the syntax highlighting of the current file / buffer by changing the syntax to Plain Text.

You can do that by choosing Plain Text after clicking on the active syntax name on the right of the Status Bar or from the View --> Syntax menu, or by opening the Command Palette and selecting the Set Syntax: Plain Text command.