Skip to content

Commit 39b3ba2

Browse files
committed
fixup! fix(config): user-agent properly shows ci
1 parent 0de45b8 commit 39b3ba2

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

smoke-tests/index.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const fs = require('fs')
22
const { promisify } = require('util')
33
const execAsync = promisify(require('child_process').exec)
4-
const { resolve } = require('path')
4+
const { join, resolve } = require('path')
55
const t = require('tap')
6+
const rimraf = promisify(require('rimraf'))
67

78
const normalizePath = path => path.replace(/[A-Z]:/, '').replace(/\\/g, '/')
89
const cwd = normalizePath(process.cwd())
@@ -47,6 +48,43 @@ const exec = async cmd => {
4748
const readFile = filename =>
4849
String(fs.readFileSync(resolve(localPrefix, filename)))
4950

51+
// this test must come first, its package.json will be destroyed and the one
52+
// created in the next test (npm init) will create a new one that must be
53+
// present for later tests
54+
t.test('npm install sends correct user-agent', async t => {
55+
const pkgPath = join(localPrefix, 'package.json')
56+
const pkgContent = JSON.stringify({
57+
name: 'smoke-test-workspaces',
58+
workspaces: ['packages/*'],
59+
})
60+
fs.writeFileSync(pkgPath, pkgContent, { encoding: 'utf8' })
61+
62+
const wsRoot = join(localPrefix, 'packages')
63+
fs.mkdirSync(wsRoot)
64+
65+
const wsPath = join(wsRoot, 'foo')
66+
fs.mkdirSync(wsPath)
67+
68+
const wsPkgPath = join(wsPath, 'package.json')
69+
const wsContent = JSON.stringify({
70+
name: 'foo',
71+
})
72+
fs.writeFileSync(wsPkgPath, wsContent, { encoding: 'utf8' })
73+
t.teardown(async () => {
74+
await rimraf(`${localPrefix}/*`)
75+
})
76+
77+
const cmd = `${npmBin} install fail_reflect_user_agent`
78+
await t.rejects(exec(cmd), {
79+
stderr: /workspaces\/false/,
80+
}, 'workspaces/false is present in output')
81+
82+
const wsCmd = `${npmBin} install fail_reflect_user_agent --workspaces`
83+
await t.rejects(exec(wsCmd), {
84+
stderr: /workspaces\/true/,
85+
}, 'workspaces/true is present in output')
86+
})
87+
5088
t.test('npm init', async t => {
5189
const cmd = `${npmBin} init -y`
5290
const cmdRes = await exec(cmd)

smoke-tests/server.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* istanbul ignore file */
2-
const {join, dirname} = require('path')
2+
const {join, dirname, basename} = require('path')
33
const {existsSync, readFileSync, writeFileSync} = require('fs')
44
const PORT = 12345 + (+process.env.TAP_CHILD_ID || 0)
55
const http = require('http')
@@ -150,6 +150,12 @@ const startServer = () => new Promise((res, rej) => {
150150
}
151151

152152
const f = join(__dirname, 'content', join('/', req.url.replace(/@/, '').replace(/%2f/i, '/')))
153+
// a magic package that causes us to return an error that will be logged
154+
if (basename(f) === 'fail_reflect_user_agent') {
155+
res.setHeader('npm-notice', req.headers['user-agent'])
156+
res.writeHead(404)
157+
return res.end()
158+
}
153159
const isCorgi = req.headers.accept.includes('application/vnd.npm.install-v1+json')
154160
const file = f + (
155161
isCorgi && existsSync(`${f}.min.json`) ? '.min.json'

0 commit comments

Comments
 (0)