diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-01-23 17:51:45 -0800 |
---|---|---|
committer | Julien Gilli <julien.gilli@joyent.com> | 2015-01-27 17:41:30 -0800 |
commit | 491ac6a84365e143255cd1b75717b05dadeec219 (patch) | |
tree | 2bc373b96c183a5d403fb874a41a8045280139fc /deps/npm/test/tap/version-git-not-clean.js | |
parent | e67073256d847be085be7049cd1d6ebd8d86ac62 (diff) | |
download | node-491ac6a84365e143255cd1b75717b05dadeec219.tar.gz |
deps: upgrade npm to 2.3.0
PR: #9086
PR-URL: https://github.com/joyent/node/pull/9086
Reviewed-By: Julien Gilli <julien.gilli@joyent.com>
Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>
Diffstat (limited to 'deps/npm/test/tap/version-git-not-clean.js')
-rw-r--r-- | deps/npm/test/tap/version-git-not-clean.js | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/deps/npm/test/tap/version-git-not-clean.js b/deps/npm/test/tap/version-git-not-clean.js new file mode 100644 index 000000000..efca36240 --- /dev/null +++ b/deps/npm/test/tap/version-git-not-clean.js @@ -0,0 +1,81 @@ +var common = require("../common-tap.js") +var test = require("tap").test +var npm = require("../../") +var osenv = require("osenv") +var path = require("path") +var fs = require("fs") +var rimraf = require("rimraf") +var mkdirp = require("mkdirp") +var which = require("which") +var spawn = require("child_process").spawn + +var pkg = path.resolve(__dirname, "version-git-not-clean") +var cache = path.resolve(pkg, "cache") + +test("npm version <semver> with working directory not clean", function (t) { + setup() + npm.load({ cache: cache, registry: common.registry, prefix: pkg }, function () { + which("git", function (err, git) { + t.ifError(err, "git found") + + function gitInit(_cb) { + var child = spawn(git, ["init"]) + var out = "" + child.stdout.on("data", function (d) { + out += d.toString() + }) + child.on("exit", function () { + return _cb(out) + }) + } + + function addPackageJSON(_cb) { + var data = JSON.stringify({ name: "blah", version: "0.1.2" }) + fs.writeFile("package.json", data, function() { + var child = spawn(git, ["add", "package.json"]) + child.on("exit", function () { + var child2 = spawn(git, ["commit", "package.json", "-m", "init"]) + var out = "" + child2.stdout.on("data", function (d) { + out += d.toString() + }) + child2.on("exit", function () { + return _cb(out) + }) + }) + }) + } + + gitInit(function() { + addPackageJSON(function() { + var data = JSON.stringify({ name: "blah", version: "0.1.3" }) + fs.writeFile("package.json", data, function() { + npm.commands.version(["patch"], function (err) { + if (!err) { + t.fail("should fail on non-clean working directory") + } + else { + t.equal(err.message, "Git working directory not clean.\nM package.json") + } + t.end() + }) + }) + }) + }) + }) + }) +}) + +test("cleanup", function (t) { + // windows fix for locked files + process.chdir(osenv.tmpdir()) + + rimraf.sync(pkg) + t.end() +}) + +function setup() { + mkdirp.sync(pkg) + mkdirp.sync(cache) + process.chdir(pkg) +} |