Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2021-08-26 20:58:44 +0300
committerGar <gar+gh@danger.computer>2021-08-26 21:18:17 +0300
commit7af36bb9f8e5c9facaa8deb114b76368841fbc66 (patch)
treeecf074f364a796c804bc2caddb80fbd516b38348 /test
parent4e52217cb25a697b0f6b0131bcb8c87e0dbcda53 (diff)
tests(config): fix snapshot cleaner
Order matters here so we clean the more specific things before the generic ones. PR-URL: https://github.com/npm/cli/pull/3687 Credit: @wraithgar Close: #3687 Reviewed-by: @nlf
Diffstat (limited to 'test')
-rw-r--r--test/fixtures/sandbox.js35
1 files changed, 20 insertions, 15 deletions
diff --git a/test/fixtures/sandbox.js b/test/fixtures/sandbox.js
index 45af373d2..4cdd9b70d 100644
--- a/test/fixtures/sandbox.js
+++ b/test/fixtures/sandbox.js
@@ -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
@@ -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
}