-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathrelativeOrAbsolute.test.mjs
More file actions
66 lines (55 loc) · 1.89 KB
/
relativeOrAbsolute.test.mjs
File metadata and controls
66 lines (55 loc) · 1.89 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
55
56
57
58
59
60
61
62
63
64
65
66
import assert from 'node:assert/strict';
import { beforeEach, describe, it } from 'node:test';
import {
setConfig,
default as getConfig,
} from '../../../../utils/configuration/index.mjs';
import { relativeOrAbsolute } from '../relativeOrAbsolute.mjs';
await setConfig({
version: 'v22.0.0',
changelog: [],
generators: {
web: {
useAbsoluteURLs: false,
baseURL: 'https://nodejs.org/docs',
},
},
});
describe('relativeOrAbsolute (relative mode)', () => {
beforeEach(() => {
getConfig('web').useAbsoluteURLs = false;
});
it('returns a relative path from a nested page to root', () => {
const result = relativeOrAbsolute('/', '/api/fs');
assert.strictEqual(result, '..');
});
it('returns a relative path between sibling pages', () => {
const result = relativeOrAbsolute('/http', '/fs');
assert.strictEqual(result, 'http');
});
it('returns a relative path for a deeper target', () => {
const result = relativeOrAbsolute('/orama-db.json', '/api/fs');
assert.strictEqual(result, '../orama-db.json');
});
it('returns "." when source and target resolve to the same path', () => {
const result = relativeOrAbsolute('/', '/');
assert.strictEqual(result, '.');
});
});
describe('relativeOrAbsolute (absolute mode)', () => {
beforeEach(() => {
getConfig('web').useAbsoluteURLs = true;
});
it('returns an absolute URL to root', () => {
const result = relativeOrAbsolute('/', '/api/fs');
assert.strictEqual(result, 'https://nodejs.org/docs');
});
it('returns an absolute URL for a page path', () => {
const result = relativeOrAbsolute('/http', '/fs');
assert.strictEqual(result, 'https://nodejs.org/docs/http');
});
it('returns an absolute URL for a resource', () => {
const result = relativeOrAbsolute('/orama-db.json', '/api/fs');
assert.strictEqual(result, 'https://nodejs.org/docs/orama-db.json');
});
});