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