Skip to content
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

tests(config): fix snapshot cleaner #3687

Merged
merged 1 commit into from
Aug 26, 2021
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
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