Testing URL Path Joining Utilities in Parcel Bundler
This test suite validates the URL joining functionality in Parcel’s core utilities, ensuring proper path concatenation and normalization across different formats and operating systems. The tests verify the urlJoin utility’s ability to handle various path combinations while maintaining correct URL structure.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
parcel-bundler/parcel
packages/core/utils/test/urlJoin.test.js
// @flow strict-local
import assert from 'assert';
import urlJoin from '../src/urlJoin';
describe('urlJoin', () => {
it('Should join two paths', () => {
let joinedUrl = urlJoin('/', './image.jpeg?test=test');
assert.equal(joinedUrl, '/image.jpeg?test=test');
});
it('Should join two paths with longer publicUrl', () => {
let joinedUrl = urlJoin('/static', './image.jpeg?test=test');
assert.equal(joinedUrl, '/static/image.jpeg?test=test');
});
it('Should join two paths with longer publicUrl', () => {
let joinedUrl = urlJoin('/static', 'image.jpeg?test=test');
assert.equal(joinedUrl, '/static/image.jpeg?test=test');
});
it('Should turn windows path into posix', () => {
let joinedUrl = urlJoin('/static', '.\\image.jpeg?test=test');
assert.equal(joinedUrl, '/static/image.jpeg?test=test');
});
it('should support paths with colons', () => {
let joinedUrl = urlJoin('/static', 'a:b:c.html');
assert.equal(joinedUrl, '/static/a:b:c.html');
joinedUrl = urlJoin('/static', '/a:b:c.html');
assert.equal(joinedUrl, '/static/a:b:c.html');
joinedUrl = urlJoin('/static', './a:b:c.html');
assert.equal(joinedUrl, '/static/a:b:c.html');
});
});