@docusaurus/plugin-client-redirects 2.0.0-beta.ff31de0ff → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/lib/collectRedirects.d.ts +2 -2
  2. package/lib/collectRedirects.js +45 -47
  3. package/lib/createRedirectPageContent.d.ts +2 -4
  4. package/lib/createRedirectPageContent.js +2 -4
  5. package/lib/extensionRedirects.d.ts +11 -3
  6. package/lib/extensionRedirects.js +22 -17
  7. package/lib/index.d.ts +5 -3
  8. package/lib/index.js +11 -8
  9. package/lib/options.d.ts +35 -0
  10. package/lib/options.js +36 -0
  11. package/lib/redirectValidation.d.ts +2 -2
  12. package/lib/types.d.ts +14 -16
  13. package/lib/writeRedirectFiles.d.ts +5 -5
  14. package/lib/writeRedirectFiles.js +41 -14
  15. package/package.json +16 -13
  16. package/src/collectRedirects.ts +76 -83
  17. package/src/createRedirectPageContent.ts +8 -10
  18. package/src/deps.d.ts +16 -0
  19. package/src/extensionRedirects.ts +32 -25
  20. package/src/index.ts +21 -14
  21. package/src/options.ts +75 -0
  22. package/src/redirectValidation.ts +3 -3
  23. package/src/types.ts +16 -30
  24. package/src/writeRedirectFiles.ts +53 -25
  25. package/lib/.tsbuildinfo +0 -1970
  26. package/lib/normalizePluginOptions.d.ts +0 -9
  27. package/lib/normalizePluginOptions.js +0 -44
  28. package/src/__tests__/__snapshots__/collectRedirects.test.ts.snap +0 -27
  29. package/src/__tests__/__snapshots__/createRedirectPageContent.test.ts.snap +0 -29
  30. package/src/__tests__/__snapshots__/normalizePluginOptions.test.ts.snap +0 -35
  31. package/src/__tests__/__snapshots__/redirectValidation.test.ts.snap +0 -11
  32. package/src/__tests__/__snapshots__/writeRedirectFiles.test.ts.snap +0 -71
  33. package/src/__tests__/collectRedirects.test.ts +0 -255
  34. package/src/__tests__/createRedirectPageContent.test.ts +0 -26
  35. package/src/__tests__/extensionRedirects.test.ts +0 -109
  36. package/src/__tests__/normalizePluginOptions.test.ts +0 -76
  37. package/src/__tests__/redirectValidation.test.ts +0 -66
  38. package/src/__tests__/writeRedirectFiles.test.ts +0 -146
  39. package/src/normalizePluginOptions.ts +0 -55
  40. package/tsconfig.json +0 -10
@@ -1,9 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
- import { PluginOptions, UserPluginOptions } from './types';
8
- export declare const DefaultPluginOptions: PluginOptions;
9
- export default function normalizePluginOptions(userPluginOptions?: UserPluginOptions): PluginOptions;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- /**
3
- * Copyright (c) Facebook, Inc. and its affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.DefaultPluginOptions = void 0;
10
- const utils_validation_1 = require("@docusaurus/utils-validation");
11
- const constants_1 = require("@docusaurus/core/lib/constants");
12
- exports.DefaultPluginOptions = {
13
- id: constants_1.DEFAULT_PLUGIN_ID,
14
- fromExtensions: [],
15
- toExtensions: [],
16
- redirects: [],
17
- };
18
- const RedirectPluginOptionValidation = utils_validation_1.Joi.object({
19
- to: utils_validation_1.PathnameSchema.required(),
20
- from: utils_validation_1.Joi.alternatives().try(utils_validation_1.PathnameSchema.required(), utils_validation_1.Joi.array().items(utils_validation_1.PathnameSchema.required())),
21
- });
22
- const isString = utils_validation_1.Joi.string().required().not(null);
23
- const UserOptionsSchema = utils_validation_1.Joi.object({
24
- id: utils_validation_1.Joi.string().optional(),
25
- fromExtensions: utils_validation_1.Joi.array().items(isString),
26
- toExtensions: utils_validation_1.Joi.array().items(isString),
27
- redirects: utils_validation_1.Joi.array().items(RedirectPluginOptionValidation),
28
- createRedirects: utils_validation_1.Joi.function().arity(1),
29
- });
30
- function validateUserOptions(userOptions) {
31
- const { error } = UserOptionsSchema.validate(userOptions, {
32
- abortEarly: true,
33
- allowUnknown: false,
34
- });
35
- if (error) {
36
- throw new Error(`Invalid @docusaurus/plugin-client-redirects options: ${error.message}
37
- ${JSON.stringify(userOptions, null, 2)}`);
38
- }
39
- }
40
- function normalizePluginOptions(userPluginOptions = {}) {
41
- validateUserOptions(userPluginOptions);
42
- return { ...exports.DefaultPluginOptions, ...userPluginOptions };
43
- }
44
- exports.default = normalizePluginOptions;
@@ -1,27 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`collectRedirects should throw if plugin option redirects contain invalid to paths 1`] = `
4
- "You are trying to create client-side redirections to paths that do not exist:
5
- - /this/path/does/not/exist2
6
- - /this/path/does/not/exist2
7
-
8
- Valid paths you can redirect to:
9
- - /
10
- - /someExistingPath
11
- - /anotherExistingPath
12
- "
13
- `;
14
-
15
- exports[`collectRedirects should throw if redirect creator creates array of array redirect 1`] = `
16
- "Some created redirects are invalid:
17
- - {\\"from\\":[\\"/fromPath\\"],\\"to\\":\\"/\\"} => Validation error: \\"from\\" must be a string
18
- "
19
- `;
20
-
21
- exports[`collectRedirects should throw if redirect creator creates invalid redirects 1`] = `
22
- "Some created redirects are invalid:
23
- - {\\"from\\":\\"https://google.com/\\",\\"to\\":\\"/\\"} => Validation error: \\"from\\" is not a valid pathname. Pathname should start with / and not contain any domain or query string
24
- - {\\"from\\":\\"//abc\\",\\"to\\":\\"/\\"} => Validation error: \\"from\\" is not a valid pathname. Pathname should start with / and not contain any domain or query string
25
- - {\\"from\\":\\"/def?queryString=toto\\",\\"to\\":\\"/\\"} => Validation error: \\"from\\" is not a valid pathname. Pathname should start with / and not contain any domain or query string
26
- "
27
- `;
@@ -1,29 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`createRedirectPageContent should encode uri special chars 1`] = `
4
- "<!DOCTYPE html>
5
- <html>
6
- <head>
7
- <meta charset=\\"UTF-8\\">
8
- <meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/gr/%CF%83%CE%B5%CE%BB%CE%B9%CE%B4%CE%B1%CF%82/\\">
9
- <link rel=\\"canonical\\" href=\\"https://docusaurus.io/gr/%CF%83%CE%B5%CE%BB%CE%B9%CE%B4%CE%B1%CF%82/\\" />
10
- </head>
11
- <script>
12
- window.location.href = 'https://docusaurus.io/gr/%CF%83%CE%B5%CE%BB%CE%B9%CE%B4%CE%B1%CF%82/';
13
- </script>
14
- </html>"
15
- `;
16
-
17
- exports[`createRedirectPageContent should match snapshot 1`] = `
18
- "<!DOCTYPE html>
19
- <html>
20
- <head>
21
- <meta charset=\\"UTF-8\\">
22
- <meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/\\">
23
- <link rel=\\"canonical\\" href=\\"https://docusaurus.io/\\" />
24
- </head>
25
- <script>
26
- window.location.href = 'https://docusaurus.io/';
27
- </script>
28
- </html>"
29
- `;
@@ -1,35 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`normalizePluginOptions should reject bad createRedirects user inputs 1`] = `
4
- "Invalid @docusaurus/plugin-client-redirects options: \\"createRedirects\\" must be of type function
5
- {
6
- \\"createRedirects\\": [
7
- \\"bad\\",
8
- \\"value\\"
9
- ]
10
- }"
11
- `;
12
-
13
- exports[`normalizePluginOptions should reject bad fromExtensions user inputs 1`] = `
14
- "Invalid @docusaurus/plugin-client-redirects options: \\"fromExtensions[0]\\" contains an invalid value
15
- {
16
- \\"fromExtensions\\": [
17
- null,
18
- null,
19
- 123,
20
- true
21
- ]
22
- }"
23
- `;
24
-
25
- exports[`normalizePluginOptions should reject bad toExtensions user inputs 1`] = `
26
- "Invalid @docusaurus/plugin-client-redirects options: \\"toExtensions[0]\\" contains an invalid value
27
- {
28
- \\"toExtensions\\": [
29
- null,
30
- null,
31
- 123,
32
- true
33
- ]
34
- }"
35
- `;
@@ -1,11 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`validateRedirect throw for bad redirects 1`] = `"{\\"from\\":\\"https://fb.com/fromSomePath\\",\\"to\\":\\"/toSomePath\\"} => Validation error: \\"from\\" is not a valid pathname. Pathname should start with / and not contain any domain or query string"`;
4
-
5
- exports[`validateRedirect throw for bad redirects 2`] = `"{\\"from\\":\\"/fromSomePath\\",\\"to\\":\\"https://fb.com/toSomePath\\"} => Validation error: \\"to\\" is not a valid pathname. Pathname should start with / and not contain any domain or query string"`;
6
-
7
- exports[`validateRedirect throw for bad redirects 3`] = `"{\\"from\\":\\"/fromSomePath\\",\\"to\\":\\"/toSomePath?queryString=xyz\\"} => Validation error: \\"to\\" is not a valid pathname. Pathname should start with / and not contain any domain or query string"`;
8
-
9
- exports[`validateRedirect throw for bad redirects 4`] = `"{\\"from\\":null,\\"to\\":\\"/toSomePath?queryString=xyz\\"} => Validation error: \\"from\\" must be a string"`;
10
-
11
- exports[`validateRedirect throw for bad redirects 5`] = `"{\\"from\\":[\\"heyho\\"],\\"to\\":\\"/toSomePath?queryString=xyz\\"} => Validation error: \\"from\\" must be a string"`;
@@ -1,71 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`toRedirectFilesMetadata should create appropriate metadatas for empty baseUrl: fileContent baseUrl=empty 1`] = `
4
- Array [
5
- "<!DOCTYPE html>
6
- <html>
7
- <head>
8
- <meta charset=\\"UTF-8\\">
9
- <meta http-equiv=\\"refresh\\" content=\\"0; url=/abc\\">
10
- <link rel=\\"canonical\\" href=\\"/abc\\" />
11
- </head>
12
- <script>
13
- window.location.href = '/abc';
14
- </script>
15
- </html>",
16
- ]
17
- `;
18
-
19
- exports[`toRedirectFilesMetadata should create appropriate metadatas for root baseUrl: fileContent baseUrl=/ 1`] = `
20
- Array [
21
- "<!DOCTYPE html>
22
- <html>
23
- <head>
24
- <meta charset=\\"UTF-8\\">
25
- <meta http-equiv=\\"refresh\\" content=\\"0; url=/abc\\">
26
- <link rel=\\"canonical\\" href=\\"/abc\\" />
27
- </head>
28
- <script>
29
- window.location.href = '/abc';
30
- </script>
31
- </html>",
32
- ]
33
- `;
34
-
35
- exports[`toRedirectFilesMetadata should create appropriate metadatas: fileContent 1`] = `
36
- Array [
37
- "<!DOCTYPE html>
38
- <html>
39
- <head>
40
- <meta charset=\\"UTF-8\\">
41
- <meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/abc\\">
42
- <link rel=\\"canonical\\" href=\\"https://docusaurus.io/abc\\" />
43
- </head>
44
- <script>
45
- window.location.href = 'https://docusaurus.io/abc';
46
- </script>
47
- </html>",
48
- "<!DOCTYPE html>
49
- <html>
50
- <head>
51
- <meta charset=\\"UTF-8\\">
52
- <meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/def.html\\">
53
- <link rel=\\"canonical\\" href=\\"https://docusaurus.io/def.html\\" />
54
- </head>
55
- <script>
56
- window.location.href = 'https://docusaurus.io/def.html';
57
- </script>
58
- </html>",
59
- "<!DOCTYPE html>
60
- <html>
61
- <head>
62
- <meta charset=\\"UTF-8\\">
63
- <meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/\\">
64
- <link rel=\\"canonical\\" href=\\"https://docusaurus.io/\\" />
65
- </head>
66
- <script>
67
- window.location.href = 'https://docusaurus.io/';
68
- </script>
69
- </html>",
70
- ]
71
- `;
@@ -1,255 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import {PluginContext, UserPluginOptions} from '../types';
9
- import collectRedirects from '../collectRedirects';
10
- import normalizePluginOptions from '../normalizePluginOptions';
11
- import {removeTrailingSlash} from '@docusaurus/utils';
12
-
13
- function createTestPluginContext(
14
- options?: UserPluginOptions,
15
- relativeRoutesPaths: string[] = [],
16
- ): PluginContext {
17
- return {
18
- outDir: '/tmp',
19
- baseUrl: 'https://docusaurus.io',
20
- relativeRoutesPaths,
21
- options: normalizePluginOptions(options),
22
- };
23
- }
24
-
25
- describe('collectRedirects', () => {
26
- test('should collect no redirect for undefined config', () => {
27
- expect(
28
- collectRedirects(createTestPluginContext(undefined, ['/', '/path'])),
29
- ).toEqual([]);
30
- });
31
-
32
- test('should collect no redirect for empty config', () => {
33
- expect(collectRedirects(createTestPluginContext({}))).toEqual([]);
34
- });
35
-
36
- test('should collect redirects to html/exe extension', () => {
37
- expect(
38
- collectRedirects(
39
- createTestPluginContext(
40
- {
41
- fromExtensions: ['html', 'exe'],
42
- },
43
- ['/', '/somePath', '/otherPath.html'],
44
- ),
45
- ),
46
- ).toEqual([
47
- {
48
- from: '/somePath.html',
49
- to: '/somePath',
50
- },
51
- {
52
- from: '/somePath.exe',
53
- to: '/somePath',
54
- },
55
- ]);
56
- });
57
-
58
- test('should collect redirects to html/exe extension', () => {
59
- expect(
60
- collectRedirects(
61
- createTestPluginContext(
62
- {
63
- toExtensions: ['html', 'exe'],
64
- },
65
- ['/', '/somePath', '/otherPath.html'],
66
- ),
67
- ),
68
- ).toEqual([
69
- {
70
- from: '/otherPath',
71
- to: '/otherPath.html',
72
- },
73
- ]);
74
- });
75
-
76
- test('should collect redirects from plugin option redirects', () => {
77
- expect(
78
- collectRedirects(
79
- createTestPluginContext(
80
- {
81
- redirects: [
82
- {
83
- from: '/someLegacyPath',
84
- to: '/somePath',
85
- },
86
- {
87
- from: ['/someLegacyPathArray1', '/someLegacyPathArray2'],
88
- to: '/',
89
- },
90
- ],
91
- },
92
- ['/', '/somePath'],
93
- ),
94
- ),
95
- ).toEqual([
96
- {
97
- from: '/someLegacyPath',
98
- to: '/somePath',
99
- },
100
- {
101
- from: '/someLegacyPathArray1',
102
- to: '/',
103
- },
104
- {
105
- from: '/someLegacyPathArray2',
106
- to: '/',
107
- },
108
- ]);
109
- });
110
-
111
- test('should throw if plugin option redirects contain invalid to paths', () => {
112
- expect(() =>
113
- collectRedirects(
114
- createTestPluginContext(
115
- {
116
- redirects: [
117
- {
118
- from: '/someLegacyPath',
119
- to: '/',
120
- },
121
- {
122
- from: '/someLegacyPath',
123
- to: '/this/path/does/not/exist2',
124
- },
125
- {
126
- from: '/someLegacyPath',
127
- to: '/this/path/does/not/exist2',
128
- },
129
- ],
130
- },
131
- ['/', '/someExistingPath', '/anotherExistingPath'],
132
- ),
133
- ),
134
- ).toThrowErrorMatchingSnapshot();
135
- });
136
-
137
- test('should collect redirects with custom redirect creator', () => {
138
- expect(
139
- collectRedirects(
140
- createTestPluginContext(
141
- {
142
- createRedirects: (routePath) => {
143
- return [
144
- `${removeTrailingSlash(routePath)}/some/path/suffix1`,
145
- `${removeTrailingSlash(routePath)}/some/other/path/suffix2`,
146
- ];
147
- },
148
- },
149
- ['/', '/testpath', '/otherPath.html'],
150
- ),
151
- ),
152
- ).toEqual([
153
- {
154
- from: '/some/path/suffix1',
155
- to: '/',
156
- },
157
- {
158
- from: '/some/other/path/suffix2',
159
- to: '/',
160
- },
161
-
162
- {
163
- from: '/testpath/some/path/suffix1',
164
- to: '/testpath',
165
- },
166
- {
167
- from: '/testpath/some/other/path/suffix2',
168
- to: '/testpath',
169
- },
170
-
171
- {
172
- from: '/otherPath.html/some/path/suffix1',
173
- to: '/otherPath.html',
174
- },
175
- {
176
- from: '/otherPath.html/some/other/path/suffix2',
177
- to: '/otherPath.html',
178
- },
179
- ]);
180
- });
181
-
182
- test('should throw if redirect creator creates invalid redirects', () => {
183
- expect(() =>
184
- collectRedirects(
185
- createTestPluginContext(
186
- {
187
- createRedirects: (routePath) => {
188
- if (routePath === '/') {
189
- return [
190
- `https://google.com/`,
191
- `//abc`,
192
- `/def?queryString=toto`,
193
- ];
194
- }
195
- return undefined;
196
- },
197
- },
198
- ['/'],
199
- ),
200
- ),
201
- ).toThrowErrorMatchingSnapshot();
202
- });
203
-
204
- test('should throw if redirect creator creates array of array redirect', () => {
205
- expect(() =>
206
- collectRedirects(
207
- createTestPluginContext(
208
- {
209
- createRedirects: (routePath) => {
210
- if (routePath === '/') {
211
- return ([[`/fromPath`]] as unknown) as string;
212
- }
213
- return undefined;
214
- },
215
- },
216
- ['/'],
217
- ),
218
- ),
219
- ).toThrowErrorMatchingSnapshot();
220
- });
221
-
222
- test('should filter unwanted redirects', () => {
223
- expect(
224
- collectRedirects(
225
- createTestPluginContext(
226
- {
227
- fromExtensions: ['html', 'exe'],
228
- toExtensions: ['html', 'exe'],
229
- },
230
- [
231
- '/',
232
- '/somePath',
233
- '/somePath.html',
234
- '/somePath.exe',
235
- '/fromShouldWork.html',
236
- '/toShouldWork',
237
- ],
238
- ),
239
- ),
240
- ).toEqual([
241
- {
242
- from: '/toShouldWork.html',
243
- to: '/toShouldWork',
244
- },
245
- {
246
- from: '/toShouldWork.exe',
247
- to: '/toShouldWork',
248
- },
249
- {
250
- from: '/fromShouldWork',
251
- to: '/fromShouldWork.html',
252
- },
253
- ]);
254
- });
255
- });
@@ -1,26 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import createRedirectPageContent from '../createRedirectPageContent';
9
-
10
- describe('createRedirectPageContent', () => {
11
- test('should match snapshot', () => {
12
- expect(
13
- createRedirectPageContent({toUrl: 'https://docusaurus.io/'}),
14
- ).toMatchSnapshot();
15
- });
16
-
17
- test('should encode uri special chars', () => {
18
- const result = createRedirectPageContent({
19
- toUrl: 'https://docusaurus.io/gr/σελιδας/',
20
- });
21
- expect(result).toContain(
22
- 'https://docusaurus.io/gr/%CF%83%CE%B5%CE%BB%CE%B9%CE%B4%CE%B1%CF%82/',
23
- );
24
- expect(result).toMatchSnapshot();
25
- });
26
- });
@@ -1,109 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import {
9
- createFromExtensionsRedirects,
10
- createToExtensionsRedirects,
11
- } from '../extensionRedirects';
12
- import {RedirectMetadata} from '../types';
13
-
14
- const createExtensionValidationTests = (
15
- extensionRedirectCreatorFn: (
16
- paths: string[],
17
- extensions: string[],
18
- ) => RedirectMetadata[],
19
- ) => {
20
- test('should reject empty extensions', () => {
21
- expect(() => {
22
- extensionRedirectCreatorFn(['/'], ['.html']);
23
- }).toThrowErrorMatchingInlineSnapshot(
24
- `"Extension=['.html'] contains a . (dot) and 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."`,
25
- );
26
- });
27
- test('should reject extensions with .', () => {
28
- expect(() => {
29
- extensionRedirectCreatorFn(['/'], ['.html']);
30
- }).toThrowErrorMatchingInlineSnapshot(
31
- `"Extension=['.html'] contains a . (dot) and 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."`,
32
- );
33
- });
34
- test('should reject extensions with /', () => {
35
- expect(() => {
36
- extensionRedirectCreatorFn(['/'], ['ht/ml']);
37
- }).toThrowErrorMatchingInlineSnapshot(
38
- `"Extension=['ht/ml'] contains a / and 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."`,
39
- );
40
- });
41
- test('should reject extensions with illegal url char', () => {
42
- expect(() => {
43
- extensionRedirectCreatorFn(['/'], [',']);
44
- }).toThrowErrorMatchingInlineSnapshot(
45
- `"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."`,
46
- );
47
- });
48
- };
49
-
50
- describe('createToExtensionsRedirects', () => {
51
- createExtensionValidationTests(createToExtensionsRedirects);
52
-
53
- test('should create redirects from html/htm extensions', () => {
54
- const ext = ['html', 'htm'];
55
- expect(createToExtensionsRedirects([''], ext)).toEqual([]);
56
- expect(createToExtensionsRedirects(['/'], ext)).toEqual([]);
57
- expect(createToExtensionsRedirects(['/abc.html'], ext)).toEqual([
58
- {from: '/abc', to: '/abc.html'},
59
- ]);
60
- expect(createToExtensionsRedirects(['/abc.htm'], ext)).toEqual([
61
- {from: '/abc', to: '/abc.htm'},
62
- ]);
63
- expect(createToExtensionsRedirects(['/abc.xyz'], ext)).toEqual([]);
64
- });
65
-
66
- test('should create "to" redirects when relativeRoutesPath contains a prefix', () => {
67
- expect(
68
- createToExtensionsRedirects(['/prefix/file.html'], ['html']),
69
- ).toEqual([{from: '/prefix/file', to: '/prefix/file.html'}]);
70
- });
71
-
72
- test('should not create redirection for an empty extension array', () => {
73
- const ext: string[] = [];
74
- expect(createToExtensionsRedirects([''], ext)).toEqual([]);
75
- expect(createToExtensionsRedirects(['/'], ext)).toEqual([]);
76
- expect(createToExtensionsRedirects(['/abc.html'], ext)).toEqual([]);
77
- });
78
- });
79
-
80
- describe('createFromExtensionsRedirects', () => {
81
- createExtensionValidationTests(createFromExtensionsRedirects);
82
-
83
- test('should create redirects to html/htm extensions', () => {
84
- const ext = ['html', 'htm'];
85
- expect(createFromExtensionsRedirects([''], ext)).toEqual([]);
86
- expect(createFromExtensionsRedirects(['/'], ext)).toEqual([]);
87
- expect(createFromExtensionsRedirects(['/abc'], ext)).toEqual([
88
- {from: '/abc.html', to: '/abc'},
89
- {from: '/abc.htm', to: '/abc'},
90
- ]);
91
- expect(createFromExtensionsRedirects(['/def.html'], ext)).toEqual([]);
92
- expect(createFromExtensionsRedirects(['/def/'], ext)).toEqual([]);
93
- });
94
-
95
- test('should create "from" redirects when relativeRoutesPath contains a prefix', () => {
96
- expect(createFromExtensionsRedirects(['/prefix/file'], ['html'])).toEqual([
97
- {from: '/prefix/file.html', to: '/prefix/file'},
98
- ]);
99
- });
100
-
101
- test('should not create redirection for an empty extension array', () => {
102
- const ext: string[] = [];
103
- expect(createFromExtensionsRedirects([''], ext)).toEqual([]);
104
- expect(createFromExtensionsRedirects(['/'], ext)).toEqual([]);
105
- expect(createFromExtensionsRedirects(['/abc'], ext)).toEqual([]);
106
- expect(createFromExtensionsRedirects(['/def.html'], ext)).toEqual([]);
107
- expect(createFromExtensionsRedirects(['/def/'], ext)).toEqual([]);
108
- });
109
- });