SBoudrias/Inquirer.js

stdout trim issue in tests

Bartheleway opened this issue · 3 comments

Hi,

I'm trying to write a plugin for inquirer and while writing tests I found a weird issue.

All my tests are running fine on Github actions but fails when running on my computer (Windows).

It seems that long lines are truncated to 80 caracters and if ends with a space are truncated in Github actions but not in Windows Powershell.

New test in input.test.mts

it('handle long question', async () => {
  const { answer, events, getScreen } = await render(input, {
    message: 'This is a very_very_very_very_very_very_very_very_very_very_very_very_very long question',
  });

  expect(getScreen()).toMatchInlineSnapshot([
    '"? This is a very_very_very_very_very_very_very_very_very_very_very_very_very',
    'long question"'
  ].join('\n'));
});

How should I workaround that?

Best regards,
Barthélemy

Ohhh interesting. My educated guess is that cli-width returns a different value between windows/linux in this context. I don't have a windows machine, so I would really appreciate it if you could test it out and report what you find!

I'm not sure how we could automatically make this consistent from @inquirer/testing. Mocks are unlikely to work since they're now test framework agnostic, and CLI_WIDTH env variable would need to be set from outside.

At the very least, will add a note to the documentation.

I changed the issue after realising it was just a trim issue more than a width issue.