Skip to content

[OASIS-3799] Tests for automatically created logger instances #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/optimizely-sdk/lib/index.browser.umdtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,46 @@ describe('javascript-sdk', function() {
var variation = optlyInstance.getVariation('testExperimentNotRunning', 'testUser');
assert.strictEqual(variation, null);
});

describe('automatically created logger instances', function() {
beforeEach(function() {
sinon.spy(console, 'log')
});

afterEach(function() {
console.log.restore();
});

it('should instantiate the logger with a custom logLevel when provided', function() {
// checking that INFO logs do not log for a logLevel of ERROR
var optlyInstance = window.optimizelySdk.createInstance({
datafile: testData.getTestProjectConfig(),
logLevel: enums.LOG_LEVEL.ERROR,
skipJSONValidation: true
});
assert.strictEqual(console.log.getCalls().length, 0)

// checking that ERROR logs do log for a logLevel of ERROR
var optlyInstanceInvalid = window.optimizelySdk.createInstance({
datafile: {},
logLevel: enums.LOG_LEVEL.ERROR
});
optlyInstance.activate('testExperiment', 'testUser')
assert.strictEqual(console.error.getCalls().length, 1)
});

it('should default to INFO when no logLevel is provided', function() {
// checking that INFO logs log for an unspecified logLevel
var optlyInstance = window.optimizelySdk.createInstance({
datafile: testData.getTestProjectConfig(),
skipJSONValidation: true
});
assert.strictEqual(console.log.getCalls().length, 1)
call = console.log.getCalls()[0]
assert.strictEqual(call.args.length, 1)
assert(call.args[0].indexOf('OPTIMIZELY: Skipping JSON schema validation.') > -1)
});
});
});
});
});