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

Strip ANSI escape codes when writing test reports to non-tty #23316

Open
magurotuna opened this issue Apr 11, 2024 · 1 comment · May be fixed by #23371
Open

Strip ANSI escape codes when writing test reports to non-tty #23316

magurotuna opened this issue Apr 11, 2024 · 1 comment · May be fixed by #23371
Labels
feat new feature (which has been agreed to/accepted) testing related to deno test and coverage

Comments

@magurotuna
Copy link
Member

Suppose we have a test file that looks like:

import { assertEquals } from "https://deno.land/std@0.217.0/assert/mod.ts";

Deno.test({
  name: "test",
  fn: () => {
    assertEquals(0, 1);
  },
});

Running deno test --junit-path junit.xml, we get the following result

<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="deno test" tests="1" failures="1" errors="0" time="0.002">
    <testsuite name="./main_test.ts" tests="1" disabled="0" errors="0" failures="1">
        <testcase name="test" classname="./main_test.ts" time="0.001" line="3" col="6">
            <failure message="Uncaught AssertionError: Values are not equal.


    �[90m�[1m[Diff]�[22m�[39m �[31m�[1mActual�[22m�[39m / �[32m�[1mExpected�[22m�[39m


�[31m�[1m-   0�[22m�[39m
�[32m�[1m+   1�[22m�[39m
">AssertionError: Values are not equal.


    �[90m�[1m[Diff]�[22m�[39m �[31m�[1mActual�[22m�[39m / �[32m�[1mExpected�[22m�[39m


�[31m�[1m-   0�[22m�[39m
�[32m�[1m+   1�[22m�[39m

  throw new AssertionError(message);
�[0m�[31m        ^�[0m
    at �[0m�[1m�[3massertEquals�[0m (�[0m�[36mhttps://deno.land/std@0.217.0/assert/assert_equals.ts�[0m:�[0m�[33m52�[0m:�[0m�[33m9�[0m)
    at �[0m�[1m�[3mfn�[0m (�[0m�[36mfile:///tmp/main_test.ts�[0m:�[0m�[33m6�[0m:�[0m�[33m5�[0m)</failure>
        </testcase>
    </testsuite>
</testsuites>

This contains ANSI escape codes, which is not really preferable. It would be nice to strip ANSI escape codes when it's writing to non-tty. This may be applicable to other types of test reporters.

@bartlomieju
Copy link
Member

Seems reasonable 👍

@bartlomieju bartlomieju added feat new feature (which has been agreed to/accepted) testing related to deno test and coverage labels Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat new feature (which has been agreed to/accepted) testing related to deno test and coverage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants