playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Bug]: Calling execSync() in test produces extra attachment

Open vitalets opened this issue 1 year ago • 1 comments

Version

1.49.0

Steps to reproduce

Follow the steps in README: https://github.com/vitalets/playwright-issues/tree/exec-sync-output

The key point is calling execSync() in the test:

test('my test', async ({}) => {
  console.log('foo');
  execSync('echo bar', { stdio: 'inherit' });
  console.log('baz');
});

Expected behavior

Single stdout attachment containing all outputs:

foo
bar
baz

Actual behavior

There are two stdout attachments:

  1. normal expandable stdout attachment:
    foo
    baz
    
  2. binary stdout attachment

Report:

Additional context

Also tried to call execSync() without stdout: 'inherit', result is the same.

Environment

System:
    OS: macOS 13.6.9
    CPU: (8) arm64 Apple M1
    Memory: 56.22 MB / 16.00 GB
  Binaries:
    Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v20.14.0/bin/yarn
    npm: 10.9.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
    pnpm: 7.27.1 - ~/Library/pnpm/pnpm
  IDEs:
    VSCode: 1.95.3 - /usr/local/bin/code
  Languages:
    Bash: 3.2.57 - /bin/bash
  npmPackages:
    @playwright/test: 1.49.0 => 1.49.0

vitalets avatar Dec 06 '24 10:12 vitalets

Interesting! Thanks for the report.

Skn0tt avatar Dec 06 '24 17:12 Skn0tt

This seems to only happen with the HTML reporter. We concatenate all text/plain stdout chunks into one big attachment: https://github.com/microsoft/playwright/blob/a14d9750b314c26d72daa9f33598ad9d66d3e61c/packages/playwright/src/reporters/html.ts#L437-L447

The execSync output is of type application/octet-stream though, so it gets attached chunk-per-chunk. I'll see if it's safe for us to also concatenate those octet-stream chunks.

In the meantime, you can work around this by specifying encoding: "utf-8" / "ascii" in your execSync call.

Skn0tt avatar Dec 11 '24 11:12 Skn0tt