So I'm trying to run a tests.js for a python code I've written, everything seems fine however at the end of each line ("\n" character), the tests.js file is appending a "·" character. The file internally uses the toString() method to convert the python output to a string and then compares it with the expected string using toEqual().
My code:
def print_help():
print("""Usage :-
$ ./task add 2 hello world # Add a new item with priority 2 and text "hello world" to the list
$ ./task ls # Show incomplete priority list items sorted by priority in ascending order
$ ./task del INDEX # Delete the incomplete item with the given index
$ ./task done INDEX # Mark the incomplete item with the given index as complete
$ ./task help # Show usage
$ ./task report # Statistics""", end="")
The tests.js code:
test("prints help", () => {
let received = execSync(tasksTxtCli("help")).toString("utf8");
expect(received).toEqual(expect.stringContaining(usage));
});
I don't know what you're using for your output in Node.js, but it's likely that this isn't actually a middle dot character, but an otherwise unprintable character by your terminal emulator.
In other words, what you're seeing isn't really there. It's just that something is there.
I expect that this is a difference between \r\n and \n for newline characters. Your comparison string probably doesn't have \r\n, but the Python output probably does.
If you want to be really sure as to what it is, pipe your Python output to a file and open it up with a hex editor. Or even, just don't convert to a string and use console.log() (or util.inspect()) to see a hex representation of the binary output.
As per my solution modify your code as:
def print_help():
help="""Usage :-
$ ./task add 2 hello world # Add a new item with priority 2 and text "hello world" to the list
$ ./task ls # Show incomplete priority list items sorted by priority in ascending order
$ ./task del INDEX # Delete the incomplete item with the given index
$ ./task done INDEX # Mark the incomplete item with the given index as complete
$ ./task help # Show usage
$ ./task report # Statistics"""
sys.stdout.buffer.write(help.encode('utf8'))
In this way , the dot(.) won't appear on command line. Reference: https://github.com/nseadlc-2020/package-todo-cli-task/issues/12