• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var common = require('../common-tap.js')
2var fs = require('fs')
3var path = require('path')
4
5var mkdirp = require('mkdirp')
6var test = require('tap').test
7
8var npm = require('../../lib/npm.js')
9
10var pkg = common.pkg
11var subDirectory = path.resolve(pkg, 'sub-directory')
12var packagePath = path.resolve(pkg, 'package.json')
13var cache = common.cache
14
15var json = { name: 'cat', version: '0.1.2' }
16
17test('npm version <semver> from a subdirectory', function (t) {
18  mkdirp.sync(subDirectory)
19  process.chdir(subDirectory)
20  fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8')
21  npmLoad()
22
23  function npmLoad () {
24    npm.load({ cache: cache }, function () {
25      common.makeGitRepo({
26        path: pkg,
27        added: ['package.json']
28      }, version)
29    })
30  }
31
32  function version (er, stdout, stderr) {
33    t.ifError(er, 'git repo initialized without issue')
34    t.notOk(stderr, 'no error output')
35    npm.config.set('sign-git-commit', false)
36    npm.config.set('sign-git-tag', false)
37    npm.commands.version(['patch'], checkVersion)
38  }
39
40  function checkVersion (er) {
41    var git = require('../../lib/utils/git.js')
42    t.ifError(er, 'version command ran without error')
43    git.whichAndExec(
44      ['log'],
45      { cwd: pkg, env: process.env },
46      checkCommit
47    )
48  }
49
50  function checkCommit (er, log, stderr) {
51    t.ifError(er, 'git log ran without issue')
52    t.notOk(stderr, 'no error output')
53    t.ok(log.match(/0\.1\.3/g), 'commited from subdirectory')
54    t.end()
55  }
56})
57