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-09-14 17:27:36 +0300
committerGar <gar+gh@danger.computer>2021-09-14 20:16:22 +0300
commitb4aac345b0a7cdec4d713c5be4daea37330b2b26 (patch)
tree05b55e7ba11290476477dcef4d4339e7b082d212 /test
parent291d977e09f5c17fa2ef8fccda6a61a24cb6d590 (diff)
fix(config): user-agent properly shows ci
The way we were flattening user-agent back into itself meant that any values that were dependent on other config items would never be seen, since we have to re-flatten the item for each one it depends on. We also weren't re-flattening the user-agent when setting workspaces or workspace, which were things that affected the final result. This does change the main config value of `user-agent` but not the flattened one. We are not using the main config value anywhere (which is correct). PR-URL: https://github.com/npm/cli/pull/3754 Credit: @wraithgar Close: #3754 Reviewed-by: @nlf
Diffstat (limited to 'test')
-rw-r--r--test/lib/utils/config/definitions.js30
1 files changed, 26 insertions, 4 deletions
diff --git a/test/lib/utils/config/definitions.js b/test/lib/utils/config/definitions.js
index 65193020d..88993303b 100644
--- a/test/lib/utils/config/definitions.js
+++ b/test/lib/utils/config/definitions.js
@@ -747,7 +747,7 @@ t.test('user-agent', t => {
definitions['user-agent'].flatten('user-agent', obj, flat)
t.equal(flat.userAgent, expectNoCI)
t.equal(process.env.npm_config_user_agent, flat.userAgent, 'npm_user_config environment is set')
- t.equal(obj['user-agent'], flat.userAgent, 'config user-agent template is translated')
+ t.not(obj['user-agent'], flat.userAgent, 'config user-agent template is not translated')
obj['ci-name'] = 'foo'
obj['user-agent'] = definitions['user-agent'].default
@@ -755,7 +755,7 @@ t.test('user-agent', t => {
definitions['user-agent'].flatten('user-agent', obj, flat)
t.equal(flat.userAgent, expectCI)
t.equal(process.env.npm_config_user_agent, flat.userAgent, 'npm_user_config environment is set')
- t.equal(obj['user-agent'], flat.userAgent, 'config user-agent template is translated')
+ t.not(obj['user-agent'], flat.userAgent, 'config user-agent template is not translated')
delete obj['ci-name']
obj.workspaces = true
@@ -764,7 +764,7 @@ t.test('user-agent', t => {
definitions['user-agent'].flatten('user-agent', obj, flat)
t.equal(flat.userAgent, expectWorkspaces)
t.equal(process.env.npm_config_user_agent, flat.userAgent, 'npm_user_config environment is set')
- t.equal(obj['user-agent'], flat.userAgent, 'config user-agent template is translated')
+ t.not(obj['user-agent'], flat.userAgent, 'config user-agent template is not translated')
delete obj.workspaces
obj.workspace = ['foo']
@@ -772,7 +772,7 @@ t.test('user-agent', t => {
definitions['user-agent'].flatten('user-agent', obj, flat)
t.equal(flat.userAgent, expectWorkspaces)
t.equal(process.env.npm_config_user_agent, flat.userAgent, 'npm_user_config environment is set')
- t.equal(obj['user-agent'], flat.userAgent, 'config user-agent template is translated')
+ t.not(obj['user-agent'], flat.userAgent, 'config user-agent template is not translated')
t.end()
})
@@ -853,3 +853,25 @@ t.test('package-lock-only', t => {
t.strictSame(flat, { packageLock: false, packageLockOnly: false })
t.end()
})
+
+t.test('workspaces', t => {
+ const obj = {
+ workspaces: true,
+ 'user-agent': definitions['user-agent'].default,
+ }
+ const flat = {}
+ definitions.workspaces.flatten('workspaces', obj, flat)
+ t.match(flat.userAgent, /workspaces\/true/)
+ t.end()
+})
+
+t.test('workspace', t => {
+ const obj = {
+ workspace: ['workspace-a'],
+ 'user-agent': definitions['user-agent'].default,
+ }
+ const flat = {}
+ definitions.workspace.flatten('workspaces', obj, flat)
+ t.match(flat.userAgent, /workspaces\/true/)
+ t.end()
+})