|
| 1 | +/* eslint-disable */ |
| 2 | + |
| 3 | +import { expect } from 'chai'; |
| 4 | + |
| 5 | +import { convertRelativeImagePathsToAbsoluteInReadme } from '../src/git'; |
| 6 | + |
| 7 | +describe('convertRelativeImagePathsToAbsoluteInReadme()', () => { |
| 8 | + it('works correctly for Github repo with explicit branch name', () => { |
| 9 | + const testMarkdown = ` |
| 10 | + # Heading |
| 11 | +  |
| 12 | +  |
| 13 | + `; |
| 14 | + const expectedResult = ` |
| 15 | + # Heading |
| 16 | +  |
| 17 | +  |
| 18 | + `; |
| 19 | + |
| 20 | + expect(convertRelativeImagePathsToAbsoluteInReadme({ |
| 21 | + readme: testMarkdown, |
| 22 | + gitRepoUrl: 'git@github.com:apify/test-repo.git', |
| 23 | + gitBranchName: 'main', |
| 24 | + })).to.eql(expectedResult) |
| 25 | + }); |
| 26 | + |
| 27 | + it('works correctly for Bitbucket repo with explicit branch name', () => { |
| 28 | + const testMarkdown = ` |
| 29 | + # Heading |
| 30 | +  |
| 31 | +  |
| 32 | + `; |
| 33 | + const expectedResult = ` |
| 34 | + # Heading |
| 35 | +  |
| 36 | +  |
| 37 | + `; |
| 38 | + expect(convertRelativeImagePathsToAbsoluteInReadme({ |
| 39 | + readme: testMarkdown, |
| 40 | + gitRepoUrl: 'git@bitbucket.org:apify/test-repo.git', |
| 41 | + gitBranchName: 'main', |
| 42 | + })).to.eql(expectedResult) |
| 43 | + }); |
| 44 | + |
| 45 | + it('works correctly for Gitlab repo with explicit branch name', () => { |
| 46 | + const testMarkdown = ` |
| 47 | + # Heading |
| 48 | +  |
| 49 | +  |
| 50 | + `; |
| 51 | + const expectedResult = ` |
| 52 | + # Heading |
| 53 | +  |
| 54 | +  |
| 55 | + `; |
| 56 | + |
| 57 | + expect(convertRelativeImagePathsToAbsoluteInReadme({ |
| 58 | + readme: testMarkdown, |
| 59 | + gitRepoUrl: 'git@gitlab.com:apify/test-repo.git', |
| 60 | + gitBranchName: 'main', |
| 61 | + })).to.eql(expectedResult) |
| 62 | + }); |
| 63 | + |
| 64 | + it('works correctly for Github repo with branch name in hash', () => { |
| 65 | + const testMarkdown = ` |
| 66 | + # Heading |
| 67 | +  |
| 68 | +  |
| 69 | + `; |
| 70 | + const expectedResult = ` |
| 71 | + # Heading |
| 72 | +  |
| 73 | +  |
| 74 | + `; |
| 75 | + |
| 76 | + expect(convertRelativeImagePathsToAbsoluteInReadme({ |
| 77 | + readme: testMarkdown, |
| 78 | + gitRepoUrl: 'git@github.com:apify/test-repo.git#my-awesome-branch', |
| 79 | + })).to.eql(expectedResult) |
| 80 | + }); |
| 81 | + |
| 82 | + it('works correctly for Github repo without explicit branch name', () => { |
| 83 | + const testMarkdown = ` |
| 84 | + # Heading |
| 85 | +  |
| 86 | +  |
| 87 | + `; |
| 88 | + const expectedResult = ` |
| 89 | + # Heading |
| 90 | +  |
| 91 | +  |
| 92 | + `; |
| 93 | + |
| 94 | + expect(convertRelativeImagePathsToAbsoluteInReadme({ |
| 95 | + readme: testMarkdown, |
| 96 | + gitRepoUrl: 'git@github.com:apify/test-repo.git', |
| 97 | + })).to.eql(expectedResult) |
| 98 | + }); |
| 99 | + |
| 100 | + it('works correctly for Github repo with explicit branch name and <img src=... /> tags', () => { |
| 101 | + const testMarkdown = ` |
| 102 | + # Heading |
| 103 | +  |
| 104 | +  |
| 105 | + <img src='./relative-path-to-img.jpg' /> |
| 106 | + <img src='./relative-path-to-img.jpg' alt='Some alt text'/> |
| 107 | + <img alt='Some alt text' src='./relative-path-to-img.jpg' /> |
| 108 | + <img alt='Some alt text' src='./relative-path-to-img.jpg' width="500"/> |
| 109 | + <img src="./relative-path-to-img.jpg" /> |
| 110 | + <img src="./relative-path-to-img.jpg" alt="Some alt text"/> |
| 111 | + <img alt="Some alt text" src="./relative-path-to-img.jpg" /> |
| 112 | + <img alt="Some alt text" src="./relative-path-to-img.jpg" width="500"/> |
| 113 | + `; |
| 114 | + const expectedResult = ` |
| 115 | + # Heading |
| 116 | +  |
| 117 | +  |
| 118 | + <img src='https://raw.githubusercontent.com/apify/test-repo/master/relative-path-to-img.jpg' /> |
| 119 | + <img src='https://raw.githubusercontent.com/apify/test-repo/master/relative-path-to-img.jpg' alt='Some alt text'/> |
| 120 | + <img alt='Some alt text' src='https://raw.githubusercontent.com/apify/test-repo/master/relative-path-to-img.jpg' /> |
| 121 | + <img alt='Some alt text' src='https://raw.githubusercontent.com/apify/test-repo/master/relative-path-to-img.jpg' width="500"/> |
| 122 | + <img src="https://raw.githubusercontent.com/apify/test-repo/master/relative-path-to-img.jpg" /> |
| 123 | + <img src="https://raw.githubusercontent.com/apify/test-repo/master/relative-path-to-img.jpg" alt="Some alt text"/> |
| 124 | + <img alt="Some alt text" src="https://raw.githubusercontent.com/apify/test-repo/master/relative-path-to-img.jpg" /> |
| 125 | + <img alt="Some alt text" src="https://raw.githubusercontent.com/apify/test-repo/master/relative-path-to-img.jpg" width="500"/> |
| 126 | + `; |
| 127 | + console.log(convertRelativeImagePathsToAbsoluteInReadme({ |
| 128 | + readme: testMarkdown, |
| 129 | + gitRepoUrl: 'git@github.com:apify/test-repo.git', |
| 130 | + })); |
| 131 | + expect(convertRelativeImagePathsToAbsoluteInReadme({ |
| 132 | + readme: testMarkdown, |
| 133 | + gitRepoUrl: 'git@github.com:apify/test-repo.git', |
| 134 | + })).to.eql(expectedResult) |
| 135 | + }); |
| 136 | + |
| 137 | + it('works correctly for unknown repo', () => { |
| 138 | + const testMarkdown = ` |
| 139 | + # Heading |
| 140 | +  |
| 141 | +  |
| 142 | + `; |
| 143 | + expect(convertRelativeImagePathsToAbsoluteInReadme({ |
| 144 | + readme: testMarkdown, |
| 145 | + gitRepoUrl: 'git@some-unknown-git-site.com:apify/test-repo.git', |
| 146 | + })).to.eql(testMarkdown) |
| 147 | + }); |
| 148 | + |
| 149 | +}); |
0 commit comments