@docusaurus/plugin-client-redirects 2.0.0-beta.2 → 2.0.0-beta.20
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.
- package/lib/collectRedirects.d.ts +1 -1
- package/lib/collectRedirects.js +38 -42
- package/lib/createRedirectPageContent.d.ts +2 -4
- package/lib/createRedirectPageContent.js +2 -4
- package/lib/extensionRedirects.d.ts +1 -1
- package/lib/extensionRedirects.js +12 -8
- package/lib/index.d.ts +5 -3
- package/lib/index.js +8 -15
- package/lib/options.d.ts +31 -0
- package/lib/options.js +36 -0
- package/lib/redirectValidation.d.ts +1 -1
- package/lib/types.d.ts +12 -14
- package/lib/writeRedirectFiles.d.ts +1 -1
- package/lib/writeRedirectFiles.js +33 -9
- package/package.json +16 -14
- package/src/collectRedirects.ts +48 -55
- package/src/createRedirectPageContent.ts +8 -10
- package/src/extensionRedirects.ts +17 -9
- package/src/index.ts +9 -21
- package/src/options.ts +71 -0
- package/src/redirectValidation.ts +1 -1
- package/src/types.ts +14 -28
- package/src/writeRedirectFiles.ts +40 -10
- package/lib/.tsbuildinfo +0 -1
- package/lib/normalizePluginOptions.d.ts +0 -9
- package/lib/normalizePluginOptions.js +0 -44
- package/src/__tests__/__snapshots__/collectRedirects.test.ts.snap +0 -27
- package/src/__tests__/__snapshots__/createRedirectPageContent.test.ts.snap +0 -29
- package/src/__tests__/__snapshots__/normalizePluginOptions.test.ts.snap +0 -35
- package/src/__tests__/__snapshots__/redirectValidation.test.ts.snap +0 -11
- package/src/__tests__/__snapshots__/writeRedirectFiles.test.ts.snap +0 -147
- package/src/__tests__/collectRedirects.test.ts +0 -340
- package/src/__tests__/createRedirectPageContent.test.ts +0 -26
- package/src/__tests__/extensionRedirects.test.ts +0 -140
- package/src/__tests__/normalizePluginOptions.test.ts +0 -76
- package/src/__tests__/redirectValidation.test.ts +0 -66
- package/src/__tests__/writeRedirectFiles.test.ts +0 -203
- package/src/normalizePluginOptions.ts +0 -55
- package/tsconfig.json +0 -10
|
@@ -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 slash and not contain any domain or query string.
|
|
24
|
-
- {\\"from\\":\\"//abc\\",\\"to\\":\\"/\\"} => Validation error: \\"from\\" is not a valid pathname. Pathname should start with slash 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 slash 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 slash 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 slash 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 slash 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,147 +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 trailingSlash=false: 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
|
-
`;
|
|
72
|
-
|
|
73
|
-
exports[`toRedirectFilesMetadata should create appropriate metadatas trailingSlash=true: fileContent 1`] = `
|
|
74
|
-
Array [
|
|
75
|
-
"<!DOCTYPE html>
|
|
76
|
-
<html>
|
|
77
|
-
<head>
|
|
78
|
-
<meta charset=\\"UTF-8\\">
|
|
79
|
-
<meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/abc\\">
|
|
80
|
-
<link rel=\\"canonical\\" href=\\"https://docusaurus.io/abc\\" />
|
|
81
|
-
</head>
|
|
82
|
-
<script>
|
|
83
|
-
window.location.href = 'https://docusaurus.io/abc';
|
|
84
|
-
</script>
|
|
85
|
-
</html>",
|
|
86
|
-
"<!DOCTYPE html>
|
|
87
|
-
<html>
|
|
88
|
-
<head>
|
|
89
|
-
<meta charset=\\"UTF-8\\">
|
|
90
|
-
<meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/def.html\\">
|
|
91
|
-
<link rel=\\"canonical\\" href=\\"https://docusaurus.io/def.html\\" />
|
|
92
|
-
</head>
|
|
93
|
-
<script>
|
|
94
|
-
window.location.href = 'https://docusaurus.io/def.html';
|
|
95
|
-
</script>
|
|
96
|
-
</html>",
|
|
97
|
-
"<!DOCTYPE html>
|
|
98
|
-
<html>
|
|
99
|
-
<head>
|
|
100
|
-
<meta charset=\\"UTF-8\\">
|
|
101
|
-
<meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/\\">
|
|
102
|
-
<link rel=\\"canonical\\" href=\\"https://docusaurus.io/\\" />
|
|
103
|
-
</head>
|
|
104
|
-
<script>
|
|
105
|
-
window.location.href = 'https://docusaurus.io/';
|
|
106
|
-
</script>
|
|
107
|
-
</html>",
|
|
108
|
-
]
|
|
109
|
-
`;
|
|
110
|
-
|
|
111
|
-
exports[`toRedirectFilesMetadata should create appropriate metadatas trailingSlash=undefined: fileContent 1`] = `
|
|
112
|
-
Array [
|
|
113
|
-
"<!DOCTYPE html>
|
|
114
|
-
<html>
|
|
115
|
-
<head>
|
|
116
|
-
<meta charset=\\"UTF-8\\">
|
|
117
|
-
<meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/abc\\">
|
|
118
|
-
<link rel=\\"canonical\\" href=\\"https://docusaurus.io/abc\\" />
|
|
119
|
-
</head>
|
|
120
|
-
<script>
|
|
121
|
-
window.location.href = 'https://docusaurus.io/abc';
|
|
122
|
-
</script>
|
|
123
|
-
</html>",
|
|
124
|
-
"<!DOCTYPE html>
|
|
125
|
-
<html>
|
|
126
|
-
<head>
|
|
127
|
-
<meta charset=\\"UTF-8\\">
|
|
128
|
-
<meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/def.html\\">
|
|
129
|
-
<link rel=\\"canonical\\" href=\\"https://docusaurus.io/def.html\\" />
|
|
130
|
-
</head>
|
|
131
|
-
<script>
|
|
132
|
-
window.location.href = 'https://docusaurus.io/def.html';
|
|
133
|
-
</script>
|
|
134
|
-
</html>",
|
|
135
|
-
"<!DOCTYPE html>
|
|
136
|
-
<html>
|
|
137
|
-
<head>
|
|
138
|
-
<meta charset=\\"UTF-8\\">
|
|
139
|
-
<meta http-equiv=\\"refresh\\" content=\\"0; url=https://docusaurus.io/\\">
|
|
140
|
-
<link rel=\\"canonical\\" href=\\"https://docusaurus.io/\\" />
|
|
141
|
-
</head>
|
|
142
|
-
<script>
|
|
143
|
-
window.location.href = 'https://docusaurus.io/';
|
|
144
|
-
</script>
|
|
145
|
-
</html>",
|
|
146
|
-
]
|
|
147
|
-
`;
|
|
@@ -1,340 +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(
|
|
29
|
-
createTestPluginContext(undefined, ['/', '/path']),
|
|
30
|
-
undefined,
|
|
31
|
-
),
|
|
32
|
-
).toEqual([]);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('should collect no redirect for empty config', () => {
|
|
36
|
-
expect(collectRedirects(createTestPluginContext({}), undefined)).toEqual(
|
|
37
|
-
[],
|
|
38
|
-
);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('should collect redirects to html/exe extension', () => {
|
|
42
|
-
expect(
|
|
43
|
-
collectRedirects(
|
|
44
|
-
createTestPluginContext(
|
|
45
|
-
{
|
|
46
|
-
fromExtensions: ['html', 'exe'],
|
|
47
|
-
},
|
|
48
|
-
['/', '/somePath', '/otherPath.html'],
|
|
49
|
-
),
|
|
50
|
-
undefined,
|
|
51
|
-
),
|
|
52
|
-
).toEqual([
|
|
53
|
-
{
|
|
54
|
-
from: '/somePath.html',
|
|
55
|
-
to: '/somePath',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
from: '/somePath.exe',
|
|
59
|
-
to: '/somePath',
|
|
60
|
-
},
|
|
61
|
-
]);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('should collect redirects to html/exe extension', () => {
|
|
65
|
-
expect(
|
|
66
|
-
collectRedirects(
|
|
67
|
-
createTestPluginContext(
|
|
68
|
-
{
|
|
69
|
-
toExtensions: ['html', 'exe'],
|
|
70
|
-
},
|
|
71
|
-
['/', '/somePath', '/otherPath.html'],
|
|
72
|
-
),
|
|
73
|
-
undefined,
|
|
74
|
-
),
|
|
75
|
-
).toEqual([
|
|
76
|
-
{
|
|
77
|
-
from: '/otherPath',
|
|
78
|
-
to: '/otherPath.html',
|
|
79
|
-
},
|
|
80
|
-
]);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
test('should collect redirects from plugin option redirects', () => {
|
|
84
|
-
expect(
|
|
85
|
-
collectRedirects(
|
|
86
|
-
createTestPluginContext(
|
|
87
|
-
{
|
|
88
|
-
redirects: [
|
|
89
|
-
{
|
|
90
|
-
from: '/someLegacyPath',
|
|
91
|
-
to: '/somePath',
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
from: ['/someLegacyPathArray1', '/someLegacyPathArray2'],
|
|
95
|
-
to: '/',
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
},
|
|
99
|
-
['/', '/somePath'],
|
|
100
|
-
),
|
|
101
|
-
undefined,
|
|
102
|
-
),
|
|
103
|
-
).toEqual([
|
|
104
|
-
{
|
|
105
|
-
from: '/someLegacyPath',
|
|
106
|
-
to: '/somePath',
|
|
107
|
-
},
|
|
108
|
-
{
|
|
109
|
-
from: '/someLegacyPathArray1',
|
|
110
|
-
to: '/',
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
from: '/someLegacyPathArray2',
|
|
114
|
-
to: '/',
|
|
115
|
-
},
|
|
116
|
-
]);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('should collect redirects from plugin option redirects with trailingSlash=true', () => {
|
|
120
|
-
expect(
|
|
121
|
-
collectRedirects(
|
|
122
|
-
createTestPluginContext(
|
|
123
|
-
{
|
|
124
|
-
redirects: [
|
|
125
|
-
{
|
|
126
|
-
from: '/someLegacyPath',
|
|
127
|
-
to: '/somePath',
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
from: ['/someLegacyPathArray1', '/someLegacyPathArray2'],
|
|
131
|
-
to: '/',
|
|
132
|
-
},
|
|
133
|
-
],
|
|
134
|
-
},
|
|
135
|
-
['/', '/somePath/'],
|
|
136
|
-
),
|
|
137
|
-
true,
|
|
138
|
-
),
|
|
139
|
-
).toEqual([
|
|
140
|
-
{
|
|
141
|
-
from: '/someLegacyPath',
|
|
142
|
-
to: '/somePath/',
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
from: '/someLegacyPathArray1',
|
|
146
|
-
to: '/',
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
from: '/someLegacyPathArray2',
|
|
150
|
-
to: '/',
|
|
151
|
-
},
|
|
152
|
-
]);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test('should collect redirects from plugin option redirects with trailingSlash=false', () => {
|
|
156
|
-
expect(
|
|
157
|
-
collectRedirects(
|
|
158
|
-
createTestPluginContext(
|
|
159
|
-
{
|
|
160
|
-
redirects: [
|
|
161
|
-
{
|
|
162
|
-
from: '/someLegacyPath',
|
|
163
|
-
to: '/somePath/',
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
from: ['/someLegacyPathArray1', '/someLegacyPathArray2'],
|
|
167
|
-
to: '/',
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
},
|
|
171
|
-
['/', '/somePath'],
|
|
172
|
-
),
|
|
173
|
-
false,
|
|
174
|
-
),
|
|
175
|
-
).toEqual([
|
|
176
|
-
{
|
|
177
|
-
from: '/someLegacyPath',
|
|
178
|
-
to: '/somePath',
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
from: '/someLegacyPathArray1',
|
|
182
|
-
to: '/',
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
from: '/someLegacyPathArray2',
|
|
186
|
-
to: '/',
|
|
187
|
-
},
|
|
188
|
-
]);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test('should throw if plugin option redirects contain invalid to paths', () => {
|
|
192
|
-
expect(() =>
|
|
193
|
-
collectRedirects(
|
|
194
|
-
createTestPluginContext(
|
|
195
|
-
{
|
|
196
|
-
redirects: [
|
|
197
|
-
{
|
|
198
|
-
from: '/someLegacyPath',
|
|
199
|
-
to: '/',
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
from: '/someLegacyPath',
|
|
203
|
-
to: '/this/path/does/not/exist2',
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
from: '/someLegacyPath',
|
|
207
|
-
to: '/this/path/does/not/exist2',
|
|
208
|
-
},
|
|
209
|
-
],
|
|
210
|
-
},
|
|
211
|
-
['/', '/someExistingPath', '/anotherExistingPath'],
|
|
212
|
-
),
|
|
213
|
-
undefined,
|
|
214
|
-
),
|
|
215
|
-
).toThrowErrorMatchingSnapshot();
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
test('should collect redirects with custom redirect creator', () => {
|
|
219
|
-
expect(
|
|
220
|
-
collectRedirects(
|
|
221
|
-
createTestPluginContext(
|
|
222
|
-
{
|
|
223
|
-
createRedirects: (routePath) => {
|
|
224
|
-
return [
|
|
225
|
-
`${removeTrailingSlash(routePath)}/some/path/suffix1`,
|
|
226
|
-
`${removeTrailingSlash(routePath)}/some/other/path/suffix2`,
|
|
227
|
-
];
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
['/', '/testpath', '/otherPath.html'],
|
|
231
|
-
),
|
|
232
|
-
undefined,
|
|
233
|
-
),
|
|
234
|
-
).toEqual([
|
|
235
|
-
{
|
|
236
|
-
from: '/some/path/suffix1',
|
|
237
|
-
to: '/',
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
from: '/some/other/path/suffix2',
|
|
241
|
-
to: '/',
|
|
242
|
-
},
|
|
243
|
-
|
|
244
|
-
{
|
|
245
|
-
from: '/testpath/some/path/suffix1',
|
|
246
|
-
to: '/testpath',
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
from: '/testpath/some/other/path/suffix2',
|
|
250
|
-
to: '/testpath',
|
|
251
|
-
},
|
|
252
|
-
|
|
253
|
-
{
|
|
254
|
-
from: '/otherPath.html/some/path/suffix1',
|
|
255
|
-
to: '/otherPath.html',
|
|
256
|
-
},
|
|
257
|
-
{
|
|
258
|
-
from: '/otherPath.html/some/other/path/suffix2',
|
|
259
|
-
to: '/otherPath.html',
|
|
260
|
-
},
|
|
261
|
-
]);
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
test('should throw if redirect creator creates invalid redirects', () => {
|
|
265
|
-
expect(() =>
|
|
266
|
-
collectRedirects(
|
|
267
|
-
createTestPluginContext(
|
|
268
|
-
{
|
|
269
|
-
createRedirects: (routePath) => {
|
|
270
|
-
if (routePath === '/') {
|
|
271
|
-
return [
|
|
272
|
-
`https://google.com/`,
|
|
273
|
-
`//abc`,
|
|
274
|
-
`/def?queryString=toto`,
|
|
275
|
-
];
|
|
276
|
-
}
|
|
277
|
-
return undefined;
|
|
278
|
-
},
|
|
279
|
-
},
|
|
280
|
-
['/'],
|
|
281
|
-
),
|
|
282
|
-
undefined,
|
|
283
|
-
),
|
|
284
|
-
).toThrowErrorMatchingSnapshot();
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
test('should throw if redirect creator creates array of array redirect', () => {
|
|
288
|
-
expect(() =>
|
|
289
|
-
collectRedirects(
|
|
290
|
-
createTestPluginContext(
|
|
291
|
-
{
|
|
292
|
-
createRedirects: (routePath) => {
|
|
293
|
-
if (routePath === '/') {
|
|
294
|
-
return ([[`/fromPath`]] as unknown) as string;
|
|
295
|
-
}
|
|
296
|
-
return undefined;
|
|
297
|
-
},
|
|
298
|
-
},
|
|
299
|
-
['/'],
|
|
300
|
-
),
|
|
301
|
-
undefined,
|
|
302
|
-
),
|
|
303
|
-
).toThrowErrorMatchingSnapshot();
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
test('should filter unwanted redirects', () => {
|
|
307
|
-
expect(
|
|
308
|
-
collectRedirects(
|
|
309
|
-
createTestPluginContext(
|
|
310
|
-
{
|
|
311
|
-
fromExtensions: ['html', 'exe'],
|
|
312
|
-
toExtensions: ['html', 'exe'],
|
|
313
|
-
},
|
|
314
|
-
[
|
|
315
|
-
'/',
|
|
316
|
-
'/somePath',
|
|
317
|
-
'/somePath.html',
|
|
318
|
-
'/somePath.exe',
|
|
319
|
-
'/fromShouldWork.html',
|
|
320
|
-
'/toShouldWork',
|
|
321
|
-
],
|
|
322
|
-
),
|
|
323
|
-
undefined,
|
|
324
|
-
),
|
|
325
|
-
).toEqual([
|
|
326
|
-
{
|
|
327
|
-
from: '/toShouldWork.html',
|
|
328
|
-
to: '/toShouldWork',
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
from: '/toShouldWork.exe',
|
|
332
|
-
to: '/toShouldWork',
|
|
333
|
-
},
|
|
334
|
-
{
|
|
335
|
-
from: '/fromShouldWork',
|
|
336
|
-
to: '/fromShouldWork.html',
|
|
337
|
-
},
|
|
338
|
-
]);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
@@ -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
|
-
});
|