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
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 /smoke-tests
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 'smoke-tests')
-rw-r--r--smoke-tests/index.js40
-rw-r--r--smoke-tests/server.js8
2 files changed, 46 insertions, 2 deletions
diff --git a/smoke-tests/index.js b/smoke-tests/index.js
index 9235c8960..5e2d5e071 100644
--- a/smoke-tests/index.js
+++ b/smoke-tests/index.js
@@ -1,8 +1,9 @@
const fs = require('fs')
const { promisify } = require('util')
const execAsync = promisify(require('child_process').exec)
-const { resolve } = require('path')
+const { join, resolve } = require('path')
const t = require('tap')
+const rimraf = promisify(require('rimraf'))
const normalizePath = path => path.replace(/[A-Z]:/, '').replace(/\\/g, '/')
const cwd = normalizePath(process.cwd())
@@ -47,6 +48,43 @@ const exec = async cmd => {
const readFile = filename =>
String(fs.readFileSync(resolve(localPrefix, filename)))
+// this test must come first, its package.json will be destroyed and the one
+// created in the next test (npm init) will create a new one that must be
+// present for later tests
+t.test('npm install sends correct user-agent', async t => {
+ const pkgPath = join(localPrefix, 'package.json')
+ const pkgContent = JSON.stringify({
+ name: 'smoke-test-workspaces',
+ workspaces: ['packages/*'],
+ })
+ fs.writeFileSync(pkgPath, pkgContent, { encoding: 'utf8' })
+
+ const wsRoot = join(localPrefix, 'packages')
+ fs.mkdirSync(wsRoot)
+
+ const wsPath = join(wsRoot, 'foo')
+ fs.mkdirSync(wsPath)
+
+ const wsPkgPath = join(wsPath, 'package.json')
+ const wsContent = JSON.stringify({
+ name: 'foo',
+ })
+ fs.writeFileSync(wsPkgPath, wsContent, { encoding: 'utf8' })
+ t.teardown(async () => {
+ await rimraf(`${localPrefix}/*`)
+ })
+
+ const cmd = `${npmBin} install fail_reflect_user_agent`
+ await t.rejects(exec(cmd), {
+ stderr: /workspaces\/false/,
+ }, 'workspaces/false is present in output')
+
+ const wsCmd = `${npmBin} install fail_reflect_user_agent --workspaces`
+ await t.rejects(exec(wsCmd), {
+ stderr: /workspaces\/true/,
+ }, 'workspaces/true is present in output')
+})
+
t.test('npm init', async t => {
const cmd = `${npmBin} init -y`
const cmdRes = await exec(cmd)
diff --git a/smoke-tests/server.js b/smoke-tests/server.js
index b864114af..e0ac0c94e 100644
--- a/smoke-tests/server.js
+++ b/smoke-tests/server.js
@@ -1,5 +1,5 @@
/* istanbul ignore file */
-const {join, dirname} = require('path')
+const {join, dirname, basename} = require('path')
const {existsSync, readFileSync, writeFileSync} = require('fs')
const PORT = 12345 + (+process.env.TAP_CHILD_ID || 0)
const http = require('http')
@@ -150,6 +150,12 @@ const startServer = () => new Promise((res, rej) => {
}
const f = join(__dirname, 'content', join('/', req.url.replace(/@/, '').replace(/%2f/i, '/')))
+ // a magic package that causes us to return an error that will be logged
+ if (basename(f) === 'fail_reflect_user_agent') {
+ res.setHeader('npm-notice', req.headers['user-agent'])
+ res.writeHead(404)
+ return res.end()
+ }
const isCorgi = req.headers.accept.includes('application/vnd.npm.install-v1+json')
const file = f + (
isCorgi && existsSync(`${f}.min.json`) ? '.min.json'