vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
12.98k stars 1.16k forks source link

Disable screenshot file creation when getting base64 #6637

Open unional opened 3 weeks ago

unional commented 3 weeks ago

Clear and concise description of the problem

Currently, when page.screenshot({ base64: true }), the file is still being created.

I want to delegate the file creation to another code similar to jest-image-snapshot.

https://vitest.dev/guide/browser/locators.html#screenshot

Suggested solution

IMO when doing { base64: true } it should not generate the file. It should even return Promise<Buffer> like how it is done in playwright.

If we want to avoid breaking change, we can add { skipFileCreation?: true } option.

Alternative

playwright does not create the file by default:

  /**
   * The file path to save the image to. The screenshot type will be inferred from file extension. If `path` is a
   * relative path, then it is resolved relative to the current working directory. If no path is provided, the image
   * won't be saved to the disk.
   */
  path?: string;

No response

Additional context

No response

Validations

sheremet-va commented 2 weeks ago

IMO when doing { base64: true } it should not generate the file. It should even return Promise<Buffer> like how it is done in playwright.

There is no such thing as Buffer in the browser.

Currently, when page.screenshot({ base64: true }), the file is still being created

The API is universal - currently, webdriverio always creates a file. This is the main reason why it's the same across the board. I guess, technically we can have different behaviours between different providers.

unional commented 2 weeks ago

currently, webdriverio always creates a file

Can webdriverio disable the file creation? playwright default is not creating a file. IMO that is a better approach/default as the behavior is more decoupled.

Currently, per documentation the path must be a relative path, which further limits the ability to fake it by saving it to a vinyl or temp folder.

sheremet-va commented 1 week ago

Can webdriverio disable the file creation?

You are quoting the answer to your own question. It cannot. (At least, to my knowledge)