-
-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathhelper.test.js
More file actions
208 lines (180 loc) · 6.11 KB
/
Copy pathhelper.test.js
File metadata and controls
208 lines (180 loc) · 6.11 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
const os = require('os');
const helper = require('../helper');
const SOURCEMAPS_OPTIONS = require('../releases/options/uploadSourcemaps');
describe('SentryCli helper', () => {
test('call sentry-cli --version', () => {
expect.assertions(1);
return helper
.execute(['--version'])
.then((version) => expect(version.trim()).toBe('sentry-cli DEV'));
});
test('call sentry-cli with wrong command', () => {
expect.assertions(1);
return helper.execute(['fail']).catch((e) => expect(e.message).toMatch('Command failed:'));
});
test('getPath returns platform-appropriate path', () => {
const pattern = os.platform() === 'win32' ? /sentry-cli.exe$/ : /sentry-cli$/;
expect(helper.getPath()).toMatch(pattern);
});
describe('execute', () => {
test('execute with live=false returns stdout', async () => {
const output = await helper.execute(['--version'], false);
expect(output.trim()).toBe('sentry-cli DEV');
});
test('execute with live=true resolves on success', async () => {
// TODO (v3): This should resolve with a string, not undefined/void
const result = await helper.execute(['--version'], true);
expect(result).toBe('success (live mode)');
});
test('execute with live=true rejects on failure', async () => {
await expect(helper.execute(['fail'], true)).rejects.toThrow(
'Command fail failed with exit code 1'
);
});
// live=rejectOnError is not supported per the type declarations, but we should still aim
// to support it for backwards compatibility.
test('execute with live=rejectOnError resolves on success', async () => {
const result = await helper.execute(['--version'], 'rejectOnError');
expect(result).toBe('success (live mode)');
});
// live=rejectOnError is not supported per the type declarations, but we should still aim
// to support it for backwards compatibility.
test('execute with live=rejectOnError rejects on failure', async () => {
await expect(helper.execute(['fail'], 'rejectOnError')).rejects.toThrow(
'Command fail failed with exit code 1'
);
});
});
describe('`prepare` command', () => {
test('call prepare command add default ignore', () => {
const command = ['sourcemaps', 'upload', '--release', 'release', '/dev/null'];
expect(helper.prepareCommand(command)).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
]);
});
test('call prepare command with array option', () => {
const command = ['sourcemaps', 'upload', '--release', 'release', '/dev/null'];
expect(
helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { stripPrefix: ['node', 'app'] })
).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
'--strip-prefix',
'node',
'--strip-prefix',
'app',
]);
// Should throw since it is no array
expect(() => {
helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { stripPrefix: 'node' });
}).toThrow();
});
test('call prepare command with boolean option', () => {
const command = ['sourcemaps', 'upload', '--release', 'release', '/dev/null'];
expect(
helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { sourceMapReference: false })
).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
'--no-sourcemap-reference',
]);
expect(
helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { sourceMapReference: true })
).toEqual(['sourcemaps', 'upload', '--release', 'release', '/dev/null']);
expect(
helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { decompress: true, rewrite: true })
).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
'--decompress',
'--rewrite',
]);
expect(
helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { rewrite: false, dedupe: false })
).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
'--no-rewrite',
'--no-dedupe',
]);
// Only `invertedParam` registered for `dedupe` in `uploadSourcemaps`, so it should not add anything for positive boolean.
expect(helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { dedupe: true })).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
]);
expect(() => {
helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { sourceMapReference: 'node' });
}).toThrow();
});
test('call prepare command with string option', () => {
const command = ['sourcemaps', 'upload', '--release', 'release', '/dev/null'];
expect(helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { ext: ['js'] })).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
'--ext',
'js',
]);
expect(helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { urlPrefix: '~/' })).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
'--url-prefix',
'~/',
]);
expect(
helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { urlSuffix: '?hash=1337' })
).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
'--url-suffix',
'?hash=1337',
]);
expect(helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { decompress: true })).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
'--decompress',
]);
expect(
helper.prepareCommand(command, SOURCEMAPS_OPTIONS, { ignoreFile: '/js.ignore' })
).toEqual([
'sourcemaps',
'upload',
'--release',
'release',
'/dev/null',
'--ignore-file',
'/js.ignore',
]);
});
});
});