]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/outdated-color.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / outdated-color.js
1 var fs = require('graceful-fs')
2 var path = require('path')
3
4 var mkdirp = require('mkdirp')
5 var mr = require('npm-registry-mock')
6 var rimraf = require('rimraf')
7 var test = require('tap').test
8
9 var common = require('../common-tap.js')
10
11 var pkg = path.resolve(__dirname, 'outdated-color')
12
13 var EXEC_OPTS = { cwd: pkg }
14
15 function hasControlCodes (str) {
16   return str.length !== ansiTrim(str).length
17 }
18
19 function ansiTrim (str) {
20   var r = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|' +
21         '\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g')
22   return str.replace(r, '')
23 }
24
25 var json = {
26   name: 'outdated-color',
27   description: 'fixture',
28   version: '0.0.1',
29   dependencies: {
30     underscore: '1.3.1'
31   }
32 }
33
34 test('setup', function (t) {
35   cleanup()
36   mkdirp.sync(pkg)
37   fs.writeFileSync(
38     path.join(pkg, 'package.json'),
39     JSON.stringify(json, null, 2)
40   )
41
42   process.chdir(pkg)
43   t.end()
44 })
45
46 // note hard to automate tests for color = true
47 // as npm kills the color config when it detects
48 // it's not running in a tty
49 test('does not use ansi styling', function (t) {
50   t.plan(4)
51   mr({ port: common.port }, function (er, s) { // create mock registry.
52     common.npm(
53     [
54       '--registry', common.registry,
55       'outdated', 'underscore'
56     ],
57     EXEC_OPTS,
58     function (err, code, stdout) {
59       t.ifError(err)
60       t.notOk(code, 'npm outdated exited with code 0')
61       t.ok(stdout, stdout.length)
62       t.ok(!hasControlCodes(stdout))
63       s.close()
64     })
65   })
66 })
67
68 test('cleanup', function (t) {
69   cleanup()
70   t.end()
71 })
72
73 function cleanup () {
74   rimraf.sync(pkg)
75 }