Skip to content

stringOutput produces wrong result when a certain line is not erased from the output #1

@saurabhdaware

Description

@saurabhdaware

The CLI libraries add multiple erase line commands throughout to make the CLIs interactive. Which means, the raw string output looks something like this -

'? How old are you? › ? How old are you? › 1? How old are you? › 19✔ How old are you? … 19\n' +
          '{ value: 19 }\n' +
          '? What is your name? › ? What is your name? › s? What is your name? › sa? What is your name? › sau? What is your name? › saur? What is your name? › saura? What is your name? › saurab? What is your name? › saurabh✔ What is your name? … saurabh\n' +
          "{ value: 'saurabh' }"

This is far from the actual output that we see on screen.

In order to get the output similar to the thing we see on screen, we have to simulate the behaviour of erase_line command.

This means, every time we come across the ERASE_LINE command, we erase the output on that line.

This is the current logic of trimming the output-
https://github.com/saurabhdaware/cli-testing-library/blob/b26ed0a5e7ffdf5085472826f76900a60b678708/lib/cli-testing-library.js#L69-L71

I just move to last ERASE_LINE and consider things after that. This is however not the accurate and does not consider the scenario where we have multiple lines of outputs where a certain line is not erased.

Possible Algorithm:

  • In for loop, look for ERASE_LINE command
  • trim everything between (\n OR string start) to [ERASE_LINE]
  • return the output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions