1 var common = require("../common-tap.js")
2 var test = require("tap").test
3 var npm = require("../../")
4 var osenv = require("osenv")
5 var path = require("path")
7 var rimraf = require("rimraf")
8 var mkdirp = require("mkdirp")
9 var which = require("which")
10 var spawn = require("child_process").spawn
12 var pkg = path.resolve(__dirname, "version-no-tags")
13 var cache = path.resolve(pkg, "cache")
15 test("npm version <semver> without git tag", function (t) {
17 npm.load({ cache: cache, registry: common.registry}, function () {
18 which("git", function (err, git) {
19 t.ifError(err, "git found on system")
20 function tagExists(tag, _cb) {
21 var child1 = spawn(git, ["tag", "-l", tag])
23 child1.stdout.on("data", function (d) {
26 child1.on("exit", function () {
27 return _cb(null, Boolean(~out.indexOf(tag)))
31 var child2 = spawn(git, ["init"])
32 child2.stdout.pipe(process.stdout)
33 child2.on("exit", function () {
34 npm.config.set("git-tag-version", false)
35 npm.commands.version(["patch"], function (err) {
36 if (err) return t.fail("Error perform version patch")
37 var p = path.resolve(pkg, "package")
38 var testPkg = require(p)
39 if (testPkg.version !== "0.0.1") t.fail(testPkg.version+" !== \"0.0.1\"")
40 t.equal("0.0.1", testPkg.version)
41 tagExists("v0.0.1", function (err, exists) {
42 t.ifError(err, "tag found to exist")
43 t.equal(exists, false, "git tag DOES exist")
44 t.pass("git tag does not exist")
53 test("cleanup", function (t) {
54 // windows fix for locked files
55 process.chdir(osenv.tmpdir())
64 fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify({
66 name: "version-no-tags-test",
68 description: "Test for git-tag-version flag"