Skip to content

Commit

Permalink
fixup! feat: streaming debug logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Nov 30, 2021
1 parent e8a8f84 commit 3ac7224
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
35 changes: 13 additions & 22 deletions test/fixtures/mock-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const getPropertyDescriptor = (obj, key, fullKey) => {

const _pushDescriptor = Symbol('pushDescriptor')
const _popDescriptor = Symbol('popDescriptor')
const _createReset = Symbol('createReset')
const _set = Symbol('set')

class MockGlobals {
Expand All @@ -85,7 +84,7 @@ class MockGlobals {
}

teardown () {
this.#resets.forEach(r => r.reset(true))
this.#resets.forEach(r => r.reset())
}

registerGlobals (globals, { replace = false } = {}) {
Expand Down Expand Up @@ -120,24 +119,6 @@ class MockGlobals {
return value
}

[_createReset] (parent, key, fullKey) {
return {
fullKey,
key,
reset: () => {
const popped = this[_popDescriptor](fullKey)
// undefined means delete the property so only skip
// if it is explicitly null
if (popped === null) {
return
}
return popped
? Object.defineProperty(parent, key, popped)
: (delete parent[key])
},
}
}

[_set] (fullKey, globals) {
const values = getGlobalAncestors(fullKey)
const parentValue = values[values.length - 2]
Expand All @@ -148,7 +129,17 @@ class MockGlobals {
const currentDescriptor = getPropertyDescriptor(parentValue, key, fullKey)
this[_pushDescriptor](fullKey, currentDescriptor)

const reset = this[_createReset](parentValue, key, fullKey)
const reset = () => {
const popped = this[_popDescriptor](fullKey)
// undefined means delete the property so only skip
// if it is explicitly null
if (popped === null) {
return
}
return popped
? Object.defineProperty(parentValue, key, popped)
: (delete parentValue[key])
}

if (newValue === undefined) {
delete parentValue[key]
Expand All @@ -162,7 +153,7 @@ class MockGlobals {
Object.defineProperty(parentValue, key, newDescriptor)
}

return reset
return { fullKey, reset }
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/lib/fixtures/mock-globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,15 @@ t.test('mixed object/string mode', async t => {
t.equal(process.env.TEST, undefined)
})

t.test('deletes prop', async t => {
await t.test('mocks', async t => {
mockGlobals(t, { 'process.platform': undefined })
t.equal(process.platform, undefined)
})

t.equal(process.platform, originals.platform)
})

t.test('date', async t => {
await t.test('mocks', async t => {
mockGlobals(t, {
Expand Down

0 comments on commit 3ac7224

Please sign in to comment.