-
-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathindex.test.js
More file actions
161 lines (150 loc) · 4.3 KB
/
index.test.js
File metadata and controls
161 lines (150 loc) · 4.3 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
describe('SentryCli source maps', () => {
afterEach(() => {
jest.resetModules();
});
describe('with mock', () => {
let cli;
let mockExecute;
beforeAll(() => {
mockExecute = jest.fn(async () => {});
jest.doMock('../../helper', () => ({
...jest.requireActual('../../helper'),
execute: mockExecute,
}));
});
beforeEach(() => {
mockExecute.mockClear();
// eslint-disable-next-line global-require
const { SentryCli: SentryCliLocal } = require('../..');
cli = new SentryCliLocal();
});
describe('inject', () => {
test('with single path', async () => {
await cli.sourceMaps.inject({ paths: ['./dist'] });
expect(mockExecute).toHaveBeenCalledWith(
['sourcemaps', 'inject', './dist', '--ignore', 'node_modules'],
true,
false,
undefined,
{ silent: false }
);
});
test('with multiple paths', async () => {
await cli.sourceMaps.inject({ paths: ['./dist', './build'] });
expect(mockExecute).toHaveBeenCalledWith(
['sourcemaps', 'inject', './dist', './build', '--ignore', 'node_modules'],
true,
false,
undefined,
{ silent: false }
);
});
test('with custom ignore patterns', async () => {
await cli.sourceMaps.inject({
paths: ['./dist'],
ignore: ['vendor', '*.test.js'],
});
expect(mockExecute).toHaveBeenCalledWith(
['sourcemaps', 'inject', './dist', '--ignore', 'vendor', '--ignore', '*.test.js'],
true,
false,
undefined,
{ silent: false }
);
});
test('with ignoreFile', async () => {
await cli.sourceMaps.inject({
paths: ['./dist'],
ignoreFile: '.gitignore',
});
expect(mockExecute).toHaveBeenCalledWith(
['sourcemaps', 'inject', './dist', '--ignore-file', '.gitignore'],
true,
false,
undefined,
{ silent: false }
);
});
test('with custom extensions', async () => {
await cli.sourceMaps.inject({
paths: ['./dist'],
ext: ['js', 'mjs', 'cjs'],
});
expect(mockExecute).toHaveBeenCalledWith(
[
'sourcemaps',
'inject',
'./dist',
'--ignore',
'node_modules',
'--ext',
'js',
'--ext',
'mjs',
'--ext',
'cjs',
],
true,
false,
undefined,
{ silent: false }
);
});
test('with dryRun', async () => {
await cli.sourceMaps.inject({
paths: ['./dist'],
dryRun: true,
});
expect(mockExecute).toHaveBeenCalledWith(
['sourcemaps', 'inject', './dist', '--ignore', 'node_modules', '--dry-run'],
true,
false,
undefined,
{ silent: false }
);
});
test('with all options', async () => {
await cli.sourceMaps.inject({
paths: ['./dist', './build'],
ignore: ['vendor'],
ext: ['js', 'mjs'],
dryRun: true,
});
expect(mockExecute).toHaveBeenCalledWith(
[
'sourcemaps',
'inject',
'./dist',
'./build',
'--ignore',
'vendor',
'--ext',
'js',
'--ext',
'mjs',
'--dry-run',
],
true,
false,
undefined,
{ silent: false }
);
});
test('throws error when paths is not provided', async () => {
await expect(cli.sourceMaps.inject({})).rejects.toThrow(
'`options.paths` must be a valid array of paths.'
);
});
test('throws error when paths is not an array', async () => {
await expect(cli.sourceMaps.inject({ paths: './dist' })).rejects.toThrow(
'`options.paths` must be a valid array of paths.'
);
});
test('throws error when paths is empty', async () => {
await expect(cli.sourceMaps.inject({ paths: [] })).rejects.toThrow(
'`options.paths` must contain at least one path.'
);
});
});
});
});