Skip to content
This repository has been archived by the owner on Nov 20, 2023. It is now read-only.

Commit

Permalink
feat: Allow for skiping release finalization (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Nov 12, 2019
1 parent 8ee86c4 commit 9c4592c
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 43 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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) |
Expand Down
84 changes: 46 additions & 38 deletions src/__tests__/index.spec.js
Expand Up @@ -21,70 +21,52 @@ 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', () => {
const sentryCliPlugin = new SentryCliPlugin({
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', () => {
const sentryCliPlugin = new SentryCliPlugin({
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`', () => {
const sentryCliPlugin = new SentryCliPlugin({
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`', () => {
const sentryCliPlugin = new SentryCliPlugin({
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']);
});
});

Expand Down Expand Up @@ -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(() =>
Expand Down
18 changes: 13 additions & 5 deletions src/index.js
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down

0 comments on commit 9c4592c

Please sign in to comment.