Skip to content

Commit

Permalink
fix jest issue
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Jun 16, 2021
1 parent 660e98b commit 37568d7
Showing 1 changed file with 59 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,43 @@ import {
createFromExtensionsRedirects,
createToExtensionsRedirects,
} from '../extensionRedirects';
import {RedirectMetadata} from '../types';

const createExtensionValidationTests = (
extensionRedirectCreatorFn: (
paths: string[],
extensions: string[],
) => RedirectMetadata[],
) => {
describe('createToExtensionsRedirects', () => {
test('should reject empty extensions', () => {
expect(() => {
extensionRedirectCreatorFn(['/'], ['.html']);
}).toThrowErrorMatchingInlineSnapshot(
`"Extension ".html" contains a "." (dot) which is not allowed.\nIf the redirect extension system is not good enough for your usecase, you can create redirects yourself with the "createRedirects" plugin option."`,
);
createToExtensionsRedirects(['/'], ['.html']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

test('should reject extensions with .', () => {
expect(() => {
extensionRedirectCreatorFn(['/'], ['.html']);
}).toThrowErrorMatchingInlineSnapshot(
`"Extension ".html" contains a "." (dot) which is not allowed.\nIf the redirect extension system is not good enough for your usecase, you can create redirects yourself with the "createRedirects" plugin option."`,
);
createToExtensionsRedirects(['/'], ['.html']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

test('should reject extensions with /', () => {
expect(() => {
extensionRedirectCreatorFn(['/'], ['ht/ml']);
}).toThrowErrorMatchingInlineSnapshot(
`"Extension "ht/ml" contains a "/" (slash) which is not allowed.\nIf the redirect extension system is not good enough for your usecase, you can create redirects yourself with the "createRedirects" plugin option."`,
);
createToExtensionsRedirects(['/'], ['ht/ml']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\"ht/ml\\" contains a \\"/\\" (slash) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

test('should reject extensions with illegal url char', () => {
expect(() => {
extensionRedirectCreatorFn(['/'], [',']);
}).toThrowErrorMatchingInlineSnapshot(
`"Extension "," contains invalid URI characters.\nIf the redirect extension system is not good enough for your usecase, you can create redirects yourself with the "createRedirects" plugin option."`,
);
createToExtensionsRedirects(['/'], [',']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\",\\" contains invalid URI characters.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});
};

describe('createToExtensionsRedirects', () => {
createExtensionValidationTests(createToExtensionsRedirects);

test('should create redirects from html/htm extensions', () => {
const ext = ['html', 'htm'];
Expand Down Expand Up @@ -78,7 +75,41 @@ describe('createToExtensionsRedirects', () => {
});

describe('createFromExtensionsRedirects', () => {
createExtensionValidationTests(createFromExtensionsRedirects);
test('should reject empty extensions', () => {
expect(() => {
createFromExtensionsRedirects(['/'], ['.html']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

test('should reject extensions with .', () => {
expect(() => {
createFromExtensionsRedirects(['/'], ['.html']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

test('should reject extensions with /', () => {
expect(() => {
createFromExtensionsRedirects(['/'], ['ht/ml']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\"ht/ml\\" contains a \\"/\\" (slash) which is not allowed.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

test('should reject extensions with illegal url char', () => {
expect(() => {
createFromExtensionsRedirects(['/'], [',']);
}).toThrowErrorMatchingInlineSnapshot(`
"Extension \\",\\" contains invalid URI characters.
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
`);
});

test('should create redirects to html/htm extensions', () => {
const ext = ['html', 'htm'];
Expand Down

0 comments on commit 37568d7

Please sign in to comment.