]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/test/tap/noargs-install-config-save.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / test / tap / noargs-install-config-save.js
1 var common = require('../common-tap.js')
2 var test = require('tap').test
3 var path = require('path')
4 var fs = require('fs')
5 var rimraf = require('rimraf')
6 var mkdirp = require('mkdirp')
7
8 var mr = require("npm-registry-mock")
9
10 var pkg = path.resolve(process.env.npm_config_tmp || '/tmp',
11   'noargs-install-config-save')
12
13 function writePackageJson() {
14   rimraf.sync(pkg)
15   mkdirp.sync(pkg)
16   mkdirp.sync(pkg + "/cache")
17
18   fs.writeFileSync(pkg + "/package.json", JSON.stringify({
19     "author": "Rocko Artischocko",
20     "name": "noargs",
21     "version": "0.0.0",
22     "devDependencies": {
23       "underscore": "1.3.1"
24     }
25   }), "utf8")
26 }
27
28 var env = {
29   'npm_config_save': true,
30   'npm_config_registry': common.registry,
31   'npm_config_cache': pkg + '/cache',
32   HOME: process.env.HOME,
33   Path: process.env.PATH,
34   PATH: process.env.PATH
35 }
36 var OPTS = {
37   cwd: pkg,
38   env: env
39 }
40
41 test("does not update the package.json with empty arguments", function (t) {
42   writePackageJson()
43   t.plan(2)
44
45   mr({ port: common.port }, function (er, s) {
46     common.npm('install', OPTS, function (er, code, stdout, stderr) {
47       if (er) throw er
48       t.is(code, 0)
49       if (code !== 0) {
50         console.error('#', stdout)
51         console.error('#', stderr)
52       }
53       var text = JSON.stringify(fs.readFileSync(pkg + '/package.json', 'utf8'))
54       s.close()
55       t.ok(text.indexOf("\"dependencies") === -1)
56     })
57   })
58 })
59
60 test("updates the package.json (adds dependencies) with an argument", function (t) {
61   writePackageJson()
62   t.plan(2)
63
64   mr({ port: common.port }, function (er, s) {
65     common.npm(['install', 'underscore'], OPTS, function (er, code, stdout, stderr) {
66       if (er) throw er
67       t.is(code, 0)
68       s.close()
69       var text = JSON.stringify(fs.readFileSync(pkg + "/package.json", "utf8"))
70       t.ok(text.indexOf("\"dependencies") !== -1)
71     })
72   })
73 })
74
75 test("cleanup", function (t) {
76   rimraf.sync(pkg + "/cache")
77   t.end()
78 })