diff options
author | Tim Oxley <secoif@gmail.com> | 2014-05-11 01:07:44 +0400 |
---|---|---|
committer | Tim Oxley <secoif@gmail.com> | 2014-05-11 01:08:19 +0400 |
commit | c8242a25a091de4cc68e6178ff8fb756657e4902 (patch) | |
tree | 7a7e1a37667a0aaf2a9b469dd95e8c016e3ce1d2 | |
parent | 1f108b8a1f0f28a21b4ba4d0b86037abfd426dcd (diff) |
Test update + optional dependencies behaviour.
-rw-r--r-- | test/tap/update-save.js | 94 |
1 files changed, 85 insertions, 9 deletions
diff --git a/test/tap/update-save.js b/test/tap/update-save.js index 6771c6254..7a8801b1c 100644 --- a/test/tap/update-save.js +++ b/test/tap/update-save.js @@ -14,7 +14,11 @@ var MODULES_DIR = path.resolve(PKG_DIR, "node_modules") var EXEC_OPTS = { cwd: PKG_DIR, - stdio: 'ignore' + stdio: 'ignore', + env: { + npm_config_registry: common.registry, + npm_config_loglevel: 'verbose' + } } var DEFAULT_PKG = { @@ -28,7 +32,7 @@ var DEFAULT_PKG = { } } -var s = undefined +var s = undefined // mock server reference test('setup', function (t) { resetPackage() @@ -48,10 +52,11 @@ test("update regular dependencies only", function (t) { common.npm(['update', '--save'], EXEC_OPTS, function (err, code) { t.ifError(err) t.equal(code, 0) + var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8')) t.deepEqual(pkgdata.dependencies, {mkdirp: '^0.3.5'}, 'only dependencies updated') - t.deepEqual(pkgdata.devDependencies, {underscore: '~1.3.1'}, 'dev dependencies should be untouched') - s.close() + t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, 'dev dependencies should be untouched') + t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, 'optional dependencies should be untouched') t.end() }) }) @@ -59,29 +64,100 @@ test("update regular dependencies only", function (t) { test("update devDependencies only", function (t) { resetPackage() - common.npm(['update', '--save-dev'], EXEC_OPTS, function (err, code) { + common.npm(['update', '--save-dev'], EXEC_OPTS, function (err, code, stdout, stderr) { t.ifError(err) t.equal(code, 0) + var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8')) + t.deepEqual(pkgdata.dependencies, DEFAULT_PKG.dependencies, 'dependencies should be untouched') t.deepEqual(pkgdata.devDependencies, {underscore: '^1.3.3'}, 'dev dependencies should be updated') - t.deepEqual(pkgdata.dependencies, {mkdirp: '~0.3.0'}, 'dependencies should be untouched') + t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, 'optional dependencies should be untouched') t.end() }) }) +test("update optionalDependencies only", function (t) { + resetPackage({ + "optionalDependencies": { + "underscore": "~1.3.1" + } + }) + + common.npm(['update', '--save-optional'], EXEC_OPTS, function (err, code) { + t.ifError(err) + t.equal(code, 0) -function resetPackage() { + var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8')) + t.deepEqual(pkgdata.dependencies, DEFAULT_PKG.dependencies, 'dependencies should be untouched') + t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, 'dev dependencies should be untouched') + t.deepEqual(pkgdata.optionalDependencies, {underscore: '^1.3.3'}, 'optional dependencies should be updated') + t.end() + }) +}) + +test("optionalDependencies are merged into dependencies during --save", function (t) { + var pkg = resetPackage({ + "optionalDependencies": { + "underscore": "~1.3.1" + } + }) + + common.npm(['update', '--save'], EXEC_OPTS, function (err, code) { + t.ifError(err) + t.equal(code, 0) + + var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8')) + t.deepEqual(pkgdata.dependencies, { + mkdirp: '^0.3.5', + underscore: '^1.3.3' + }, 'dependencies should be updated with optional dependencies') + t.deepEqual(pkgdata.devDependencies, pkg.devDependencies, 'dev dependencies should be untouched') + t.deepEqual(pkgdata.optionalDependencies, pkg.optionalDependencies, 'optional dependencies should be untouched') + t.end() + }) +}) + +test("semver prefix is replaced with configured save-prefix", function (t) { + resetPackage() + + common.npm(['update', '--save', '--save-prefix', '~'], EXEC_OPTS, function (err, code) { + t.ifError(err) + t.equal(code, 0) + + var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8')) + t.deepEqual(pkgdata.dependencies, { + mkdirp: '~0.3.5' + }, 'dependencies should be updated') + t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, 'dev dependencies should be untouched') + t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, 'optional dependencies should be updated') + t.end() + }) +}) + +function resetPackage(extendWith) { rimraf.sync(CACHE_DIR) rimraf.sync(MODULES_DIR) mkdirp.sync(CACHE_DIR) - - fs.writeFileSync(PKG, JSON.stringify(DEFAULT_PKG, null, 2), 'ascii') + var pkg = clone(DEFAULT_PKG) + extend(pkg, extendWith) + for (key in extend) { pkg[key] = extend[key]} + fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2), 'ascii') + return pkg } test("cleanup", function (t) { + s.close() resetPackage() // restore package.json rimraf.sync(CACHE_DIR) rimraf.sync(MODULES_DIR) t.end() }) +function clone(a) { + return extend({}, a) +} + +function extend(a, b) { + for (key in b) { a[key] = b[key]} + return a +} |