Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2022-01-20 21:52:00 +0300
committerGitHub <noreply@github.com>2022-01-20 21:52:00 +0300
commitcfd59b8c81078f842328b13a23a234150842cd58 (patch)
tree74fd15153445b59dda6b1d5ec4e8c64436115e94 /smoke-tests
parent510f0ecbc9970ed8c8993107cc03cf27b7b996dc (diff)
fix: npm update --save (#4223)
Previously `npm update` was not respecting the `save` option, it would be impossible for users to use `npm update` and automatically update their `package.json` files. This fixes it by adding extra steps on `Arborist.reify._saveIdealTree` to read direct dependencies of any `package.json` and update them as needed when reifying using the `update` and `save` options. - Uses config.isDefault to set a different value for the `save` config for both the update and dedupe commands - Tweaks arborist to make sure saveIdealTree preserves the behavior of skipping writing to package-lock.json on save=false for install while still writing the lockfile for `npm update` with its new default value of save=false. - Updated and added some new tests on arborist to cover for these tweaks - Added `npm update --save` smoke test on cli Fixes: https://github.com/npm/cli/issues/708 Fixes: https://github.com/npm/cli/issues/2704 Relates to: https://github.com/npm/feedback/discussions/270
Diffstat (limited to 'smoke-tests')
-rw-r--r--smoke-tests/index.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/smoke-tests/index.js b/smoke-tests/index.js
index 06ca3dee6..83e54ae9f 100644
--- a/smoke-tests/index.js
+++ b/smoke-tests/index.js
@@ -267,3 +267,56 @@ t.test('npm pkg', async t => {
'should have expected npm pkg delete modified package.json result'
)
})
+
+t.test('npm update --no-save --no-package-lock', async t => {
+ // setup, manually reset dep value
+ await exec(`${npmBin} pkg set "dependencies.abbrev==1.0.4"`)
+ await exec(`${npmBin} install`)
+ await exec(`${npmBin} pkg set "dependencies.abbrev=^1.0.4"`)
+
+ const cmd = `${npmBin} update --no-save --no-package-lock`
+ await exec(cmd)
+
+ t.equal(
+ JSON.parse(readFile('package.json')).dependencies.abbrev,
+ '^1.0.4',
+ 'should have expected update --no-save --no-package-lock package.json result'
+ )
+ t.equal(
+ JSON.parse(readFile('package-lock.json')).packages['node_modules/abbrev'].version,
+ '1.0.4',
+ 'should have expected update --no-save --no-package-lock lockfile result'
+ )
+})
+
+t.test('npm update --no-save', async t => {
+ const cmd = `${npmBin} update --no-save`
+ await exec(cmd)
+
+ t.equal(
+ JSON.parse(readFile('package.json')).dependencies.abbrev,
+ '^1.0.4',
+ 'should have expected update --no-save package.json result'
+ )
+ t.equal(
+ JSON.parse(readFile('package-lock.json')).packages['node_modules/abbrev'].version,
+ '1.1.1',
+ 'should have expected update --no-save lockfile result'
+ )
+})
+
+t.test('npm update --save', async t => {
+ const cmd = `${npmBin} update --save`
+ await exec(cmd)
+
+ t.equal(
+ JSON.parse(readFile('package.json')).dependencies.abbrev,
+ '^1.1.1',
+ 'should have expected update --save package.json result'
+ )
+ t.equal(
+ JSON.parse(readFile('package-lock.json')).packages['node_modules/abbrev'].version,
+ '1.1.1',
+ 'should have expected update --save lockfile result'
+ )
+})