Skip to content

Commit

Permalink
fix: check process on browser (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
Creskendoll committed May 15, 2023
1 parent d7ee635 commit 090f64e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/ini.js
Expand Up @@ -8,8 +8,9 @@ const encode = (obj, opt = {}) => {
opt.newline = opt.newline === true
opt.sort = opt.sort === true
opt.whitespace = opt.whitespace === true || opt.align === true
// The `typeof` check is required because accessing the `process` directly fails on browsers.
/* istanbul ignore next */
opt.platform = opt.platform || process?.platform
opt.platform = opt.platform || (typeof process !== 'undefined' && process.platform)
opt.bracketedArray = opt.bracketedArray !== false

/* istanbul ignore next */
Expand Down Expand Up @@ -172,8 +173,8 @@ const decode = (str, opt = {}) => {
const remove = []
for (const k of Object.keys(out)) {
if (!hasOwnProperty.call(out, k) ||
typeof out[k] !== 'object' ||
Array.isArray(out[k])) {
typeof out[k] !== 'object' ||
Array.isArray(out[k])) {
continue
}

Expand Down
10 changes: 10 additions & 0 deletions tap-snapshots/test/foo.js.test.cjs
Expand Up @@ -292,3 +292,13 @@ label = debug
value = 10
`

exports[`test/foo.js TAP encode within browser context > must match snapshot 1`] = `
[log]
type=file
[log.level]
label=debug
value=10
`
10 changes: 10 additions & 0 deletions test/foo.js
Expand Up @@ -84,3 +84,13 @@ test('encode with align and sort', function (t) {
t.matchSnapshot(e)
t.end()
})

test('encode within browser context', function (t) {
Object.defineProperty(process, 'platform', { value: undefined })

const obj = { log: { type: 'file', level: { label: 'debug', value: 10 } } }
const e = i.encode(obj)

t.matchSnapshot(e)
t.end()
})

0 comments on commit 090f64e

Please sign in to comment.