-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
test.js
102 lines (80 loc) · 3.09 KB
/
test.js
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
91
92
93
94
95
96
97
98
99
100
101
102
import test from 'ava';
// TODO: Tests don't currently work as we need to be able to clear `supports-color`, but our `importFresh` helper can only bypass the cache at top-level.
// eslint-disable-next-line node/no-unsupported-features/es-syntax
const importFresh = async modulePath => import(`${modulePath}?x=${new Date()}`);
const importModule = async () => (await importFresh('./index.js')).default;
test.afterEach(() => {
delete process.env.FORCE_HYPERLINK;
});
test('main', async t => {
process.env.FORCE_HYPERLINK = 1;
const terminalLink = await importModule();
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', async t => {
process.env.FORCE_HYPERLINK = 1;
const terminalLink = await importModule();
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', async t => {
process.env.FORCE_HYPERLINK = 0;
const terminalLink = await importModule();
const actual = terminalLink('My Website', 'https://sindresorhus.com');
console.log(actual);
t.is(actual, 'My Website (\u200Bhttps://sindresorhus.com\u200B)');
});
test('disabled fallback', async t => {
process.env.FORCE_HYPERLINK = 0;
const terminalLink = await importModule();
const actual = terminalLink('My Website', 'https://sindresorhus.com', {
fallback: false
});
console.log(actual);
t.is(actual, 'My Website');
});
test('explicitly enabled fallback', async t => {
process.env.FORCE_HYPERLINK = 0;
const terminalLink = await importModule();
const actual = terminalLink('My Website', 'https://sindresorhus.com', {
fallback: true
});
console.log(actual);
t.is(actual, 'My Website (\u200Bhttps://sindresorhus.com\u200B)');
});
test('stderr default fallback', async t => {
process.env.FORCE_HYPERLINK = 0;
const terminalLink = await importModule();
const actual = terminalLink.stderr('My Website', 'https://sindresorhus.com');
console.log(actual);
t.is(actual, 'My Website (\u200Bhttps://sindresorhus.com\u200B)');
});
test('custom fallback', async t => {
process.env.FORCE_HYPERLINK = 0;
const terminalLink = await importModule();
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', async t => {
process.env.FORCE_HYPERLINK = 0;
const terminalLink = await importModule();
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', async t => {
const terminalLink = await importModule();
t.is(typeof terminalLink.isSupported, 'boolean');
});
test('isSupported stderr', async t => {
const terminalLink = await importModule();
t.is(typeof terminalLink.stderr.isSupported, 'boolean');
});