Skip to content
Snippets Groups Projects
Select Git revision
  • e4dbd4ad491f656aaa7f9da9d4dae2c18622a1e6
  • main default protected
  • renovate/main-docs-renovate-renovate-41.x
  • renovate/main-ghcr.io-renovatebot-base-image-11.x
  • renovate/main-sindresorhus-is-7.x
  • renovate/main-renovatebot-detect-tools-1.x
  • refactor/pin-new-value
  • fix/user-agent
  • feat/37517-base64-private-key
  • next
  • feat/gnupg
  • fix/36615b-branch-reuse-no-cache
  • chore/punycode
  • feat/36219--git-x509-signing
  • feat/structured-logger
  • hotfix/39.264.1
  • feat/skip-dangling
  • gh-readonly-queue/next/pr-36034-7a061c4ca1024a19e2c295d773d9642625d1c2be
  • hotfix/39.238.3
  • refactor/gitlab-auto-approve
  • feat/template-strings
  • 41.122.3
  • 41.122.2
  • 41.122.1
  • 41.122.0
  • 41.121.4
  • 41.121.3
  • 41.121.2
  • 41.121.1
  • 41.121.0
  • 41.120.0
  • 41.119.6
  • 41.119.5
  • 41.119.4
  • 41.119.3
  • 41.119.2
  • 41.119.1
  • 41.119.0
  • 41.118.2
  • 41.118.1
  • 41.118.0
41 results

massage-markdown-links.spec.ts

Blame
  • user avatar
    Rhys Arkins authored and GitHub committed
    9a1d98cc
    History
    massage-markdown-links.spec.ts 6.33 KiB
    import { massageMarkdownLinks } from './massage-markdown-links';
    
    describe('modules/platform/github/massage-markdown-links', () => {
      it('performs multiple replacements', () => {
        const input = [
          'Link [foo/bar#1](https://github.com/foo/bar/pull/1) points to https://github.com/foo/bar/pull/1.',
          'URL https://github.com/foo/bar/pull/1 becomes [foo/bar#1](https://github.com/foo/bar/pull/1).',
        ].join('\n');
        const res = massageMarkdownLinks(input);
        expect(res).toEqual(
          [
            'Link [foo/bar#1](https://togithub.com/foo/bar/pull/1) points to [https://github.com/foo/bar/pull/1](https://togithub.com/foo/bar/pull/1).',
            'URL [https://github.com/foo/bar/pull/1](https://togithub.com/foo/bar/pull/1) becomes [foo/bar#1](https://togithub.com/foo/bar/pull/1).',
          ].join('\n')
        );
      });
    
      test.each`
        input
        ${'github.com'}
        ${'github.com/foo/bar'}
        ${'github.com/foo/bar/'}
        ${'github.com/foo/bar/discussions'}
        ${'github.com/foo/bar/issues'}
        ${'github.com/foo/bar/pull'}
        ${'github.com/foo/bar/discussions/'}
        ${'github.com/foo/bar/issues/'}
        ${'github.com/foo/bar/pull/'}
        ${'www.github.com'}
        ${'www.github.com/foo/bar'}
        ${'www.github.com/foo/bar/'}
        ${'www.github.com/foo/bar/discussions'}
        ${'www.github.com/foo/bar/issues'}
        ${'www.github.com/foo/bar/pull'}
        ${'www.github.com/foo/bar/discussions/'}
        ${'www.github.com/foo/bar/issues/'}
        ${'www.github.com/foo/bar/pull/'}
        ${'https://github.com'}
        ${'https://github.com/foo/bar'}
        ${'https://github.com/foo/bar/'}
        ${'https://github.com/foo/bar/discussions'}
        ${'https://github.com/foo/bar/issues'}
        ${'https://github.com/foo/bar/pull'}
        ${'https://github.com/foo/bar/discussions/'}
        ${'https://github.com/foo/bar/issues/'}
        ${'https://github.com/foo/bar/pull/'}
        ${'api.github.com'}
        ${'togithub.com'}
        ${'www.togithub.com'}
        ${'https://togithub.com/foo/bar/releases/tag/v0.20.3'}
        ${'https://togithub.com/foo/bar/compare/v0.20.2...v0.20.3'}
      `('Unchanged: $input', ({ input }: { input: string }) => {
        const inputText = `Foo ${input}, bar.`;
        expect(massageMarkdownLinks(inputText)).toEqual(inputText);
    
        const inputLink = `[foobar](${input})`;
        expect(massageMarkdownLinks(inputLink)).toEqual(inputLink);
      });
    
      test.each`
        input                                                                                     | output
        ${'github.com/foo/bar/discussions/1'}                                                     | ${'[github.com/foo/bar/discussions/1](togithub.com/foo/bar/discussions/1)'}
        ${'github.com/foo/bar/issues/1'}                                                          | ${'[github.com/foo/bar/issues/1](togithub.com/foo/bar/issues/1)'}
        ${'github.com/foo/bar/pull/1'}                                                            | ${'[github.com/foo/bar/pull/1](togithub.com/foo/bar/pull/1)'}
        ${'github.com/Foo/bar/pull/1'}                                                            | ${'[github.com/Foo/bar/pull/1](togithub.com/Foo/bar/pull/1)'}
        ${'www.github.com/foo/bar/discussions/1'}                                                 | ${'[www.github.com/foo/bar/discussions/1](www.togithub.com/foo/bar/discussions/1)'}
        ${'www.github.com/foo/bar/issues/1'}                                                      | ${'[www.github.com/foo/bar/issues/1](www.togithub.com/foo/bar/issues/1)'}
        ${'www.github.com/foo/bar/pull/1'}                                                        | ${'[www.github.com/foo/bar/pull/1](www.togithub.com/foo/bar/pull/1)'}
        ${'https://github.com/foo/bar/discussions/1'}                                             | ${'[https://github.com/foo/bar/discussions/1](https://togithub.com/foo/bar/discussions/1)'}
        ${'https://github.com/foo/bar/issues/1'}                                                  | ${'[https://github.com/foo/bar/issues/1](https://togithub.com/foo/bar/issues/1)'}
        ${'https://github.com/foo/bar/pull/1'}                                                    | ${'[https://github.com/foo/bar/pull/1](https://togithub.com/foo/bar/pull/1)'}
        ${'https://github.com/foo/bar/discussions/1#comment-123'}                                 | ${'[https://github.com/foo/bar/discussions/1#comment-123](https://togithub.com/foo/bar/discussions/1#comment-123)'}
        ${'https://github.com/foo/bar/issues/1#comment-123'}                                      | ${'[https://github.com/foo/bar/issues/1#comment-123](https://togithub.com/foo/bar/issues/1#comment-123)'}
        ${'https://github.com/foo/bar/pull/1#comment-123'}                                        | ${'[https://github.com/foo/bar/pull/1#comment-123](https://togithub.com/foo/bar/pull/1#comment-123)'}
        ${'[github.com/foo/bar/discussions/1](github.com/foo/bar/discussions/1)'}                 | ${'[github.com/foo/bar/discussions/1](togithub.com/foo/bar/discussions/1)'}
        ${'[github.com/foo/bar/issues/1](github.com/foo/bar/issues/1)'}                           | ${'[github.com/foo/bar/issues/1](togithub.com/foo/bar/issues/1)'}
        ${'[github.com/foo/bar/pull/1](github.com/foo/bar/pull/1)'}                               | ${'[github.com/foo/bar/pull/1](togithub.com/foo/bar/pull/1)'}
        ${'[www.github.com/foo/bar/discussions/1](www.github.com/foo/bar/discussions/1)'}         | ${'[www.github.com/foo/bar/discussions/1](www.togithub.com/foo/bar/discussions/1)'}
        ${'[www.github.com/foo/bar/issues/1](www.github.com/foo/bar/issues/1)'}                   | ${'[www.github.com/foo/bar/issues/1](www.togithub.com/foo/bar/issues/1)'}
        ${'[www.github.com/foo/bar/pull/1](www.github.com/foo/bar/pull/1)'}                       | ${'[www.github.com/foo/bar/pull/1](www.togithub.com/foo/bar/pull/1)'}
        ${'[https://github.com/foo/bar/discussions/1](https://github.com/foo/bar/discussions/1)'} | ${'[https://github.com/foo/bar/discussions/1](https://togithub.com/foo/bar/discussions/1)'}
        ${'[https://github.com/foo/bar/issues/1](https://github.com/foo/bar/issues/1)'}           | ${'[https://github.com/foo/bar/issues/1](https://togithub.com/foo/bar/issues/1)'}
        ${'[https://github.com/foo/bar/pull/1](https://github.com/foo/bar/pull/1)'}               | ${'[https://github.com/foo/bar/pull/1](https://togithub.com/foo/bar/pull/1)'}
      `(
        '$input -> $output',
        ({ input, output }: { input: string; output: string }) => {
          expect(massageMarkdownLinks(input)).toEqual(output);
        }
      );
    });