Skip to content

Commit

Permalink
tests(config): fix snapshot cleaner
Browse files Browse the repository at this point in the history
Order matters here so we clean the more specific things before the
generic ones.

PR-URL: #3687
Credit: @wraithgar
Close: #3687
Reviewed-by: @nlf
  • Loading branch information
wraithgar committed Aug 26, 2021
1 parent 4e52217 commit 7af36bb
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions test/fixtures/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,6 @@ class Sandbox extends EventEmitter {
cleanSnapshot (snapshot) {
let clean = normalize(snapshot)

if (this[_npm]) {
// replace default config values with placeholders
for (const name of redactedDefaults) {
let value = this[_npm].config.defaults[name]
clean = clean.split(value).join(`{${name.toUpperCase()}}`)
}

// replace vague default config values that are present within quotes
// with placeholders
for (const name of vagueRedactedDefaults) {
const value = this[_npm].config.defaults[name]
clean = clean.split(`"${value}"`).join(`"{${name.toUpperCase()}}"`)
}
}

const viewer = _process.platform === 'win32'
? /"browser"([^:]+|$)/g
: /"man"([^:]+|$)/g
Expand Down Expand Up @@ -180,6 +165,26 @@ class Sandbox extends EventEmitter {
.split(this[_proxy].platform).join('{PLATFORM}')
.split(this[_proxy].arch).join('{ARCH}')

// We do the defaults after everything else so that they don't cause the
// other cleaners to miss values we would have clobbered here. For
// instance if execPath is /home/user/.nvm/versions/node/1.0.0/bin/node,
// and we replaced the node version first, the real execPath we're trying
// to replace would no longer be represented, and be missed.
if (this[_npm]) {
// replace default config values with placeholders
for (const name of redactedDefaults) {
let value = this[_npm].config.defaults[name]
clean = clean.split(value).join(`{${name.toUpperCase()}}`)
}

// replace vague default config values that are present within quotes
// with placeholders
for (const name of vagueRedactedDefaults) {
const value = this[_npm].config.defaults[name]
clean = clean.split(`"${value}"`).join(`"{${name.toUpperCase()}}"`)
}
}

return clean
}

Expand Down

0 comments on commit 7af36bb

Please sign in to comment.