|
| 1 | +describe('SentryCli source maps', () => { |
| 2 | + afterEach(() => { |
| 3 | + jest.resetModules(); |
| 4 | + }); |
| 5 | + |
| 6 | + describe('with mock', () => { |
| 7 | + let cli; |
| 8 | + let mockExecute; |
| 9 | + beforeAll(() => { |
| 10 | + mockExecute = jest.fn(async () => {}); |
| 11 | + jest.doMock('../../helper', () => ({ |
| 12 | + ...jest.requireActual('../../helper'), |
| 13 | + execute: mockExecute, |
| 14 | + })); |
| 15 | + }); |
| 16 | + beforeEach(() => { |
| 17 | + mockExecute.mockClear(); |
| 18 | + // eslint-disable-next-line global-require |
| 19 | + const { SentryCli: SentryCliLocal } = require('../..'); |
| 20 | + cli = new SentryCliLocal(); |
| 21 | + }); |
| 22 | + |
| 23 | + describe('inject', () => { |
| 24 | + test('with single path', async () => { |
| 25 | + await cli.sourceMaps.inject({ paths: ['./dist'] }); |
| 26 | + expect(mockExecute).toHaveBeenCalledWith( |
| 27 | + ['sourcemaps', 'inject', './dist', '--ignore', 'node_modules'], |
| 28 | + true, |
| 29 | + false, |
| 30 | + undefined, |
| 31 | + { silent: false } |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + test('with multiple paths', async () => { |
| 36 | + await cli.sourceMaps.inject({ paths: ['./dist', './build'] }); |
| 37 | + expect(mockExecute).toHaveBeenCalledWith( |
| 38 | + ['sourcemaps', 'inject', './dist', './build', '--ignore', 'node_modules'], |
| 39 | + true, |
| 40 | + false, |
| 41 | + undefined, |
| 42 | + { silent: false } |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + test('with custom ignore patterns', async () => { |
| 47 | + await cli.sourceMaps.inject({ |
| 48 | + paths: ['./dist'], |
| 49 | + ignore: ['vendor', '*.test.js'], |
| 50 | + }); |
| 51 | + expect(mockExecute).toHaveBeenCalledWith( |
| 52 | + ['sourcemaps', 'inject', './dist', '--ignore', 'vendor', '--ignore', '*.test.js'], |
| 53 | + true, |
| 54 | + false, |
| 55 | + undefined, |
| 56 | + { silent: false } |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + test('with ignoreFile', async () => { |
| 61 | + await cli.sourceMaps.inject({ |
| 62 | + paths: ['./dist'], |
| 63 | + ignoreFile: '.gitignore', |
| 64 | + }); |
| 65 | + expect(mockExecute).toHaveBeenCalledWith( |
| 66 | + ['sourcemaps', 'inject', './dist', '--ignore-file', '.gitignore'], |
| 67 | + true, |
| 68 | + false, |
| 69 | + undefined, |
| 70 | + { silent: false } |
| 71 | + ); |
| 72 | + }); |
| 73 | + |
| 74 | + test('with custom extensions', async () => { |
| 75 | + await cli.sourceMaps.inject({ |
| 76 | + paths: ['./dist'], |
| 77 | + ext: ['js', 'mjs', 'cjs'], |
| 78 | + }); |
| 79 | + expect(mockExecute).toHaveBeenCalledWith( |
| 80 | + [ |
| 81 | + 'sourcemaps', |
| 82 | + 'inject', |
| 83 | + './dist', |
| 84 | + '--ignore', |
| 85 | + 'node_modules', |
| 86 | + '--ext', |
| 87 | + 'js', |
| 88 | + '--ext', |
| 89 | + 'mjs', |
| 90 | + '--ext', |
| 91 | + 'cjs', |
| 92 | + ], |
| 93 | + true, |
| 94 | + false, |
| 95 | + undefined, |
| 96 | + { silent: false } |
| 97 | + ); |
| 98 | + }); |
| 99 | + |
| 100 | + test('with dryRun', async () => { |
| 101 | + await cli.sourceMaps.inject({ |
| 102 | + paths: ['./dist'], |
| 103 | + dryRun: true, |
| 104 | + }); |
| 105 | + expect(mockExecute).toHaveBeenCalledWith( |
| 106 | + ['sourcemaps', 'inject', './dist', '--ignore', 'node_modules', '--dry-run'], |
| 107 | + true, |
| 108 | + false, |
| 109 | + undefined, |
| 110 | + { silent: false } |
| 111 | + ); |
| 112 | + }); |
| 113 | + |
| 114 | + test('with all options', async () => { |
| 115 | + await cli.sourceMaps.inject({ |
| 116 | + paths: ['./dist', './build'], |
| 117 | + ignore: ['vendor'], |
| 118 | + ext: ['js', 'mjs'], |
| 119 | + dryRun: true, |
| 120 | + }); |
| 121 | + expect(mockExecute).toHaveBeenCalledWith( |
| 122 | + [ |
| 123 | + 'sourcemaps', |
| 124 | + 'inject', |
| 125 | + './dist', |
| 126 | + './build', |
| 127 | + '--ignore', |
| 128 | + 'vendor', |
| 129 | + '--ext', |
| 130 | + 'js', |
| 131 | + '--ext', |
| 132 | + 'mjs', |
| 133 | + '--dry-run', |
| 134 | + ], |
| 135 | + true, |
| 136 | + false, |
| 137 | + undefined, |
| 138 | + { silent: false } |
| 139 | + ); |
| 140 | + }); |
| 141 | + |
| 142 | + test('throws error when paths is not provided', async () => { |
| 143 | + await expect(cli.sourceMaps.inject({})).rejects.toThrow( |
| 144 | + '`options.paths` must be a valid array of paths.' |
| 145 | + ); |
| 146 | + }); |
| 147 | + |
| 148 | + test('throws error when paths is not an array', async () => { |
| 149 | + await expect(cli.sourceMaps.inject({ paths: './dist' })).rejects.toThrow( |
| 150 | + '`options.paths` must be a valid array of paths.' |
| 151 | + ); |
| 152 | + }); |
| 153 | + |
| 154 | + test('throws error when paths is empty', async () => { |
| 155 | + await expect(cli.sourceMaps.inject({ paths: [] })).rejects.toThrow( |
| 156 | + '`options.paths` must contain at least one path.' |
| 157 | + ); |
| 158 | + }); |
| 159 | + }); |
| 160 | + }); |
| 161 | +}); |
0 commit comments