|
| 1 | +const path = require('path'); |
| 2 | +const { ensureLeadingDotSlash } = require('../src/update-ts-references'); |
| 3 | + |
| 4 | +test('returns null as-is', () => { |
| 5 | + expect(ensureLeadingDotSlash(null)).toBe(null); |
| 6 | +}); |
| 7 | + |
| 8 | +test('returns undefined as-is', () => { |
| 9 | + expect(ensureLeadingDotSlash(undefined)).toBe(undefined); |
| 10 | +}); |
| 11 | + |
| 12 | +test('returns . for empty string', () => { |
| 13 | + expect(ensureLeadingDotSlash('')).toBe('.'); |
| 14 | +}); |
| 15 | + |
| 16 | +test('returns absolute path as-is', () => { |
| 17 | + const p = path.resolve('/some/absolute/path'); |
| 18 | + expect(ensureLeadingDotSlash(p)).toBe(p); |
| 19 | +}); |
| 20 | + |
| 21 | +test('returns path already starting with .' + path.sep + ' as-is', () => { |
| 22 | + const p = '.' + path.sep + 'foo'; |
| 23 | + expect(ensureLeadingDotSlash(p)).toBe(p); |
| 24 | +}); |
| 25 | + |
| 26 | +test('returns path already starting with ..' + path.sep + ' as-is', () => { |
| 27 | + const p = '..' + path.sep + 'foo'; |
| 28 | + expect(ensureLeadingDotSlash(p)).toBe(p); |
| 29 | +}); |
| 30 | + |
| 31 | +test('prepends .' + path.sep + ' to a plain relative path', () => { |
| 32 | + expect(ensureLeadingDotSlash('foo')).toBe('.' + path.sep + 'foo'); |
| 33 | +}); |
| 34 | + |
| 35 | +test('prepends .' + path.sep + ' to a nested relative path', () => { |
| 36 | + expect(ensureLeadingDotSlash('foo' + path.sep + 'bar')).toBe('.' + path.sep + 'foo' + path.sep + 'bar'); |
| 37 | +}); |
0 commit comments