Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow debug receive outerHTML #292

Closed
wants to merge 1 commit into from

Conversation

antoniel
Copy link

@antoniel antoniel commented Feb 19, 2023

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

  • Allow the debug function to accept an HTML string generated by other libraries
  • Replace the debug function in /src/preview.ts with a new implementation that accepts an HTML string parameter

Fixes

  • N/A

Chores

  • N/A

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
Copy link

netlify bot commented Feb 19, 2023

Deploy Preview for jest-preview-chinese canceled.

Name Link
🔨 Latest commit c840b91
🔍 Latest deploy log https://app.netlify.com/sites/jest-preview-chinese/deploys/63f24b96471a8500081d935d

@netlify
Copy link

netlify bot commented Feb 19, 2023

Deploy Preview for jest-preview-library canceled.

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

@antoniel antoniel closed this Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant