]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/version-git-not-clean.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / version-git-not-clean.js
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')
6 var fs = require('fs')
7 var rimraf = require('rimraf')
8 var mkdirp = require('mkdirp')
9 var which = require('which')
10 var spawn = require('child_process').spawn
11
12 var pkg = path.resolve(__dirname, 'version-git-not-clean')
13 var cache = path.resolve(pkg, 'cache')
14
15 test('npm version <semver> with working directory not clean', function (t) {
16   setup()
17   npm.load({ cache: cache, registry: common.registry, prefix: pkg }, function () {
18     which('git', function (err, git) {
19       t.ifError(err, 'git found')
20
21       function addPackageJSON (_cb) {
22         var data = JSON.stringify({ name: 'blah', version: '0.1.2' })
23         fs.writeFile('package.json', data, function () {
24           var child = spawn(git, ['add', 'package.json'])
25           child.on('exit', function () {
26             var child2 = spawn(git, ['commit', 'package.json', '-m', 'init'])
27             var out = ''
28             child2.stdout.on('data', function (d) {
29               out += d.toString()
30             })
31             child2.on('exit', function () {
32               return _cb(out)
33             })
34           })
35         })
36       }
37
38       common.makeGitRepo({path: pkg}, function () {
39         addPackageJSON(function () {
40           var data = JSON.stringify({ name: 'blah', version: '0.1.3' })
41           fs.writeFile('package.json', data, function () {
42             npm.commands.version(['patch'], function (err) {
43               if (!err) {
44                 t.fail('should fail on non-clean working directory')
45               } else {
46                 t.ok(err.message.match(/Git working directory not clean./))
47                 t.ok(err.message.match(/M package.json/))
48               }
49               t.end()
50             })
51           })
52         })
53       })
54     })
55   })
56 })
57
58 test('npm version <semver> --force with working directory not clean', function (t) {
59   common.npm(
60     [
61       '--force',
62       '--no-sign-git-tag',
63       '--registry', common.registry,
64       '--prefix', pkg,
65       'version',
66       'patch'
67     ],
68     { cwd: pkg, env: {PATH: process.env.PATH} },
69     function (err, code, stdout, stderr) {
70       t.ifError(err, 'npm version ran without issue')
71       t.notOk(code, 'exited with a non-error code')
72       var errorLines = stderr.trim().split('\n')
73         .map(function (line) {
74           return line.trim()
75         })
76         .filter(function (line) {
77           return !line.indexOf('using --force')
78         })
79       t.notOk(errorLines.length, 'no error output')
80       t.end()
81     })
82 })
83
84 test('cleanup', function (t) {
85   // windows fix for locked files
86   process.chdir(osenv.tmpdir())
87
88   rimraf.sync(pkg)
89   t.end()
90 })
91
92 function setup () {
93   mkdirp.sync(pkg)
94   mkdirp.sync(cache)
95   process.chdir(pkg)
96 }