nvh95 / jest-preview

Debug your Jest tests. Effortlessly.🛠🖼
https://www.jest-preview.com
MIT License
2.34k stars 76 forks source link

feat: allow debug receive outerHTML #292

Closed antoniel closed 11 months ago

antoniel commented 1 year ago

Summary/Motivation (TLDR;)

This PR adds a new feature to the Jest Preview library that allows developers to pass HTML output generated by other libraries to the debug function. Specifically, this PR replaces the current implementation of the debug function in /src/preview.ts with a new function that accepts an HTML string as a parameter. This makes it possible for developers to use other libraries (such as react-native-to-jest-preview) to generate the HTML output for Jest Preview.

Related issues

Features

Fixes

Chores

Changes Made

This PR modifies the /src/preview.ts file to add support for passing an HTML string to the debug function. Specifically, the debug function has been replaced with a new function that accepts an outerHTML parameter. If the parameter is not provided, the function falls back to the previous behavior of using document.documentElement.outerHTML.

Here is the specific change that was made:


- export function debug(): void {
+ export function debug(outerHTML = document.documentElement.outerHTML): void {
    if (!fs.existsSync(CACHE_FOLDER)) {
      fs.mkdirSync(CACHE_FOLDER, {
        recursive: true,
      });
    }

    fs.writeFileSync(
      path.join(CACHE_FOLDER, 'index.html'),
-     document.documentElement.outerHTML,
+     outerHTML,
    );
  }
netlify[bot] commented 1 year ago

Deploy Preview for jest-preview-chinese canceled.

Name Link
Latest commit c840b91d18ab984c59d5608567a404d5d027014f
Latest deploy log https://app.netlify.com/sites/jest-preview-chinese/deploys/63f24b96471a8500081d935d
netlify[bot] commented 1 year ago

Deploy Preview for jest-preview-library canceled.

Name Link
Latest commit c840b91d18ab984c59d5608567a404d5d027014f
Latest deploy log https://app.netlify.com/sites/jest-preview-library/deploys/63f24b969d944600084dc97d