Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
90 lines (70 loc) · 2.42 KB
/
Copy pathtest.js
File metadata and controls
90 lines (70 loc) · 2.42 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import test from 'ava';
import supportsHyperlinks from 'supports-hyperlinks';
import terminalLink from './index.js';
const originalStdout = supportsHyperlinks.stdout;
const originalStderr = supportsHyperlinks.stderr;
test.afterEach(() => {
supportsHyperlinks.stdout = originalStdout;
supportsHyperlinks.stderr = originalStderr;
});
test('main', t => {
supportsHyperlinks.stdout = true;
const actual = terminalLink('My Website', 'https://sindresorhus.com');
console.log(actual);
t.is(actual, '\u001B]8;;https://sindresorhus.com\u0007My Website\u001B]8;;\u0007');
});
test('stderr', t => {
supportsHyperlinks.stderr = true;
const actual = terminalLink.stderr('My Website', 'https://sindresorhus.com');
console.log(actual);
t.is(actual, '\u001B]8;;https://sindresorhus.com\u0007My Website\u001B]8;;\u0007');
});
test('default fallback', t => {
supportsHyperlinks.stdout = false;
const actual = terminalLink('My Website', 'https://sindresorhus.com');
console.log(actual);
t.is(actual, 'My Website https://sindresorhus.com');
});
test('disabled fallback', t => {
supportsHyperlinks.stdout = false;
const actual = terminalLink('My Website', 'https://sindresorhus.com', {
fallback: false,
});
console.log(actual);
t.is(actual, 'My Website');
});
test('explicitly enabled fallback', t => {
supportsHyperlinks.stdout = false;
const actual = terminalLink('My Website', 'https://sindresorhus.com', {
fallback: true,
});
console.log(actual);
t.is(actual, 'My Website https://sindresorhus.com');
});
test('stderr default fallback', t => {
supportsHyperlinks.stderr = false;
const actual = terminalLink.stderr('My Website', 'https://sindresorhus.com');
t.is(actual, 'My Website https://sindresorhus.com');
});
test('custom fallback', t => {
supportsHyperlinks.stdout = false;
const actual = terminalLink('My Website', 'https://sindresorhus.com', {
fallback: (text, url) => `${text}: ${url}`,
});
console.log(actual);
t.is(actual, 'My Website: https://sindresorhus.com');
});
test('custom fallback stderr', t => {
supportsHyperlinks.stderr = false;
const actual = terminalLink.stderr('My Website', 'https://sindresorhus.com', {
fallback: (text, url) => `${text}: ${url}`,
});
console.log(actual);
t.is(actual, 'My Website: https://sindresorhus.com');
});
test('isSupported', t => {
t.is(typeof terminalLink.isSupported, 'boolean');
});
test('isSupported stderr', t => {
t.is(typeof terminalLink.stderr.isSupported, 'boolean');
});