11cb0ef41Sopenharmony_ciconst t = require('tap') 21cb0ef41Sopenharmony_ciconst path = require('path') 31cb0ef41Sopenharmony_ciconst fs = require('fs') 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst { load: loadMockNpm } = require('../../fixtures/mock-npm') 61cb0ef41Sopenharmony_ciconst MockRegistry = require('@npmcli/mock-registry') 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst treeWithDupes = { 91cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 101cb0ef41Sopenharmony_ci name: 'test-top', 111cb0ef41Sopenharmony_ci version: '1.0.0', 121cb0ef41Sopenharmony_ci dependencies: { 131cb0ef41Sopenharmony_ci 'test-dep-a': '*', 141cb0ef41Sopenharmony_ci 'test-dep-b': '*', 151cb0ef41Sopenharmony_ci }, 161cb0ef41Sopenharmony_ci }), 171cb0ef41Sopenharmony_ci node_modules: { 181cb0ef41Sopenharmony_ci 'test-dep-a': { 191cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 201cb0ef41Sopenharmony_ci name: 'test-dep-a', 211cb0ef41Sopenharmony_ci version: '1.0.1', 221cb0ef41Sopenharmony_ci dependencies: { 'test-sub': '*' }, 231cb0ef41Sopenharmony_ci }), 241cb0ef41Sopenharmony_ci node_modules: { 251cb0ef41Sopenharmony_ci 'test-sub': { 261cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 271cb0ef41Sopenharmony_ci name: 'test-sub', 281cb0ef41Sopenharmony_ci version: '1.0.0', 291cb0ef41Sopenharmony_ci }), 301cb0ef41Sopenharmony_ci }, 311cb0ef41Sopenharmony_ci }, 321cb0ef41Sopenharmony_ci }, 331cb0ef41Sopenharmony_ci 'test-dep-b': { 341cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 351cb0ef41Sopenharmony_ci name: 'test-dep-b', 361cb0ef41Sopenharmony_ci version: '1.0.0', 371cb0ef41Sopenharmony_ci dependencies: { 'test-sub': '*' }, 381cb0ef41Sopenharmony_ci }), 391cb0ef41Sopenharmony_ci node_modules: { 401cb0ef41Sopenharmony_ci 'test-sub': { 411cb0ef41Sopenharmony_ci 'package.json': JSON.stringify({ 421cb0ef41Sopenharmony_ci name: 'test-sub', 431cb0ef41Sopenharmony_ci version: '1.0.0', 441cb0ef41Sopenharmony_ci }), 451cb0ef41Sopenharmony_ci }, 461cb0ef41Sopenharmony_ci }, 471cb0ef41Sopenharmony_ci }, 481cb0ef41Sopenharmony_ci }, 491cb0ef41Sopenharmony_ci} 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_cit.test('should run dedupe in dryRun mode', async (t) => { 521cb0ef41Sopenharmony_ci const { npm, joinedOutput } = await loadMockNpm(t, { 531cb0ef41Sopenharmony_ci prefixDir: treeWithDupes, 541cb0ef41Sopenharmony_ci config: { 551cb0ef41Sopenharmony_ci // explicitly set to false so we can be 100% sure it's always true when it 561cb0ef41Sopenharmony_ci // hits arborist 571cb0ef41Sopenharmony_ci 'dry-run': false, 581cb0ef41Sopenharmony_ci }, 591cb0ef41Sopenharmony_ci }) 601cb0ef41Sopenharmony_ci const registry = new MockRegistry({ 611cb0ef41Sopenharmony_ci tap: t, 621cb0ef41Sopenharmony_ci registry: npm.config.get('registry'), 631cb0ef41Sopenharmony_ci }) 641cb0ef41Sopenharmony_ci 651cb0ef41Sopenharmony_ci const manifestSub = registry.manifest({ 661cb0ef41Sopenharmony_ci name: 'test-sub', 671cb0ef41Sopenharmony_ci manifests: [{ name: 'test-sub', version: '1.0.0' }], 681cb0ef41Sopenharmony_ci }) 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci await registry.package({ manifest: manifestSub }) 711cb0ef41Sopenharmony_ci await npm.exec('find-dupes', []) 721cb0ef41Sopenharmony_ci t.match(joinedOutput(), /added 1 package, and removed 2 packages/) 731cb0ef41Sopenharmony_ci t.notOk( 741cb0ef41Sopenharmony_ci fs.existsSync(path.join(npm.prefix, 'node_modules', 'test-sub')), 751cb0ef41Sopenharmony_ci 'test-sub was not hoisted' 761cb0ef41Sopenharmony_ci ) 771cb0ef41Sopenharmony_ci t.ok( 781cb0ef41Sopenharmony_ci fs.existsSync(path.join(npm.prefix, 'node_modules', 'test-dep-a', 'node_modules', 'test-sub')), 791cb0ef41Sopenharmony_ci 'test-dep-a/test-sub was not removed' 801cb0ef41Sopenharmony_ci ) 811cb0ef41Sopenharmony_ci t.ok( 821cb0ef41Sopenharmony_ci fs.existsSync(path.join(npm.prefix, 'node_modules', 'test-dep-b', 'node_modules', 'test-sub')), 831cb0ef41Sopenharmony_ci 'test-dep-b/test-sub was not removed') 841cb0ef41Sopenharmony_ci}) 85