| 1 |
|
| 2 |
const t = require('tap') |
| 3 |
const setup = require('./fixtures/setup.js') |
| 4 |
|
| 5 |
t.test('install links with package lock only', async t => { |
| 6 |
const setupTest = async (t) => { |
| 7 |
const mock = await setup(t, { |
| 8 |
testdir: { |
| 9 |
project: { |
| 10 |
'package.json': { |
| 11 |
name: 'root', |
| 12 |
version: '1.0.0', |
| 13 |
workspaces: ['workspaces/*'], |
| 14 |
}, |
| 15 |
workspaces: { |
| 16 |
pkg1: { |
| 17 |
'package.json': { |
| 18 |
name: '@npmcli/pkg1', |
| 19 |
version: '1.0.0', |
| 20 |
dependencies: { '@npmcli/pkg3': '^1.0.0' }, |
| 21 |
}, |
| 22 |
}, |
| 23 |
pkg2: { |
| 24 |
'package.json': { |
| 25 |
name: '@npmcli/pkg2', |
| 26 |
version: '1.0.0', |
| 27 |
dependencies: { '@npmcli/pkg3': '^1.0.0' }, |
| 28 |
}, |
| 29 |
}, |
| 30 |
pkg3: { |
| 31 |
'package.json': { |
| 32 |
name: '@npmcli/pkg3', |
| 33 |
version: '1.0.0', |
| 34 |
}, |
| 35 |
}, |
| 36 |
}, |
| 37 |
}, |
| 38 |
}, |
| 39 |
}) |
| 40 |
const { npm } = mock |
| 41 |
|
| 42 |
// generate an initially valid lockfile |
| 43 |
await npm('install', '--package-lock-only', '--install-links=false') |
| 44 |
|
| 45 |
// manually set version and semver ranges for pkg3 |
| 46 |
await npm('pkg', 'set', '--workspace=@npmcli/pkg1', 'dependencies.@npmcli/pkg3=^1.0.1') |
| 47 |
await npm('pkg', 'set', '--workspace=@npmcli/pkg2', 'dependencies.@npmcli/pkg3=^1.0.1') |
| 48 |
await npm('pkg', 'set', '--workspace=@npmcli/pkg3', 'version=1.0.1') |
| 49 |
|
| 50 |
return mock |
| 51 |
} |
| 52 |
|
| 53 |
await t.test('updates package lock with install-links=false', async t => { |
| 54 |
const { npm, readFile } = await setupTest(t) |
| 55 |
|
| 56 |
await npm('install', '--package-lock-only', '--install-links=false') |
| 57 |
|
| 58 |
const lock = await readFile('package-lock.json') |
| 59 |
t.equal(lock.packages['workspaces/pkg3'].version, '1.0.1') |
| 60 |
}) |
| 61 |
|
| 62 |
// See https://github.com/npm/cli/issues/5967 for full bug |
| 63 |
// change to t.test when this gets fixed |
| 64 |
await t.todo('updates package lock with install-links=true', async t => { |
| 65 |
const { npm, readFile, registry } = await setupTest(t) |
| 66 |
|
| 67 |
// TODO: this test should pass the same as the previous one. For debugging |
| 68 |
// purposes the @npmcli/pkg3 package is mocked with only version 1.0.0 so |
| 69 |
// the `npm install` command will fail, instead of nock failing for the |
| 70 |
// missing request. But a proper fix for this will not need any registry |
| 71 |
// requests mocked. |
| 72 |
await registry.package({ |
| 73 |
manifest: registry.manifest({ name: '@npmcli/pkg3', versions: ['1.0.0'] }), |
| 74 |
times: 1, |
| 75 |
}) |
| 76 |
|
| 77 |
await npm('install', '--package-lock-only', '--install-links=true') |
| 78 |
|
| 79 |
const lock = await readFile('package-lock.json') |
| 80 |
t.equal(lock.packages['workspaces/pkg3'].version, '1.0.1') |
| 81 |
}) |
| 82 |
}) |