-
Notifications
You must be signed in to change notification settings - Fork 470
Expand file tree
/
Copy pathprofiler-edit.test.ts
More file actions
147 lines (134 loc) · 3.84 KB
/
profiler-edit.test.ts
File metadata and controls
147 lines (134 loc) · 3.84 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { makeOptionsFromArgv } from '../../node-tools/profiler-edit';
describe('makeOptionsFromArgv', function () {
const commonArgs = ['/path/to/node', '/path/to/profiler-edit.js'];
it('recognizes -i with a file path', function () {
const options = makeOptionsFromArgv([
...commonArgs,
'-i',
'/path/to/profile.json',
'-o',
'/path/to/output.json',
]);
expect(options.input).toEqual({
type: 'FILE',
path: '/path/to/profile.json',
});
expect(options.output).toEqual('/path/to/output.json');
expect(options.symbolicateWithServer).toBeUndefined();
});
it('recognizes -i with an http URL', function () {
const options = makeOptionsFromArgv([
...commonArgs,
'-i',
'http://example.com/profile.json',
'-o',
'/path/to/output.json',
]);
expect(options.input).toEqual({
type: 'URL',
url: 'http://example.com/profile.json',
});
});
it('recognizes -i with an https URL', function () {
const options = makeOptionsFromArgv([
...commonArgs,
'-i',
'https://example.com/profile.json',
'-o',
'/path/to/output.json',
]);
expect(options.input).toEqual({
type: 'URL',
url: 'https://example.com/profile.json',
});
});
it('recognizes --from-file', function () {
const options = makeOptionsFromArgv([
...commonArgs,
'--from-file',
'/path/to/profile.json',
'-o',
'/path/to/output.json',
]);
expect(options.input).toEqual({
type: 'FILE',
path: '/path/to/profile.json',
});
});
it('recognizes --from-url', function () {
const options = makeOptionsFromArgv([
...commonArgs,
'--from-url',
'https://example.com/profile.json',
'-o',
'/path/to/output.json',
]);
expect(options.input).toEqual({
type: 'URL',
url: 'https://example.com/profile.json',
});
});
it('recognizes --from-hash', function () {
const options = makeOptionsFromArgv([
...commonArgs,
'--from-hash',
'abc123',
'-o',
'/path/to/output.json',
]);
expect(options.input).toEqual({ type: 'HASH', hash: 'abc123' });
});
it('recognizes --output as an alias for -o', function () {
const options = makeOptionsFromArgv([
...commonArgs,
'-i',
'/path/to/profile.json',
'--output',
'/path/to/output.json',
]);
expect(options.output).toEqual('/path/to/output.json');
});
it('recognizes optional --symbolicate-with-server', function () {
const options = makeOptionsFromArgv([
...commonArgs,
'-i',
'/path/to/profile.json',
'-o',
'/path/to/output.json',
'--symbolicate-with-server',
'http://localhost:8001/',
]);
expect(options.symbolicateWithServer).toEqual('http://localhost:8001/');
});
it('throws when no input is provided', function () {
expect(() =>
makeOptionsFromArgv([...commonArgs, '-o', '/path/to/output.json'])
).toThrow();
});
it('throws when multiple inputs are provided', function () {
expect(() =>
makeOptionsFromArgv([
...commonArgs,
'-i',
'/path/to/profile.json',
'--from-hash',
'abc123',
'-o',
'/path/to/output.json',
])
).toThrow();
});
it('throws when no output is provided', function () {
expect(() =>
makeOptionsFromArgv([...commonArgs, '-i', '/path/to/profile.json'])
).toThrow();
});
it('throws when -i has no value because next token is a flag', function () {
expect(() =>
makeOptionsFromArgv([...commonArgs, '-i', '-o', '/path/to/output.json'])
).toThrow();
});
});