diff --git a/README.md b/README.md index 988b6a69..a8c32dbc 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ entries | `array`/`RegExp`/`function(key: string): bool` | optional | a filter f | stripCommonPrefix | `boolean` | optional | when paired with `rewrite` this will add `~` to the `stripPrefix` array. | | sourceMapReference | `boolean` | optional | this prevents the automatic detection of sourcemap references. | | rewrite | `boolean` | optional | enables rewriting of matching sourcemaps so that indexed maps are flattened and missing sources are inlined if possible. defaults to `true` | +| finalize | `boolean` | optional | determines whether processed release should be automatically finalized after artifacts upload. defaults to `true` | | dryRun | `boolean` | optional | attempts a dry run (useful for dev environments) | | debug | `boolean` | optional | print some useful debug information | | silent | `boolean` | optional | if `true`, all logs are suppressed (useful for `--json` option) | diff --git a/src/__tests__/index.spec.js b/src/__tests__/index.spec.js index 975f3557..50f32c26 100644 --- a/src/__tests__/index.spec.js +++ b/src/__tests__/index.spec.js @@ -21,13 +21,17 @@ afterEach(() => { jest.clearAllMocks(); }); +const defaults = { + debug: false, + finalize: true, + rewrite: true, +}; + describe('constructor', () => { test('uses defaults without options', () => { const sentryCliPlugin = new SentryCliPlugin(); - expect(sentryCliPlugin.options).toEqual({ - rewrite: true, - }); + expect(sentryCliPlugin.options).toEqual(defaults); }); test('merges defaults with options', () => { @@ -35,10 +39,8 @@ describe('constructor', () => { foo: 42, }); - expect(sentryCliPlugin.options).toEqual({ - rewrite: true, - foo: 42, - }); + expect(sentryCliPlugin.options).toEqual(expect.objectContaining(defaults)); + expect(sentryCliPlugin.options.foo).toEqual(42); }); test('uses declared options over defaults', () => { @@ -46,19 +48,7 @@ describe('constructor', () => { rewrite: false, }); - expect(sentryCliPlugin.options).toEqual({ - rewrite: false, - }); - }); - - test('allows to provide debug mode', () => { - let sentryCliPlugin = new SentryCliPlugin(); - expect(sentryCliPlugin.debug).toEqual(false); - - sentryCliPlugin = new SentryCliPlugin({ - debug: true, - }); - expect(sentryCliPlugin.debug).toEqual(true); + expect(sentryCliPlugin.options.rewrite).toEqual(false); }); test('sanitizes array options `include` and `ignore`', () => { @@ -66,12 +56,8 @@ describe('constructor', () => { include: 'foo', ignore: 'bar', }); - - expect(sentryCliPlugin.options).toEqual({ - rewrite: true, - include: ['foo'], - ignore: ['bar'], - }); + expect(sentryCliPlugin.options.include).toEqual(['foo']); + expect(sentryCliPlugin.options.ignore).toEqual(['bar']); }); test('keeps array options `include` and `ignore`', () => { @@ -79,12 +65,8 @@ describe('constructor', () => { include: ['foo'], ignore: ['bar'], }); - - expect(sentryCliPlugin.options).toEqual({ - rewrite: true, - include: ['foo'], - ignore: ['bar'], - }); + expect(sentryCliPlugin.options.include).toEqual(['foo']); + expect(sentryCliPlugin.options.ignore).toEqual(['bar']); }); }); @@ -173,18 +155,44 @@ describe('afterEmitHook', () => { setImmediate(() => { expect(mockCli.releases.new).toBeCalledWith('42'); - expect(mockCli.releases.uploadSourceMaps).toBeCalledWith('42', { - ignore: undefined, - release: 42, - include: ['src'], - rewrite: true, - }); + expect(mockCli.releases.uploadSourceMaps).toBeCalledWith( + '42', + expect.objectContaining({ + release: 42, + include: ['src'], + }) + ); expect(mockCli.releases.finalize).toBeCalledWith('42'); expect(compilationDoneCallback).toBeCalled(); done(); }); }); + test('skips finalizing release if finalize:false', done => { + expect.assertions(4); + + const sentryCliPlugin = new SentryCliPlugin({ + include: 'src', + release: 42, + finalize: false, + }); + sentryCliPlugin.apply(compiler); + + setImmediate(() => { + expect(mockCli.releases.new).toBeCalledWith('42'); + expect(mockCli.releases.uploadSourceMaps).toBeCalledWith( + '42', + expect.objectContaining({ + release: 42, + include: ['src'], + }) + ); + expect(mockCli.releases.finalize).not.toBeCalled(); + expect(compilationDoneCallback).toBeCalled(); + done(); + }); + }); + test('handles errors during releasing', done => { expect.assertions(2); mockCli.releases.new.mockImplementationOnce(() => diff --git a/src/index.js b/src/index.js index d137146e..c534bbc9 100644 --- a/src/index.js +++ b/src/index.js @@ -71,10 +71,13 @@ function attachAfterEmitHook(compiler, callback) { class SentryCliPlugin { constructor(options = {}) { - this.debug = options.debug || false; + const defaults = { + debug: false, + finalize: true, + rewrite: true, + }; - // By default we want that rewrite is true - this.options = Object.assign({ rewrite: true }, options); + this.options = Object.assign({}, defaults, options); if (options.include) this.options.include = toArray(options.include); if (options.ignore) this.options.ignore = toArray(options.ignore); @@ -339,7 +342,12 @@ class SentryCliPlugin { }); } }) - .then(() => this.cli.releases.finalize(release)) + .then(() => { + if (this.options.finalize) { + return this.cli.releases.finalize(release); + } + return undefined; + }) .catch(err => errorHandler( err, @@ -354,7 +362,7 @@ class SentryCliPlugin { const compilerOptions = compiler.options || {}; ensure(compilerOptions, 'module', Object); - if (this.debug) { + if (this.options.debug) { this.injectReleaseWithDebug(compilerOptions); } else { this.injectRelease(compilerOptions);