Skip to content

Commit

Permalink
Fix/avoid expcetions on node (#4)
Browse files Browse the repository at this point in the history
* fix level obtention

* remove unnecessary vars from travis config
  • Loading branch information
alextremp authored Jun 9, 2020
1 parent 7612d40 commit dbbaa82
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ cache:
before_install:
- npm config set //registry.npmjs.org/:_authToken=$NPM_TOKEN
script:
- npm run check && TRAVIS_TAG=$TRAVIS_TAG GH_TOKEN=$GH_TOKEN npm run versiona
- npm run check && npm run versiona
- npm run coverage:ci

after_success:
Expand Down
12 changes: 12 additions & 0 deletions src/integration-test/PikoTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {JSDOM} from 'jsdom'
import {expect} from 'chai'
import sinon from 'sinon'
import Piko from '../main/index'
import {DEFAULT_LEVEL} from '../main/domain/constants'

describe('Piko', () => {
const dom = new JSDOM('<!DOCTYPE html><body></body>', {
Expand Down Expand Up @@ -335,5 +336,16 @@ describe('Piko', () => {
expect(errorSpy.args[0][1]).to.equal(aFatalMessage)
expect(errorSpy.args[0][2]).to.equal(error)
})
it('should not fail on invalid configured level', () => {
const key1 = 'key1'
const key2 = 'key2'
window.localStorage.setItem('piko.level.key1', undefined)
window.localStorage.setItem('piko.level.key2', 'invent')
const logger1 = Piko.logger(key1)
const logger2 = Piko.logger(key2)

expect(logger1._level._level).to.equal(DEFAULT_LEVEL)
expect(logger2._level._level).to.equal(DEFAULT_LEVEL)
})
})
})
12 changes: 5 additions & 7 deletions src/main/domain/Level.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ export class Level {
_getLevel() {
if (typeof window !== 'undefined') {
try {
return (
const value =
window.localStorage.getItem(`${LOCAL_STORAGE_KEY}.${this._key}`) ||
window.localStorage.getItem(LOCAL_STORAGE_KEY) ||
DEFAULT_LEVEL
)
} catch {
return DEFAULT_LEVEL
}
window.localStorage.getItem(LOCAL_STORAGE_KEY)
return (!!LEVEL[value] && value) || DEFAULT_LEVEL
} catch {}
}
return DEFAULT_LEVEL
}

shouldLogTrace() {
Expand Down

0 comments on commit dbbaa82

Please sign in to comment.