|
1 | 1 | import { expect } from 'chai'; |
2 | 2 | import 'mocha'; |
3 | | -import { tryGetResolvableLocation } from '../../src/pure/bqrs-utils'; |
| 3 | +import { tryGetRemoteLocation, tryGetResolvableLocation } from '../../src/pure/bqrs-utils'; |
4 | 4 |
|
5 | 5 | describe('processing string locations', function() { |
6 | 6 | it('should detect Windows whole-file locations', function() { |
@@ -32,3 +32,79 @@ describe('processing string locations', function() { |
32 | 32 | } |
33 | 33 | }); |
34 | 34 | }); |
| 35 | + |
| 36 | +describe('getting links to remote (GitHub) locations', function() { |
| 37 | + it('should return undefined if resolvableLocation is undefined', function() { |
| 38 | + const loc = 'not a location'; |
| 39 | + const fileLinkPrefix = ''; |
| 40 | + const sourceLocationPrefix = ''; |
| 41 | + |
| 42 | + const link = tryGetRemoteLocation(loc, fileLinkPrefix, sourceLocationPrefix); |
| 43 | + |
| 44 | + expect(link).to.be.undefined; |
| 45 | + }); |
| 46 | + |
| 47 | + it('should return undefined if resolvableLocation has the wrong format', function() { |
| 48 | + const loc = { |
| 49 | + uri: 'file:/path/to/file.ext', |
| 50 | + startLine: 194, |
| 51 | + startColumn: 18, |
| 52 | + endLine: 237, |
| 53 | + endColumn: 1, |
| 54 | + }; |
| 55 | + const fileLinkPrefix = ''; |
| 56 | + const sourceLocationPrefix = '/home/foo/bar'; |
| 57 | + |
| 58 | + const link = tryGetRemoteLocation(loc, fileLinkPrefix, sourceLocationPrefix); |
| 59 | + |
| 60 | + expect(link).to.be.undefined; |
| 61 | + }); |
| 62 | + |
| 63 | + it('should return a remote file ref if the sourceLocationPrefix and resolvableLocation match up', function() { |
| 64 | + const loc = { |
| 65 | + uri: 'file:/home/foo/bar/path/to/file.ext', |
| 66 | + startLine: 194, |
| 67 | + startColumn: 18, |
| 68 | + endLine: 237, |
| 69 | + endColumn: 1, |
| 70 | + }; |
| 71 | + const fileLinkPrefix = 'https://github.com/owner/repo/blob/sha1234'; |
| 72 | + const sourceLocationPrefix = '/home/foo/bar'; |
| 73 | + |
| 74 | + const link = tryGetRemoteLocation(loc, fileLinkPrefix, sourceLocationPrefix); |
| 75 | + |
| 76 | + expect(link).to.eql('https://github.com/owner/repo/blob/sha1234/path/to/file.ext#L194-L237'); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should return undefined if the sourceLocationPrefix is missing and resolvableLocation doesn\'t match the default format', function() { |
| 80 | + const loc = { |
| 81 | + uri: 'file:/home/foo/bar/path/to/file.ext', |
| 82 | + startLine: 194, |
| 83 | + startColumn: 18, |
| 84 | + endLine: 237, |
| 85 | + endColumn: 1, |
| 86 | + }; |
| 87 | + const fileLinkPrefix = 'https://github.com/owner/repo/blob/sha1234'; |
| 88 | + const sourceLocationPrefix = ''; |
| 89 | + |
| 90 | + const link = tryGetRemoteLocation(loc, fileLinkPrefix, sourceLocationPrefix); |
| 91 | + |
| 92 | + expect(link).to.eql(undefined); |
| 93 | + }); |
| 94 | + |
| 95 | + it('should return a remote file ref if the sourceLocationPrefix is missing, but the resolvableLocation matches the default format', function() { |
| 96 | + const loc = { |
| 97 | + uri: 'file:/home/runner/work/foo/bar/path/to/file.ext', |
| 98 | + startLine: 194, |
| 99 | + startColumn: 18, |
| 100 | + endLine: 237, |
| 101 | + endColumn: 1, |
| 102 | + }; |
| 103 | + const fileLinkPrefix = 'https://github.com/owner/repo/blob/sha1234'; |
| 104 | + const sourceLocationPrefix = ''; |
| 105 | + |
| 106 | + const link = tryGetRemoteLocation(loc, fileLinkPrefix, sourceLocationPrefix); |
| 107 | + |
| 108 | + expect(link).to.eql('https://github.com/owner/repo/blob/sha1234/path/to/file.ext#L194-L237'); |
| 109 | + }); |
| 110 | +}); |
0 commit comments