Skip to content

Commit

Permalink
fix: account for browser when mocking environment
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Dec 17, 2020
1 parent eb75af3 commit f536638
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,29 @@ describe('BatchSpanProcessor', () => {
});

it('should read defaults from environment', () => {
const envStub = sinon.stub(process, 'env').value({
const bspConfig = {
OTEL_BSP_MAX_BATCH_SIZE: 256,
OTEL_BSP_SCHEDULE_DELAY_MILLIS: 2500,
};

let env: Record<string, any>;
if (typeof process === 'undefined') {
env = (window as unknown) as Record<string, any>;
} else {
env = process.env as Record<string, any>;
}

Object.entries(bspConfig).forEach(([k, v]) => {
env[k] = v;
});

const processor = new BatchSpanProcessor(exporter);
assert.ok(processor instanceof BatchSpanProcessor);
assert.strictEqual(processor['_bufferSize'], 256);
assert.strictEqual(processor['_bufferTimeout'], 2500);
processor.shutdown();
envStub.restore();

Object.keys(bspConfig).forEach(k => delete env[k]);
});
});

Expand Down

0 comments on commit f536638

Please sign in to comment.