refactor(v2): purify normalizeUrl (#4814)

Co-authored-by: Nam Hoang Le <nam.hoang.le@mgm-tp.com>
This commit is contained in:
Nam Hoang Le 2021-05-18 22:57:39 +07:00 committed by GitHub
parent fa7aa08100
commit e85ec1ab12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View file

@ -69,7 +69,7 @@ describe('load utils', () => {
});
test('simpleHash', () => {
const asserts = {
const asserts: Record<string, string> = {
'': 'd41',
'/foo-bar': '096',
'/foo/bar': '1df',
@ -230,7 +230,9 @@ describe('load utils', () => {
});
expect(idx(obj, ['translation', 'enabled'])).toEqual(true);
expect(
idx(obj, ['translation', variable]).map((lang) => lang.tag),
idx(obj, ['translation', variable]).map(
(lang: {tag: string}) => lang.tag,
),
).toEqual(['en', 'ja']);
expect(idx(test, ['arr', 0])).toEqual(1);
expect(idx(undefined)).toBeUndefined();
@ -350,6 +352,7 @@ describe('load utils', () => {
});
expect(() =>
// @ts-expect-error undefined for test
normalizeUrl(['http:example.com', undefined]),
).toThrowErrorMatchingInlineSnapshot(
`"Url must be a string. Received undefined"`,

View file

@ -199,7 +199,7 @@ export function getSubFolder(file: string, refDir: string): string | null {
}
export function normalizeUrl(rawUrls: string[]): string {
const urls = rawUrls;
const urls = [...rawUrls];
const resultArray = [];
let hasStartingSlash = false;