This repository has been archived by the owner on Aug 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
deps: When we replace/upgrade a dep, remove all its deps too
PR-URL: #9929
- Loading branch information
Showing
2 changed files
with
70 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict' | ||
var test = require('tap').test | ||
var npm = require('../../lib/npm') | ||
|
||
test('setup', function (t) { | ||
npm.load({}, t.done) | ||
}) | ||
|
||
test('replaceModule', function (t) { | ||
var replaceModule = require('../../lib/install/deps').test.replaceModule | ||
var mods = [] | ||
for (var ii = 0; ii < 10; ++ii) { | ||
mods.push({package: {name: ii}}) | ||
} | ||
|
||
var test = {} | ||
test.A = mods.slice(0, 4) | ||
replaceModule(test, 'A', mods[2]) | ||
t.isDeeply(test.A, mods.slice(0, 4), 'replacing an existing module leaves the order alone') | ||
replaceModule(test, 'A', mods[7]) | ||
t.isDeeply(test.A, mods.slice(0, 4).concat(mods[7]), 'replacing a new module appends') | ||
|
||
test.B = mods.slice(0, 4) | ||
var replacement = {package: {name: 1}, isReplacement: true} | ||
replaceModule(test, 'B', replacement) | ||
t.isDeeply(test.B, [mods[0], replacement, mods[2], mods[3]], 'replacing existing module swaps out for the new version') | ||
|
||
replaceModule(test, 'C', mods[7]) | ||
t.isDeeply(test.C, [mods[7]], 'replacing when the key does not exist yet, causes its creation') | ||
t.end() | ||
}) | ||
|
||
test('replaceModuleName', function (t) { | ||
var replaceModuleName = require('../../lib/install/deps').test.replaceModuleName | ||
var mods = [] | ||
for (var ii = 0; ii < 10; ++ii) { | ||
mods.push('pkg' + ii) | ||
} | ||
|
||
var test = {} | ||
test.A = mods.slice(0, 4) | ||
replaceModuleName(test, 'A', mods[2]) | ||
t.isDeeply(test.A, mods.slice(0, 4), 'replacing an existing module leaves the order alone') | ||
replaceModuleName(test, 'A', mods[7]) | ||
t.isDeeply(test.A, mods.slice(0, 4).concat(mods[7]), 'replacing a new module appends') | ||
|
||
replaceModuleName(test, 'C', mods[7]) | ||
t.isDeeply(test.C, [mods[7]], 'replacing when the key does not exist yet, causes its creation') | ||
t.end() | ||
}) |