|
1 | 1 | const fs = require('fs')
|
2 | 2 | const { promisify } = require('util')
|
3 | 3 | const execAsync = promisify(require('child_process').exec)
|
4 |
| -const { resolve } = require('path') |
| 4 | +const { join, resolve } = require('path') |
5 | 5 | const t = require('tap')
|
| 6 | +const rimraf = promisify(require('rimraf')) |
6 | 7 |
|
7 | 8 | const normalizePath = path => path.replace(/[A-Z]:/, '').replace(/\\/g, '/')
|
8 | 9 | const cwd = normalizePath(process.cwd())
|
@@ -47,6 +48,43 @@ const exec = async cmd => {
|
47 | 48 | const readFile = filename =>
|
48 | 49 | String(fs.readFileSync(resolve(localPrefix, filename)))
|
49 | 50 |
|
| 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 | + |
50 | 88 | t.test('npm init', async t => {
|
51 | 89 | const cmd = `${npmBin} init -y`
|
52 | 90 | const cmdRes = await exec(cmd)
|
|
0 commit comments