Add regex matcher tests.
This commit is contained in:
parent
f7d292932f
commit
696dd8fde8
|
@ -88,14 +88,27 @@ test('Redirect.isMatch', (t) => {
|
||||||
test: 'invalid',
|
test: 'invalid',
|
||||||
} as unknown as HostnameRedirect['parameters']);
|
} as unknown as HostnameRedirect['parameters']);
|
||||||
|
|
||||||
|
const regexMatch = new HostnameRedirect({
|
||||||
|
matcherType: 'regex',
|
||||||
|
matcherValue: String.raw`^https://(www\.)?example.org/$`,
|
||||||
|
redirectType: 'simple',
|
||||||
|
redirectValue: '',
|
||||||
|
});
|
||||||
|
const regexSamples: UrlSamples = [
|
||||||
|
['https://example.org', true],
|
||||||
|
['https://www.example.org', true],
|
||||||
|
['https://example.org/path', false],
|
||||||
|
];
|
||||||
|
|
||||||
const samples: Array<[Redirects, UrlSamples]> = [
|
const samples: Array<[Redirects, UrlSamples]> = [
|
||||||
[invalidRedirect, [['https://example.org', false]]],
|
[invalidRedirect, [['https://example.org', false]]],
|
||||||
[hostnameRedirect, hostnameSamples],
|
[hostnameRedirect, hostnameSamples],
|
||||||
|
[regexMatch, regexSamples],
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const [redirect, urlSamples] of samples) {
|
for (const [redirect, urlSamples] of samples) {
|
||||||
for (const [sample, expected] of urlSamples) {
|
for (const [sample, expected] of urlSamples) {
|
||||||
t.is(redirect.isMatch(new URL(sample)), expected);
|
t.is(redirect.isMatch(new URL(sample)), expected, `Sample ${sample}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue