|
| 1 | +import { interpolate } from './interpolate.js'; |
| 2 | + |
| 3 | +describe('interpolate', () => { |
| 4 | + it('should replace variable in string', () => { |
| 5 | + expect( |
| 6 | + interpolate('.code-pushup/{projectName}', { projectName: 'utils' }), |
| 7 | + ).toBe('.code-pushup/utils'); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should replace multiple variables', () => { |
| 11 | + expect( |
| 12 | + interpolate('{workspaceRoot}/coverage/{projectRoot}/lcov.info', { |
| 13 | + workspaceRoot: '/home/matej/Projects/code-pushup-cli', |
| 14 | + projectRoot: 'packages/ci', |
| 15 | + }), |
| 16 | + ).toBe( |
| 17 | + '/home/matej/Projects/code-pushup-cli/coverage/packages/ci/lcov.info', |
| 18 | + ); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should replace same variable multiple times', () => { |
| 22 | + expect( |
| 23 | + interpolate('.code-pushup/{projectName}/{projectName}-report.json', { |
| 24 | + projectName: 'utils', |
| 25 | + }), |
| 26 | + ).toBe('.code-pushup/utils/utils-report.json'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should not replace missing variables', () => { |
| 30 | + expect(interpolate('{projectRoot}/.code-pushup', {})).toBe( |
| 31 | + '{projectRoot}/.code-pushup', |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should support empty string interpolation', () => { |
| 36 | + expect(interpolate('{prefix}report.json', { prefix: '' })).toBe( |
| 37 | + 'report.json', |
| 38 | + ); |
| 39 | + }); |
| 40 | + |
| 41 | + it('should support strings with only variable', () => { |
| 42 | + expect(interpolate('{projectName}', { projectName: 'utils' })).toBe( |
| 43 | + 'utils', |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should leave strings without variables unchanged', () => { |
| 48 | + expect(interpolate('.code-pushup', { projectName: 'utils' })).toBe( |
| 49 | + '.code-pushup', |
| 50 | + ); |
| 51 | + }); |
| 52 | +}); |
0 commit comments