How to use the react-diff-view.parseDiff function in react-diff-view

To help you get started, we’ve selected a few react-diff-view examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla / addons-code-manager / src / utils.spec.tsx View on Github external
it('returns a flattened list of all changes', () => {
      const diff = parseDiff(diffWithDeletions)[0];
      const changes = getAllHunkChanges(diff.hunks);

      // Check a line from the first hunk:
      expect(changes.filter((c) => c.lineNumber === 2)[0].content).toEqual(
        "import { Diff, DiffProps, parseDiff } from 'react-diff-view';",
      );
      // Check a line from the second hunk:
      expect(changes.filter((c) => c.lineNumber === 24)[0].content).toEqual(
        '    console.log({ hunk });',
      );
      // Check a line from the third hunk:
      expect(changes.filter((c) => c.lineNumber === 50)[0].content).toEqual(
        '          ',
      );
    });
  });
github theforeman / foreman / webpack / assets / javascripts / react_app / components / DiffView / DiffView.js View on Github external
threshold: 30,
    markLongDistanceDiff: true,
  });

  // old,new Text
  if (patch === '') {
    const gitDiff = getDiff(oldText, newText);
    const files = parseDiff(gitDiff);
    const hunk = files[0].hunks;

    return (
      hunk && 
    );
  }
  // Patch
  const files = parseDiff(
    patch
      .split('\n')
      .slice(1)
      .join('\n')
  );
  // eslint-disable-next-line react/prop-types
  const renderFile = ({ oldRevision, newRevision, type, hunks }) => (
    
  );
github mozilla / addons-code-manager / src / components / DiffView / index.spec.tsx View on Github external
it('renders multiple inline messages', () => {
    const externalMessages = [
      // Add a message to line 9 in the first hunk.
      { line: 9, uid: 'first' },
      // Add a message to line 23 in the second hunk.
      { line: 23, uid: 'second' },
    ];

    const diff = parseDiff(diffWithDeletions)[0];
    const widgets = renderAndGetWidgets({
      diff,
      selectedMessageMap: createFakeLinterMessagesByPath({
        messages: externalMessages,
      }),
    });

    const { hunks } = diff;

    const firstWidget = renderWidget(hunks, widgets, externalMessages[0].line);
    expect(firstWidget.find(LinterMessage)).toHaveLength(1);
    expect(firstWidget.find(LinterMessage)).toHaveProp(
      'message',
      expect.objectContaining({
        uid: externalMessages[0].uid,
      }),
github mozilla / addons-code-manager / src / reducers / versions.spec.tsx View on Github external
const createFakeDiffWithChanges = (
    testHunks: TestHunkChange[][],
  ): DiffInfo => {
    // The fixture is only used to initialize some fields. All of the
    // hunks/changes will be overwritten.
    const diffSample = parseDiff(diffWithDeletions)[0];

    const hunks = testHunks.map((hunk) => {
      return {
        changes: hunk.map((change) => {
          return {
            content: 'the content of the change is irrelevant to the tests',
            isDelete: change.type === 'delete',
            isInsert: change.type === 'insert',
            isNormal: change.type === 'normal',
            lineNumber: change.lineNumber,
            oldLineNumber:
              change.type === 'normal' ? change.lineNumber : undefined,
            type: change.type,
          };
        }),
        content: 'the content of hunks is irrelevant to the tests',
github argoproj / argo-cd / ui / src / app / applications / components / application-resources-diff / application-resources-diff.tsx View on Github external
};
                })
                .filter(i => !i.hook)
                .filter(i => i.a !== i.b)
                .map(i => {
                    const context = pref.appDetails.compactDiff ? 2 : Number.MAX_SAFE_INTEGER;
                    // react-diff-view, awesome as it is, does not accept unidiff format, you must add a git header section
                    return `diff --git a/${i.name} b/${i.name}
index 6829b8a2..4c565f1b 100644
${formatLines(diffLines(i.a, i.b), {context, aname: `a/${name}}`, bname: `b/${i.name}`})}`;
                })
                .join('\n');
            // assume that if you only have one file, we don't need the file path
            const whiteBox = props.states.length > 1 ? 'white-box' : '';
            const showPath = props.states.length > 1;
            const files = parseDiff(diffText);
            const viewType = pref.appDetails.inlineDiff ? 'unified' : 'split';
            return (
                <div>
                    <div>
                        
                                services.viewPreferences.updatePreferences({
                                    appDetails: {
                                        ...pref.appDetails,
                                        compactDiff: !pref.appDetails.compactDiff
                                    }
                                })
                            }
                        /&gt;</div></div>
github mozilla / addons-code-manager / src / components / DiffView / index.spec.tsx View on Github external
it('tokenizes the hunks to add syntax highlighting', () => {
    const diff = parseDiff(multipleDiff)[0];
    const mimeType = 'application/javascript';
    const _codeCanBeHighlighted = jest.fn().mockReturnValue(true);
    const _tokenize = jest.fn();

    renderWithLinterProvider({
      _codeCanBeHighlighted,
      _tokenize,
      diff,
      mimeType,
    });

    expect(_tokenize).toHaveBeenCalledWith(diff.hunks, {
      highlight: true,
      language: getLanguageFromMimeType(mimeType),
      refractor: expect.any(Object),
    });
github mozilla / addons-code-manager / stories / DiffView.stories.tsx View on Github external
() => {
      return render({ diff: parseDiff(minifiedDiff)[0] });
    },
    getParams(),
github mozilla / addons-code-manager / stories / DiffView.stories.tsx View on Github external
() => {
      return render({ diff: parseDiff(diffWithDeletions)[0] });
    },
    getParams(),
github mozilla / addons-code-manager / src / components / DiffView / index.spec.tsx View on Github external
const render = ({
    _codeCanBeHighlighted = jest.fn(),
    enableCommenting = true,
    history = createFakeHistory(),
    location = createFakeLocation(),
    ...props
  }: RenderParams = {}) =&gt; {
    const shallowOptions = createContextWithFakeRouter({ history, location });

    return shallowUntilTarget(
      ,
      DiffViewBase,
      { shallowOptions },
    );
  };
github react-native-community / upgrade-helper / src / components / common / DiffViewer.js View on Github external
const fetchDiff = async () => {
      setLoading(true)

      const response = await (await fetch(
        getDiffPatchURL({ fromVersion, toVersion })
      )).text()

      setDiff(
        parseDiff(response).sort(({ newPath }) =>
          newPath.includes('package.json') ? -1 : 1
        )
      )

      resetCompletedDiff()

      setLoading(false)
    }