-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patheditor.test.ts
More file actions
115 lines (98 loc) · 4.01 KB
/
editor.test.ts
File metadata and controls
115 lines (98 loc) · 4.01 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import { when } from 'jest-when';
import { determineEditor } from './editor';
import * as envModule from './env';
import * as miscUtils from './misc-utils';
jest.mock('./env');
jest.mock('./misc-utils');
describe('editor', () => {
describe('determineEditor', () => {
it('returns information about the editor from EDITOR if it resolves to an executable', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockResolvedValue('/path/to/resolved-editor');
expect(await determineEditor()).toStrictEqual({
path: '/path/to/resolved-editor',
args: [],
});
});
it('falls back to VSCode if it exists and if EDITOR does not point to an executable', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockResolvedValue(null)
.calledWith('code')
.mockResolvedValue('/path/to/code');
expect(await determineEditor()).toStrictEqual({
path: '/path/to/code',
args: ['--wait'],
});
});
it('returns null if resolving EDITOR returns null and resolving VSCode returns null', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockResolvedValue(null)
.calledWith('code')
.mockResolvedValue(null);
expect(await determineEditor()).toBeNull();
});
it('returns null if resolving EDITOR returns null and resolving VSCode throws', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockResolvedValue(null)
.calledWith('code')
.mockRejectedValue(new Error('some error'));
expect(await determineEditor()).toBeNull();
});
it('returns null if resolving EDITOR throws and resolving VSCode returns null', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockRejectedValue(new Error('some error'))
.calledWith('code')
.mockResolvedValue(null);
expect(await determineEditor()).toBeNull();
});
it('returns null if resolving EDITOR throws and resolving VSCode throws', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: 'editor', TODAY: undefined });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('editor')
.mockRejectedValue(new Error('some error'))
.calledWith('code')
.mockRejectedValue(new Error('some error'));
expect(await determineEditor()).toBeNull();
});
it('returns null if EDITOR is unset and resolving VSCode returns null', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: undefined, TODAY: undefined });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('code')
.mockResolvedValue(null);
expect(await determineEditor()).toBeNull();
});
it('returns null if EDITOR is unset and resolving VSCode throws', async () => {
jest
.spyOn(envModule, 'getEnvironmentVariables')
.mockReturnValue({ EDITOR: undefined, TODAY: undefined });
when(jest.spyOn(miscUtils, 'resolveExecutable'))
.calledWith('code')
.mockRejectedValue(new Error('some error'));
expect(await determineEditor()).toBeNull();
});
});
});