<commit_before>var fs = require("fs")
var resolve = require("path").resolve

var chain = require("slide").chain
var osenv = require("osenv")
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
var test = require("tap").test

var npm = require("../../lib/npm.js")
var common = require("../common-tap.js")

var pkg = resolve(__dirname, "add-remote-git")
var repo = resolve(__dirname, "add-remote-git-repo")

var daemon
var daemonPID
var git

test("setup", function (t) {
  bootstrap()
  setup(function (er, r) {
    t.ifError(er, "git started up successfully")

    if (!er) {
      daemon = r[r.length - 2]
      daemonPID = r[r.length - 1]
    }

    t.end()
  })
})

test("install from repo on 'Windows'", function (t) {
  // before we confuse everything by switching the platform
  require("../../lib/install.js")
  require("../../lib/unbuild.js")
  process.platform = "win32"
  process.chdir(pkg)
  npm.commands.install(".", [], function (er) {
    t.ifError(er, "npm installed via git")

    t.end()
  })
})

test("clean", function (t) {
  daemon.on("close", function () {
    cleanup()
    t.end()
  })
  process.kill(daemonPID)
})

var pjParent = JSON.stringify({
  name : "parent",
  version : "1.2.3",
  dependencies : {
    "child" : "git://localhost:1234/child.git"
  }
}, null, 2) + "\n"

var pjChild = JSON.stringify({
  name : "child",
  version : "1.0.3"
}, null, 2) + "\n"

function bootstrap () {
  mkdirp.sync(pkg)
  fs.writeFileSync(resolve(pkg, "package.json"), pjParent)
}

function setup (cb) {
  mkdirp.sync(repo)
  fs.writeFileSync(resolve(repo, "package.json"), pjChild)
  npm.load({ registry : common.registry, loglevel : "silent" }, function () {
    // some really cheesy monkeypatching
    require("module")._cache[require.resolve("which")] = {
      exports : function (_, cb) { cb() }
    }
    git = require("../../lib/utils/git.js")

    function startDaemon (cb) {
      // start git server
      var d = git.spawn(
        [
          "daemon",
          "--verbose",
          "--listen=localhost",
          "--export-all",
          "--base-path=.",
          "--port=1234"
        ],
        {
          cwd : pkg,
          env : process.env,
          stdio : ["pipe", "pipe", "pipe"]
        }
      )<commit_msg>test: Clean folders on start for add-remote-git-fake-windows<commit_after>var fs = require("fs")
var resolve = require("path").resolve

var chain = require("slide").chain
var osenv = require("osenv")
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
var test = require("tap").test

var npm = require("../../lib/npm.js")
var common = require("../common-tap.js")

var pkg = resolve(__dirname, "add-remote-git")
var repo = resolve(__dirname, "add-remote-git-repo")

var daemon
var daemonPID
var git

test("setup", function (t) {
  bootstrap()
  setup(function (er, r) {
    if (er) {
      throw er
    }

    if (!er) {
      daemon = r[r.length - 2]
      daemonPID = r[r.length - 1]
    }

    t.end()
  })
})

test("install from repo on 'Windows'", function (t) {
  // before we confuse everything by switching the platform
  require("../../lib/install.js")
  require("../../lib/unbuild.js")
  process.platform = "win32"
  process.chdir(pkg)
  npm.commands.install(".", [], function (er) {
    t.ifError(er, "npm installed via git")

    t.end()
  })
})

test("clean", function (t) {
  daemon.on("close", function () {
    cleanup()
    t.end()
  })
  process.kill(daemonPID)
})

var pjParent = JSON.stringify({
  name : "parent",
  version : "1.2.3",
  dependencies : {
    "child" : "git://localhost:1234/child.git"
  }
}, null, 2) + "\n"

var pjChild = JSON.stringify({
  name : "child",
  version : "1.0.3"
}, null, 2) + "\n"

function bootstrap () {
  rimraf.sync(pkg)
  mkdirp.sync(pkg)
  fs.writeFileSync(resolve(pkg, "package.json"), pjParent)
}

function setup (cb) {
  rimraf.sync(repo)
  mkdirp.sync(repo)
  fs.writeFileSync(resolve(repo, "package.json"), pjChild)
  npm.load({ registry : common.registry, loglevel : "silent" }, function () {
    // some really cheesy monkeypatching
    require("module")._cache[require.resolve("which")] = {
      exports : function (_, cb) { cb() }
    }
    git = require("../../lib/utils/git.js")

    function startDaemon (cb) {
      // start git server
      var d = git.spawn(
        [
          "daemon",
          "--verbose",
          "--listen=localhost",
          "--export-all",
          "--base-path=.",
          "--port=1234"
        ],
        {
          cwd : pkg,
          env : process.env,
          stdio : ["pipe", "pipe", "pipe"]
        }
      )
{'fraction_non_alphanumeric': 0.18630434782608696, 'fraction_numerical': 0.008695652173913044, 'mean_word_length': 2.5583913379737044, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6526785', 'n_tokens_mistral': 1634, 'n_tokens_neox': 1559, 'n_words': 357}