<commit_before>var common = require("../common-tap.js")
var test = require("tap").test
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-message-config")
var opts = { cwd: pkg }
var cache = path.resolve(pkg, "cache")
var npmrcPath = path.resolve(pkg, ".npmrc")
var packagePath = path.resolve(pkg, "package.json")

test("npm version <semver> with message config", function (t) {
  setup()
  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 addConfig(_cb) {
      var data = "message = \":bookmark: %s\""
      fs.writeFileSync(npmrcPath, data, "ascii")
    }

    function addPackageJSON(_cb) {
      var data = JSON.stringify({ name: "blah", version: "0.1.2" })
      fs.writeFileSync(packagePath, data, "ascii")
    }

    function gitLog(_cb) {
      var child = spawn(git, ["log"])
      var out = ""
      child.stdout.on("data", function (d) {
        out += d.toString()
      })
      child.on("exit", function () {
        _cb(out)
      })
    }

    gitInit(function() {
      addPackageJSON()
      addConfig()
      common.npm([
          "version",
          "patch",
          "--userconfig=" + npmrcPath
        ],
        opts,
        function (err, code, stdout, stderr) {
          t.ifError(err)
          gitLog(function (log) {
            t.ok(log.match(/:bookmark: 0\.1\.3/g))
            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)
}<commit_msg>test: rework version-message-config for Travis<commit_after>var common = require('../common-tap.js')
var fs = require('fs')
var path = require('path')

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

var npm = require('../../lib/npm.js')

var pkg = path.resolve(__dirname, 'version-message-config')
var cache = path.resolve(pkg, 'cache')
var npmrc = path.resolve(pkg, '.npmrc')
var packagePath = path.resolve(pkg, 'package.json')

var json = { name: 'blah', version: '0.1.2' }

var configContents = 'sign-git-tag=false\nmessage=":bookmark: %s"\n'

test('npm version <semver> with message config', function (t) {
  setup()

  npm.load({ prefix: pkg, userconfig: npmrc }, function () {
    var git = require('../../lib/utils/git.js')

    var opts = { cwd: pkg, env: { PATH: process.env.PATH } }
    chain(
      [
        git.chainableExec(['init'], opts),
        git.chainableExec(['config', 'user.name', 'PhantomFaker'], opts),
        git.chainableExec(['config', 'user.email', 'no<EMAIL>'], opts),
        git.chainableExec(['add', 'package.json'], opts),
        git.chainableExec(['add', '.npmrc'], opts),
        git.chainableExec(['commit', '-m', 'stub package'], opts)
      ],
      function (er) {
        t.ifErr(er, 'git bootstrap ran without error')

        common.npm(
          [
            'version',
            'patch',
            '--loglevel', 'silent'
            // package config is picked up from env
          ],
          opts,
          function (err, code, stdout, stderr) {
            t.ifError(err, 'npm version ran without issue')
            t.notOk(code, 'exited with a non-error code')
            t.notOk(stderr, 'no error output')

            git.whichAndExec(
              ['log'],
              { cwd: pkg, env: process.env },
              function (er, log, stderr) {
                t.ok(log.match(/:bookmark: 0\.1\.3/g), 'config was picked up by version')
                t.end()
              }
            )
          }
        )
      }
    )
  })
})

test('cleanup', function (t) {
  cleanup()
  t.end()
})

function cleanup () {
  // windows fix for locked files
  process.chdir(osenv.tmpdir())

  rimraf.sync(pkg)
}

function setup () {
  cleanup()
  mkdirp.sync(cache)
  process.chdir(pkg)

  fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8')
  fs.writeFileSync(npmrc, configContents, 'ascii')
}
{'fraction_non_alphanumeric': 0.17003959524857018, 'fraction_numerical': 0.0028596568411790586, 'mean_word_length': 2.390753169276659, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 6, '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': '2536926', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1473, 'n_words': 344}