@docusaurus/plugin-client-redirects 2.0.0-beta.12faed89d → 2.0.0-beta.14

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.
@@ -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
- });