|
1 | 1 | const BundlerMock = require('../../mocks/bundler');
|
2 | 2 | const Bundle = require('../../../lib/build/bundle').Bundle;
|
| 3 | +const _calculateRelativeSourceMapsRoot = require('../../../lib/build/bundle')._calculateRelativeSourceMapsRoot; |
3 | 4 | const CLIOptionsMock = require('../../mocks/cli-options');
|
4 | 5 | const DependencyDescription = require('../../../lib/build/dependency-description').DependencyDescription;
|
5 | 6 | const SourceInclusion = require('../../../lib/build/source-inclusion').SourceInclusion;
|
@@ -459,3 +460,45 @@ describe('the Bundle module', () => {
|
459 | 460 | });
|
460 | 461 | });
|
461 | 462 | });
|
| 463 | + |
| 464 | +describe('function _calculateRelativeSourceMapsRoot', () => { |
| 465 | + const testCases = [ |
| 466 | + // Basic UNIX cases |
| 467 | + { projectDir: '/usr/home/my-app', outputDir: './dist', expected: '..' }, |
| 468 | + { projectDir: '/usr/home/my-app/', outputDir: './dist/', expected: '..' }, |
| 469 | + { projectDir: '/usr/home/my-app', outputDir: 'dist', expected: '..' }, |
| 470 | + { projectDir: '/usr/home/my-app/', outputDir: 'dist/', expected: '..' }, |
| 471 | + // Basic Windows cases |
| 472 | + { projectDir: 'C:/My Documents/MyApp', outputDir: './dist', expected: '..' }, |
| 473 | + { projectDir: 'C:/My Documents/MyApp/', outputDir: './dist/', expected: '..' }, |
| 474 | + { projectDir: 'C:/My Documents/MyApp', outputDir: 'dist', expected: '..' }, |
| 475 | + { projectDir: 'C:/My Documents/MyApp/', outputDir: 'dist/', expected: '..' }, |
| 476 | + // Basic Windows cases with backslashes |
| 477 | + { projectDir: 'C:\\My Documents\\MyApp', outputDir: '.\\dist', expected: '..' }, |
| 478 | + { projectDir: 'C:\\My Documents\\MyApp\\', outputDir: '.\\dist\\', expected: '..' }, |
| 479 | + { projectDir: 'C:\\My Documents\\MyApp', outputDir: 'dist', expected: '..' }, |
| 480 | + { projectDir: 'C:\\My Documents\\MyApp\\', outputDir: 'dist\\', expected: '..' }, |
| 481 | + // Windows mixed slashes |
| 482 | + { projectDir: 'C:\\My Documents\\MyApp', outputDir: './dist', expected: '..' }, |
| 483 | + { projectDir: 'C:\\My Documents\\MyApp\\', outputDir: './dist/', expected: '..' }, |
| 484 | + { projectDir: 'C:/My Documents/MyApp/', outputDir: 'dist\\', expected: '..' }, |
| 485 | + // Output directory outside of project root |
| 486 | + { projectDir: '/usr/home/my-app', outputDir: '../wwwroot/scripts', expected: '../../my-app' }, |
| 487 | + { projectDir: 'C:\\My Documents\\MyApp', outputDir: '../wwwroot/scripts', expected: '../../MyApp' }, |
| 488 | + // Relative project root paths, basic cases |
| 489 | + { projectDir: './my-app', outputDir: './dist', expected: '..' }, |
| 490 | + { projectDir: 'my-app', outputDir: 'dist', expected: '..' }, |
| 491 | + { projectDir: '.\\MyApp', outputDir: '.\\dist', expected: '..' }, |
| 492 | + { projectDir: 'MyApp\\', outputDir: 'dist\\', expected: '..' }, |
| 493 | + // Relative project root paths, output directory outside of project root |
| 494 | + { projectDir: './my-app', outputDir: '../wwwroot/scripts', expected: '../../my-app' }, |
| 495 | + { projectDir: '.\\MyApp\\', outputDir: '..\\wwwroot\\scripts\\', expected: '../../MyApp' } |
| 496 | + ]; |
| 497 | + |
| 498 | + testCases.forEach(({ projectDir, outputDir, expected }) => { |
| 499 | + it(`returns "${expected}" for projectDir "${projectDir}" and outputDir "${outputDir}"`, () => { |
| 500 | + const result = _calculateRelativeSourceMapsRoot(projectDir, outputDir); |
| 501 | + expect(result).toBe(expected); |
| 502 | + }); |
| 503 | + }); |
| 504 | +}); |
0 commit comments