@docusaurus/plugin-client-redirects 2.0.0-beta.13 → 2.0.0-beta.15
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 +5 -9
- package/lib/extensionRedirects.d.ts +1 -1
- package/lib/extensionRedirects.js +1 -1
- package/lib/index.d.ts +3 -3
- package/lib/normalizePluginOptions.d.ts +1 -1
- package/lib/redirectValidation.d.ts +1 -1
- package/lib/types.d.ts +2 -14
- package/lib/writeRedirectFiles.d.ts +1 -1
- package/package.json +8 -8
- package/src/collectRedirects.ts +13 -22
- package/src/extensionRedirects.ts +2 -2
- package/src/index.ts +5 -4
- package/src/normalizePluginOptions.ts +5 -1
- package/src/plugin-client-redirects.d.ts +20 -1
- package/src/redirectValidation.ts +1 -1
- package/src/types.ts +2 -22
- package/src/writeRedirectFiles.ts +1 -1
- package/lib/.tsbuildinfo +0 -1
- 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 -338
- package/src/__tests__/createRedirectPageContent.test.ts +0 -26
- package/src/__tests__/extensionRedirects.test.ts +0 -143
- package/src/__tests__/normalizePluginOptions.test.ts +0 -71
- package/src/__tests__/redirectValidation.test.ts +0 -66
- package/src/__tests__/writeRedirectFiles.test.ts +0 -205
- package/tsconfig.json +0 -10
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`toRedirectFilesMetadata should create appropriate metadata 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 metadata 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 metadata 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 metadata 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 metadata 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,338 +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
|
-
`${removeTrailingSlash(routePath)}/some/path/suffix1`,
|
|
225
|
-
`${removeTrailingSlash(routePath)}/some/other/path/suffix2`,
|
|
226
|
-
],
|
|
227
|
-
},
|
|
228
|
-
['/', '/testpath', '/otherPath.html'],
|
|
229
|
-
),
|
|
230
|
-
undefined,
|
|
231
|
-
),
|
|
232
|
-
).toEqual([
|
|
233
|
-
{
|
|
234
|
-
from: '/some/path/suffix1',
|
|
235
|
-
to: '/',
|
|
236
|
-
},
|
|
237
|
-
{
|
|
238
|
-
from: '/some/other/path/suffix2',
|
|
239
|
-
to: '/',
|
|
240
|
-
},
|
|
241
|
-
|
|
242
|
-
{
|
|
243
|
-
from: '/testpath/some/path/suffix1',
|
|
244
|
-
to: '/testpath',
|
|
245
|
-
},
|
|
246
|
-
{
|
|
247
|
-
from: '/testpath/some/other/path/suffix2',
|
|
248
|
-
to: '/testpath',
|
|
249
|
-
},
|
|
250
|
-
|
|
251
|
-
{
|
|
252
|
-
from: '/otherPath.html/some/path/suffix1',
|
|
253
|
-
to: '/otherPath.html',
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
from: '/otherPath.html/some/other/path/suffix2',
|
|
257
|
-
to: '/otherPath.html',
|
|
258
|
-
},
|
|
259
|
-
]);
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
test('should throw if redirect creator creates invalid redirects', () => {
|
|
263
|
-
expect(() =>
|
|
264
|
-
collectRedirects(
|
|
265
|
-
createTestPluginContext(
|
|
266
|
-
{
|
|
267
|
-
createRedirects: (routePath) => {
|
|
268
|
-
if (routePath === '/') {
|
|
269
|
-
return [
|
|
270
|
-
`https://google.com/`,
|
|
271
|
-
`//abc`,
|
|
272
|
-
`/def?queryString=toto`,
|
|
273
|
-
];
|
|
274
|
-
}
|
|
275
|
-
return undefined;
|
|
276
|
-
},
|
|
277
|
-
},
|
|
278
|
-
['/'],
|
|
279
|
-
),
|
|
280
|
-
undefined,
|
|
281
|
-
),
|
|
282
|
-
).toThrowErrorMatchingSnapshot();
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
test('should throw if redirect creator creates array of array redirect', () => {
|
|
286
|
-
expect(() =>
|
|
287
|
-
collectRedirects(
|
|
288
|
-
createTestPluginContext(
|
|
289
|
-
{
|
|
290
|
-
createRedirects: (routePath) => {
|
|
291
|
-
if (routePath === '/') {
|
|
292
|
-
return [[`/fromPath`]] as unknown as string;
|
|
293
|
-
}
|
|
294
|
-
return undefined;
|
|
295
|
-
},
|
|
296
|
-
},
|
|
297
|
-
['/'],
|
|
298
|
-
),
|
|
299
|
-
undefined,
|
|
300
|
-
),
|
|
301
|
-
).toThrowErrorMatchingSnapshot();
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
test('should filter unwanted redirects', () => {
|
|
305
|
-
expect(
|
|
306
|
-
collectRedirects(
|
|
307
|
-
createTestPluginContext(
|
|
308
|
-
{
|
|
309
|
-
fromExtensions: ['html', 'exe'],
|
|
310
|
-
toExtensions: ['html', 'exe'],
|
|
311
|
-
},
|
|
312
|
-
[
|
|
313
|
-
'/',
|
|
314
|
-
'/somePath',
|
|
315
|
-
'/somePath.html',
|
|
316
|
-
'/somePath.exe',
|
|
317
|
-
'/fromShouldWork.html',
|
|
318
|
-
'/toShouldWork',
|
|
319
|
-
],
|
|
320
|
-
),
|
|
321
|
-
undefined,
|
|
322
|
-
),
|
|
323
|
-
).toEqual([
|
|
324
|
-
{
|
|
325
|
-
from: '/toShouldWork.html',
|
|
326
|
-
to: '/toShouldWork',
|
|
327
|
-
},
|
|
328
|
-
{
|
|
329
|
-
from: '/toShouldWork.exe',
|
|
330
|
-
to: '/toShouldWork',
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
from: '/fromShouldWork',
|
|
334
|
-
to: '/fromShouldWork.html',
|
|
335
|
-
},
|
|
336
|
-
]);
|
|
337
|
-
});
|
|
338
|
-
});
|
|
@@ -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,143 +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
|
-
|
|
13
|
-
describe('createToExtensionsRedirects', () => {
|
|
14
|
-
test('should reject empty extensions', () => {
|
|
15
|
-
expect(() => {
|
|
16
|
-
createToExtensionsRedirects(['/'], ['.html']);
|
|
17
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
18
|
-
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
|
|
19
|
-
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
|
|
20
|
-
`);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
test('should reject extensions with .', () => {
|
|
24
|
-
expect(() => {
|
|
25
|
-
createToExtensionsRedirects(['/'], ['.html']);
|
|
26
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
27
|
-
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
|
|
28
|
-
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
|
|
29
|
-
`);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('should reject extensions with /', () => {
|
|
33
|
-
expect(() => {
|
|
34
|
-
createToExtensionsRedirects(['/'], ['ht/ml']);
|
|
35
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
36
|
-
"Extension \\"ht/ml\\" contains a \\"/\\" (slash) which is not allowed.
|
|
37
|
-
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
|
|
38
|
-
`);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('should reject extensions with illegal url char', () => {
|
|
42
|
-
expect(() => {
|
|
43
|
-
createToExtensionsRedirects(['/'], [',']);
|
|
44
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
45
|
-
"Extension \\",\\" contains invalid URI characters.
|
|
46
|
-
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
|
|
47
|
-
`);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
test('should create redirects from html/htm extensions', () => {
|
|
51
|
-
const ext = ['html', 'htm'];
|
|
52
|
-
expect(createToExtensionsRedirects([''], ext)).toEqual([]);
|
|
53
|
-
expect(createToExtensionsRedirects(['/'], ext)).toEqual([]);
|
|
54
|
-
expect(createToExtensionsRedirects(['/abc.html'], ext)).toEqual([
|
|
55
|
-
{from: '/abc', to: '/abc.html'},
|
|
56
|
-
]);
|
|
57
|
-
expect(createToExtensionsRedirects(['/abc.htm'], ext)).toEqual([
|
|
58
|
-
{from: '/abc', to: '/abc.htm'},
|
|
59
|
-
]);
|
|
60
|
-
expect(createToExtensionsRedirects(['/abc.xyz'], ext)).toEqual([]);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('should create "to" redirects when relativeRoutesPath contains a prefix', () => {
|
|
64
|
-
expect(
|
|
65
|
-
createToExtensionsRedirects(['/prefix/file.html'], ['html']),
|
|
66
|
-
).toEqual([{from: '/prefix/file', to: '/prefix/file.html'}]);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('should not create redirection for an empty extension array', () => {
|
|
70
|
-
const ext: string[] = [];
|
|
71
|
-
expect(createToExtensionsRedirects([''], ext)).toEqual([]);
|
|
72
|
-
expect(createToExtensionsRedirects(['/'], ext)).toEqual([]);
|
|
73
|
-
expect(createToExtensionsRedirects(['/abc.html'], ext)).toEqual([]);
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('createFromExtensionsRedirects', () => {
|
|
78
|
-
test('should reject empty extensions', () => {
|
|
79
|
-
expect(() => {
|
|
80
|
-
createFromExtensionsRedirects(['/'], ['.html']);
|
|
81
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
82
|
-
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
|
|
83
|
-
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
|
|
84
|
-
`);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('should reject extensions with .', () => {
|
|
88
|
-
expect(() => {
|
|
89
|
-
createFromExtensionsRedirects(['/'], ['.html']);
|
|
90
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
91
|
-
"Extension \\".html\\" contains a \\".\\" (dot) which is not allowed.
|
|
92
|
-
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
|
|
93
|
-
`);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('should reject extensions with /', () => {
|
|
97
|
-
expect(() => {
|
|
98
|
-
createFromExtensionsRedirects(['/'], ['ht/ml']);
|
|
99
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
100
|
-
"Extension \\"ht/ml\\" contains a \\"/\\" (slash) which is not allowed.
|
|
101
|
-
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
|
|
102
|
-
`);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('should reject extensions with illegal url char', () => {
|
|
106
|
-
expect(() => {
|
|
107
|
-
createFromExtensionsRedirects(['/'], [',']);
|
|
108
|
-
}).toThrowErrorMatchingInlineSnapshot(`
|
|
109
|
-
"Extension \\",\\" contains invalid URI characters.
|
|
110
|
-
If the redirect extension system is not good enough for your usecase, you can create redirects yourself with the \\"createRedirects\\" plugin option."
|
|
111
|
-
`);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('should create redirects from html/htm extensions', () => {
|
|
115
|
-
const ext = ['html', 'htm'];
|
|
116
|
-
expect(createFromExtensionsRedirects([''], ext)).toEqual([]);
|
|
117
|
-
expect(createFromExtensionsRedirects(['/'], ext)).toEqual([]);
|
|
118
|
-
expect(createFromExtensionsRedirects(['/abc'], ext)).toEqual([
|
|
119
|
-
{from: '/abc.html', to: '/abc'},
|
|
120
|
-
{from: '/abc.htm', to: '/abc'},
|
|
121
|
-
]);
|
|
122
|
-
expect(createFromExtensionsRedirects(['/def.html'], ext)).toEqual([]);
|
|
123
|
-
expect(createFromExtensionsRedirects(['/def/'], ext)).toEqual([
|
|
124
|
-
{from: '/def.html/', to: '/def/'},
|
|
125
|
-
{from: '/def.htm/', to: '/def/'},
|
|
126
|
-
]);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
test('should create "from" redirects when relativeRoutesPath contains a prefix', () => {
|
|
130
|
-
expect(createFromExtensionsRedirects(['/prefix/file'], ['html'])).toEqual([
|
|
131
|
-
{from: '/prefix/file.html', to: '/prefix/file'},
|
|
132
|
-
]);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('should not create redirection for an empty extension array', () => {
|
|
136
|
-
const ext: string[] = [];
|
|
137
|
-
expect(createFromExtensionsRedirects([''], ext)).toEqual([]);
|
|
138
|
-
expect(createFromExtensionsRedirects(['/'], ext)).toEqual([]);
|
|
139
|
-
expect(createFromExtensionsRedirects(['/abc'], ext)).toEqual([]);
|
|
140
|
-
expect(createFromExtensionsRedirects(['/def.html'], ext)).toEqual([]);
|
|
141
|
-
expect(createFromExtensionsRedirects(['/def/'], ext)).toEqual([]);
|
|
142
|
-
});
|
|
143
|
-
});
|