|
1 | 1 | const t = require('tap')
|
2 |
| -const { resolve } = require('path') |
| 2 | +const { resolve, join } = require('path') |
3 | 3 | const fs = require('fs')
|
4 | 4 |
|
5 | 5 | const Arborist = require('@npmcli/arborist')
|
6 |
| -const { fake: mockNpm } = require('../../fixtures/mock-npm') |
| 6 | +const { fake: mockNpm, load: fullMockNpm } = require('../../fixtures/mock-npm') |
7 | 7 |
|
8 | 8 | const redactCwd = (path) => {
|
9 | 9 | const normalizePath = p => p
|
@@ -72,7 +72,6 @@ t.test('link to globalDir when in current working dir of pkg and no args', async
|
72 | 72 | path: resolve(npm.globalDir, '..'),
|
73 | 73 | global: true,
|
74 | 74 | })
|
75 |
| - |
76 | 75 | t.matchSnapshot(links, 'should create a global link to current pkg')
|
77 | 76 | })
|
78 | 77 |
|
@@ -550,3 +549,35 @@ t.test('hash character in working directory path', async t => {
|
550 | 549 |
|
551 | 550 | t.matchSnapshot(links, 'should create a global link to current pkg, even within path with hash')
|
552 | 551 | })
|
| 552 | + |
| 553 | +t.test('test linked installed as symlinks', async t => { |
| 554 | + // fakeMock is insufficient due to lack of flatOptions |
| 555 | + const { npm } = await fullMockNpm(t, { |
| 556 | + otherDirs: { |
| 557 | + mylink: { |
| 558 | + 'package.json': JSON.stringify({ |
| 559 | + name: 'mylink', |
| 560 | + version: '1.0.0', |
| 561 | + }), |
| 562 | + }, |
| 563 | + }, |
| 564 | + }) |
| 565 | + const link = new Link(npm) |
| 566 | + |
| 567 | + const _cwd = process.cwd() |
| 568 | + process.chdir(npm.prefix) |
| 569 | + |
| 570 | + await npm.exec('link', [ |
| 571 | + join('file:../other/mylink'), |
| 572 | + ]) |
| 573 | + process.chdir(_cwd) |
| 574 | + const links = await printLinks({ |
| 575 | + path: npm.prefix, |
| 576 | + }) |
| 577 | + |
| 578 | + t.ok(fs.lstatSync(join(npm.prefix, 'node_modules', 'mylink')).isSymbolicLink(), |
| 579 | + 'linked path should by symbolic link' |
| 580 | + ) |
| 581 | + |
| 582 | + t.matchSnapshot(links, 'linked package should not be installed') |
| 583 | +}) |
0 commit comments