~webapps/unity-js-scopes/node.js

« back to all changes in this revision

Viewing changes to deps/npm/test/tap/tag-version-prefix.js

  • Committer: Marcus Tomlinson
  • Date: 2015-11-13 07:59:04 UTC
  • Revision ID: marcus.tomlinson@canonical.com-20151113075904-h0swczmoq1rvstfc
Node v4 (stable)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
var common = require('../common-tap.js')
 
2
var fs = require('fs')
 
3
var path = require('path')
 
4
 
 
5
var mkdirp = require('mkdirp')
 
6
var osenv = require('osenv')
 
7
var rimraf = require('rimraf')
 
8
var test = require('tap').test
 
9
 
 
10
var npm = require('../../lib/npm.js')
 
11
 
 
12
var pkg = path.resolve(__dirname, 'version-message-config')
 
13
var cache = path.resolve(pkg, 'cache')
 
14
var npmrc = path.resolve(pkg, '.npmrc')
 
15
var packagePath = path.resolve(pkg, 'package.json')
 
16
 
 
17
var json = { name: 'blah', version: '0.1.2' }
 
18
 
 
19
var configContents = 'sign-git-tag=false\nmessage=":bookmark: %s"\n'
 
20
 
 
21
test('npm version <semver> with message config', function (t) {
 
22
  setup()
 
23
 
 
24
  npm.load({ prefix: pkg, userconfig: npmrc }, function () {
 
25
    var git = require('../../lib/utils/git.js')
 
26
 
 
27
    common.makeGitRepo({ path: pkg }, function (er) {
 
28
        t.ifErr(er, 'git bootstrap ran without error')
 
29
 
 
30
        common.npm(
 
31
          [
 
32
            '--userconfig', npmrc,
 
33
            'config',
 
34
            'set',
 
35
            'tag-version-prefix',
 
36
            'q'
 
37
          ],
 
38
          { cwd: pkg, env: { PATH: process.env.PATH } },
 
39
          function (err, code, stdout, stderr) {
 
40
            t.ifError(err, 'npm config ran without issue')
 
41
            t.notOk(code, 'exited with a non-error code')
 
42
            t.notOk(stderr, 'no error output')
 
43
 
 
44
            common.npm(
 
45
              [
 
46
                'version',
 
47
                'patch',
 
48
                '--loglevel', 'silent'
 
49
                // package config is picked up from env
 
50
              ],
 
51
              { cwd: pkg, env: { PATH: process.env.PATH } },
 
52
              function (err, code, stdout, stderr) {
 
53
                t.ifError(err, 'npm version ran without issue')
 
54
                t.notOk(code, 'exited with a non-error code')
 
55
                t.notOk(stderr, 'no error output')
 
56
 
 
57
                git.whichAndExec(
 
58
                  ['tag'],
 
59
                  { cwd: pkg, env: process.env },
 
60
                  function (er, tags, stderr) {
 
61
                    t.ok(tags.match(/q0\.1\.3/g), 'tag was created by version' + tags)
 
62
                    t.end()
 
63
                  }
 
64
                )
 
65
              }
 
66
            )
 
67
          }
 
68
        )
 
69
      }
 
70
    )
 
71
  })
 
72
})
 
73
 
 
74
test('cleanup', function (t) {
 
75
  cleanup()
 
76
  t.end()
 
77
})
 
78
 
 
79
function cleanup () {
 
80
  // windows fix for locked files
 
81
  process.chdir(osenv.tmpdir())
 
82
 
 
83
  rimraf.sync(pkg)
 
84
}
 
85
 
 
86
function setup () {
 
87
  cleanup()
 
88
  mkdirp.sync(cache)
 
89
  process.chdir(pkg)
 
90
 
 
91
  fs.writeFileSync(packagePath, JSON.stringify(json), 'utf8')
 
92
  fs.writeFileSync(npmrc, configContents, 'ascii')
 
93
}