diff options
author | Tim Oxley <secoif@gmail.com> | 2014-05-10 23:23:12 +0400 |
---|---|---|
committer | Tim Oxley <secoif@gmail.com> | 2014-05-10 23:23:12 +0400 |
commit | 1f108b8a1f0f28a21b4ba4d0b86037abfd426dcd (patch) | |
tree | 38598c86bcc0d6a8e82e5775a0e21c73baea7f6f /test | |
parent | cb295989c38494fb1190e1bcf05683a38bbd37fc (diff) |
Add update --save/--save-dev tests.
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/update-save.js | 87 | ||||
-rw-r--r-- | test/tap/update-save/README.md | 1 | ||||
-rw-r--r-- | test/tap/update-save/index.js | 1 | ||||
-rw-r--r-- | test/tap/update-save/package.json | 10 |
4 files changed, 99 insertions, 0 deletions
diff --git a/test/tap/update-save.js b/test/tap/update-save.js new file mode 100644 index 000000000..6771c6254 --- /dev/null +++ b/test/tap/update-save.js @@ -0,0 +1,87 @@ +var common = require("../common-tap.js") +var test = require("tap").test +var npm = require("../../") +var mkdirp = require("mkdirp") +var rimraf = require("rimraf") +var fs = require('fs') +var path = require('path') +var mr = require("npm-registry-mock") + +var PKG_DIR = path.resolve(__dirname, "update-save") +var PKG = path.resolve(PKG_DIR, "package.json") +var CACHE_DIR = path.resolve(PKG_DIR, "cache") +var MODULES_DIR = path.resolve(PKG_DIR, "node_modules") + +var EXEC_OPTS = { + cwd: PKG_DIR, + stdio: 'ignore' +} + +var DEFAULT_PKG = { + "name": "update-save-example", + "version": "1.2.3", + "dependencies": { + "mkdirp": "~0.3.0" + }, + "devDependencies": { + "underscore": "~1.3.1" + } +} + +var s = undefined + +test('setup', function (t) { + resetPackage() + + mr(common.port, function (server) { + npm.load({cache: CACHE_DIR, registry: common.registry}, function (err) { + t.ifError(err) + s = server + t.end() + }) + }) +}) + +test("update regular dependencies only", function (t) { + resetPackage() + + 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.end() + }) +}) + +test("update devDependencies only", function (t) { + resetPackage() + + common.npm(['update', '--save-dev'], EXEC_OPTS, function (err, code) { + t.ifError(err) + t.equal(code, 0) + var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8')) + 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.end() + }) +}) + + +function resetPackage() { + rimraf.sync(CACHE_DIR) + rimraf.sync(MODULES_DIR) + mkdirp.sync(CACHE_DIR) + + fs.writeFileSync(PKG, JSON.stringify(DEFAULT_PKG, null, 2), 'ascii') +} + +test("cleanup", function (t) { + resetPackage() // restore package.json + rimraf.sync(CACHE_DIR) + rimraf.sync(MODULES_DIR) + t.end() +}) + diff --git a/test/tap/update-save/README.md b/test/tap/update-save/README.md new file mode 100644 index 000000000..aca67ff17 --- /dev/null +++ b/test/tap/update-save/README.md @@ -0,0 +1 @@ +# just a test diff --git a/test/tap/update-save/index.js b/test/tap/update-save/index.js new file mode 100644 index 000000000..33c1891f8 --- /dev/null +++ b/test/tap/update-save/index.js @@ -0,0 +1 @@ +module.exports = true diff --git a/test/tap/update-save/package.json b/test/tap/update-save/package.json new file mode 100644 index 000000000..cb41e88cf --- /dev/null +++ b/test/tap/update-save/package.json @@ -0,0 +1,10 @@ +{ + "name": "update-save-example", + "version": "1.2.3", + "dependencies": { + "mkdirp": "~0.3.0" + }, + "devDependencies": { + "underscore": "~1.3.1" + } +}
\ No newline at end of file |