github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/util/baseurl.spec.ts (about) 1 import basename from './baseurl'; 2 3 function checkSelector(selector: string) { 4 if (selector !== 'meta[name="pyroscope-base-url"]') { 5 throw new Error('Wrong selector'); 6 } 7 } 8 describe('baseurl', () => { 9 describe('no baseURL meta tag set', () => { 10 it('returns undefined', () => { 11 const got = basename(); 12 13 expect(got).toBe(undefined); 14 }); 15 }); 16 17 describe('baseURL meta tag set', () => { 18 describe('no content', () => { 19 beforeEach(() => { 20 jest 21 .spyOn(document, 'querySelector') 22 .mockImplementationOnce((selector) => { 23 checkSelector(selector); 24 return {} as HTMLMetaElement; 25 }); 26 }); 27 it('returns undefined', () => { 28 const got = basename(); 29 30 expect(got).toBe(undefined); 31 }); 32 }); 33 34 describe("there's content", () => { 35 it('works with a base Path', () => { 36 jest 37 .spyOn(document, 'querySelector') 38 .mockImplementationOnce((selector) => { 39 checkSelector(selector); 40 return { content: '/pyroscope' } as HTMLMetaElement; 41 }); 42 43 const got = basename(); 44 45 expect(got).toBe('/pyroscope'); 46 }); 47 48 it('works with a full URL', () => { 49 jest 50 .spyOn(document, 'querySelector') 51 .mockImplementationOnce((selector) => { 52 checkSelector(selector); 53 return { 54 content: 'http://localhost:8080/pyroscope', 55 } as HTMLMetaElement; 56 }); 57 58 const got = basename(); 59 60 expect(got).toBe('/pyroscope'); 61 }); 62 }); 63 }); 64 });