Reduce duplication.

This commit is contained in:
Bauke 2022-10-13 00:23:32 +02:00
parent 814c718c41
commit aa9a7121f8
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 10 additions and 19 deletions

View File

@ -10,17 +10,19 @@ import {
RedirectParameters,
} from '../source/redirect/exports.js';
const hostnameParameters: HostnameRedirect['parameters'] = {
hostname: 'example.org',
matchType: 'hostname',
toMatch: 'example.com',
type: 'hostname',
};
test('parseRedirect', (t) => {
const samples: Array<Redirects['parameters']> = [
{
test: 'Invalid parameters',
} as unknown as Redirects['parameters'],
{
hostname: 'example.org',
matchType: 'hostname',
toMatch: 'example.com',
type: 'hostname',
},
hostnameParameters,
];
for (const sample of samples) {
@ -35,12 +37,7 @@ test('parseRedirect', (t) => {
});
test('Redirect.redirect', (t) => {
const hostnameRedirect = new HostnameRedirect({
matchType: 'hostname',
toMatch: 'example.com',
hostname: 'example.org',
type: 'hostname',
});
const hostnameRedirect = new HostnameRedirect(hostnameParameters);
const samples: Array<[string, Redirect<RedirectParameters>]> = [
['https://example.com', hostnameRedirect],
@ -61,13 +58,7 @@ test('Redirect.redirect', (t) => {
test('Redirect.isMatch', (t) => {
type UrlSamples = Array<[string, boolean]>;
const hostnameRedirect = new HostnameRedirect({
hostname: 'example.org',
matchType: 'hostname',
toMatch: 'example.com',
type: 'hostname',
});
const hostnameRedirect = new HostnameRedirect(hostnameParameters);
const hostnameSamples: UrlSamples = [
['https://example.com', true],
['https://www.example.com', false],