Skip to content

Commit

Permalink
test(postcss-normalize-url): improve normalize-url coverage (#1483)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludofischer committed Mar 24, 2023
1 parent 91a7cdb commit 4e657ef
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/postcss-normalize-url/src/normalize.js
@@ -1,3 +1,4 @@
'use strict';
/* Derived from normalize-url https://github.com/sindresorhus/normalize-url/main/index.js by Sindre Sorhus */

// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs
Expand Down
73 changes: 73 additions & 0 deletions packages/postcss-normalize-url/test/normalize.js
@@ -0,0 +1,73 @@
'use strict';

const assert = require('uvu/assert');
const { test } = require('uvu');
const normalizeUrl = require('../src/normalize.js');

test('should add the http prefix to unprefixed URLs', () => {
assert.is(normalizeUrl('example.com'), 'http://example.com');
});

test('should not attempt to sort parameters', () => {
const fixture = 'http://sindresorhus.com/?d=Z&b=Y&c=X&a=W';
assert.is(normalizeUrl(fixture), fixture);
});

test('should leave encoded slashes alone', () => {
const fixture = 'https://example.com/music/bands/AC%2FDC';
assert.is(normalizeUrl(fixture), fixture);
});

test('should decode URI octets', () => {
assert.is(
normalizeUrl('http://example.com/%7Efoo/'),
'http://example.com/~foo'
);
});

test('should handle spaces inside parameters', () => {
assert.is(
normalizeUrl('http://example.com/?foo=bar baz'),
'http://example.com/?foo=bar%20baz'
);
});

test('should preserve authentication string', () => {
const fixture = 'http://user:password@www.example.com';
assert.is(normalizeUrl(fixture), fixture);
});

test('should preserve index', () => {
const fixture = 'http://example.com/index.html';
assert.is(normalizeUrl(fixture), fixture);
});

test('should preserve non-standard port', () => {
const fixture = 'https://example.com:123';
assert.is(normalizeUrl(fixture), fixture);
});

test('should strip default MIME type', () => {
assert.is(normalizeUrl('data:text/plain,foo'), 'data:,foo');
});

test('should strip default charset', () => {
assert.is(normalizeUrl('data:;charset=us-ascii,foo'), 'data:,foo');
});

test('should lowercase the MIME type', () => {
assert.is(normalizeUrl('data:TEXT/HTML,foo'), 'data:text/html,foo');
});

test('should keep spaces when not base64', () => {
assert.is(normalizeUrl('data:, foo #bar'), 'data:, foo #bar');
});

test('should remove trailing semicolon', () => {
assert.is(
normalizeUrl('data:;charset=UTF-8;,foo'),
'data:;charset=utf-8,foo'
);
});

test.run();

0 comments on commit 4e657ef

Please sign in to comment.