cypress icon indicating copy to clipboard operation
cypress copied to clipboard

fix: keep spaces in formatted output in test runner

Open melkstam opened this issue 3 years ago • 2 comments

  • Closes #23679

User facing changelog

Fixes issue where spaces on newlines weren't kept in the test runner

Additional details

The solution depends on tricking the markdown renderer into keeping any spaces by using the HTML entity   (a space). This will make it keep those, instead of disregarding it.

Steps to test

This is an example (taken from #23679) to reproduce.

it.only('fail to format in test runner', { retries: 0 }, () => {
  Cypress.on('fail', (error, runnable) => {
    throw {
      ...error,
      message: `Failed to assert  event.\n\nExpectedValue:**${JSON.stringify(
          error.expected,
          null,
          4
        )}** \nActual args: **${JSON.stringify(error.actual, null, 4)}** \n
      `,
    };
  });

  cy.wrap({
    category: 'resources',
    name: 'action',
    label: 'copy_clipboard',
    target: 'keyboard',
    location: {
      title: 'favorites',
    },
    search: {
      clientSearchId: 'favorites',
      sessionId: 'favorites',
    },
    resources: {
      message: 'match(undefined)',
    },
    jsonData: {
      'action.trigger': 'command_bar',
    },
  }).should('deep.equal', {
    category: 'resources',
    name: 'action',
    target: 'keyboard',
    label: 'copy_clipboard',
    location: {
      title: 'favorites',
    },
    resources: [{
      id: 'UgfdGiIVw7NklNbHWSO-fw',
      list: 'favorites',
      appId: 'mockapp',
      type: 'mockapp:item',
      position: 0,
      linkId: '631483cead6377c7a8ef5c2e',
    }, ],
    jsonData: {
      'action.trigger': 'command_bar',
    },
  });
});

How has the user experience changed?

Before before

After after

PR Tasks

  • [x] Have tests been added/updated?
  • [ ] Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • [ ] Has a PR for user-facing changes been opened in cypress-documentation?
  • [ ] Have API changes been updated in the type definitions?

melkstam avatar Nov 15 '22 08:11 melkstam

Thanks for taking the time to open a PR!

cypress-bot[bot] avatar Nov 15 '22 08:11 cypress-bot[bot]

I like this! Will approve once I have a chance to pull it down and test.

marktnoonan avatar Nov 15 '22 19:11 marktnoonan

Thank you for your patience with our test failures - we've been working pretty heavily on stabilizing CI with 12.x, so here's hoping this latest merge of develop is the charm.

BlueWinds avatar Dec 08 '22 18:12 BlueWinds

Looks like we do have one set of genuine failures, https://app.circleci.com/pipelines/github/cypress-io/cypress/47068/workflows/85b8f7a4-c7db-421a-92f4-9ce84e0cb8b5/jobs/1971826.

Specifically, these tests https://github.com/cypress-io/cypress/blob/develop/packages/app/cypress/e2e/runner/retries.ui.cy.ts#L325 are failing because it's asserting that the replaced text (with text like { retries: 2 }) matches the base text (with text like { retries: 2 }). Probably need to either decode the string before asserting on it, or encode the string it's asserted against.

BlueWinds avatar Dec 08 '22 22:12 BlueWinds

@melkstam are you able to take a look at these failures?

emilyrohrbough avatar Dec 27 '22 17:12 emilyrohrbough

@melkstam are you able to take a look at these failures?

Yes, I will look at it!

melkstam avatar Jan 06 '23 12:01 melkstam