forked from GoogleChrome/developer.chrome.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetNonLocalizedURL.js
More file actions
54 lines (45 loc) · 1.45 KB
/
getNonLocalizedURL.js
File metadata and controls
54 lines (45 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @fileoverview Tests the logic used when translating invalid localized URLs to
* valid URLs without an i18n prefix.
*/
const path = require('path');
const test = require('ava');
const {getNonLocalizedURL} = require('../../server/not-found');
const ROOT_DIR = path.join(__dirname, 'fixtures');
const DEFAULT_LOCALE = 'en';
test('returns null if no redirect is possible', t => {
const result = getNonLocalizedURL(
'/ja/doesnotexist/',
ROOT_DIR,
DEFAULT_LOCALE
);
t.is(result, null);
});
test('returns null if no redirect is possible, with an index.html suffix', t => {
const result = getNonLocalizedURL(
'/ja/doesnotexist/index.html',
ROOT_DIR,
DEFAULT_LOCALE
);
t.is(result, null);
});
test('returns null if no redirect is possible, without a trailing /', t => {
const result = getNonLocalizedURL('/doesnotexist', ROOT_DIR, DEFAULT_LOCALE);
t.is(result, null);
});
test('returns null if the URL starts with the default locale', t => {
const result = getNonLocalizedURL('/en/ignored/', ROOT_DIR, DEFAULT_LOCALE);
t.is(result, null);
});
test('returns the URL if a redirect is possible', t => {
const result = getNonLocalizedURL('/ja/exists/', ROOT_DIR, DEFAULT_LOCALE);
t.is(result, '/exists/');
});
test('returns the URL if a redirect is possible, with an index.html suffix', t => {
const result = getNonLocalizedURL(
'/ja/exists/index.html',
ROOT_DIR,
DEFAULT_LOCALE
);
t.is(result, '/exists/');
});