Add tests for SimpleRedirect.
This commit is contained in:
parent
1743959769
commit
67a2c7567f
|
@ -8,6 +8,7 @@ import {
|
||||||
Redirect,
|
Redirect,
|
||||||
Redirects,
|
Redirects,
|
||||||
RedirectParameters,
|
RedirectParameters,
|
||||||
|
SimpleRedirect,
|
||||||
} from '../source/redirect/exports.js';
|
} from '../source/redirect/exports.js';
|
||||||
|
|
||||||
const hostnameParameters: HostnameRedirect['parameters'] = {
|
const hostnameParameters: HostnameRedirect['parameters'] = {
|
||||||
|
@ -17,6 +18,13 @@ const hostnameParameters: HostnameRedirect['parameters'] = {
|
||||||
type: 'hostname',
|
type: 'hostname',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const simpleParameters: SimpleRedirect['parameters'] = {
|
||||||
|
matchType: 'hostname',
|
||||||
|
target: 'https://example.org/simple',
|
||||||
|
toMatch: 'example.com',
|
||||||
|
type: 'simple',
|
||||||
|
};
|
||||||
|
|
||||||
test('parseRedirect', (t) => {
|
test('parseRedirect', (t) => {
|
||||||
const samples: Array<Redirects['parameters']> = [
|
const samples: Array<Redirects['parameters']> = [
|
||||||
{
|
{
|
||||||
|
@ -24,6 +32,7 @@ test('parseRedirect', (t) => {
|
||||||
} as unknown as Redirects['parameters'],
|
} as unknown as Redirects['parameters'],
|
||||||
undefined as unknown as Redirects['parameters'],
|
undefined as unknown as Redirects['parameters'],
|
||||||
hostnameParameters,
|
hostnameParameters,
|
||||||
|
simpleParameters,
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const sample of samples) {
|
for (const sample of samples) {
|
||||||
|
@ -39,10 +48,13 @@ test('parseRedirect', (t) => {
|
||||||
|
|
||||||
test('Redirect.redirect', (t) => {
|
test('Redirect.redirect', (t) => {
|
||||||
const hostnameRedirect = new HostnameRedirect(hostnameParameters);
|
const hostnameRedirect = new HostnameRedirect(hostnameParameters);
|
||||||
|
const simpleRedirect = new SimpleRedirect(simpleParameters);
|
||||||
|
|
||||||
const samples: Array<[string, Redirect<RedirectParameters>]> = [
|
const samples: Array<[string, Redirect<RedirectParameters>]> = [
|
||||||
['https://example.com', hostnameRedirect],
|
['https://example.com', hostnameRedirect],
|
||||||
['https://example.com/path#hash?query=test', hostnameRedirect],
|
['https://example.com/path#hash?query=test', hostnameRedirect],
|
||||||
|
['https://example.com', simpleRedirect],
|
||||||
|
['https://example.com/path', simpleRedirect],
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const [index, [url, redirect]] of samples.entries()) {
|
for (const [index, [url, redirect]] of samples.entries()) {
|
||||||
|
|
|
@ -17,6 +17,17 @@ Generated by [AVA](https://avajs.dev).
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
> Class SimpleRedirect
|
||||||
|
|
||||||
|
SimpleRedirect {
|
||||||
|
parameters: {
|
||||||
|
matchType: 'hostname',
|
||||||
|
target: 'https://example.org/simple',
|
||||||
|
toMatch: 'example.com',
|
||||||
|
type: 'simple',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
## Redirect.redirect
|
## Redirect.redirect
|
||||||
|
|
||||||
> 0 HostnameRedirect
|
> 0 HostnameRedirect
|
||||||
|
@ -32,3 +43,17 @@ Generated by [AVA](https://avajs.dev).
|
||||||
original: 'https://example.com/path#hash?query=test',
|
original: 'https://example.com/path#hash?query=test',
|
||||||
redirected: 'https://example.org/path#hash?query=test',
|
redirected: 'https://example.org/path#hash?query=test',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
> 2 SimpleRedirect
|
||||||
|
|
||||||
|
{
|
||||||
|
original: 'https://example.com',
|
||||||
|
redirected: 'https://example.org/simple',
|
||||||
|
}
|
||||||
|
|
||||||
|
> 3 SimpleRedirect
|
||||||
|
|
||||||
|
{
|
||||||
|
original: 'https://example.com/path',
|
||||||
|
redirected: 'https://example.org/simple',
|
||||||
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue